使用proj4js转换EPSG3946至EPSG4326后点位偏移问题求助
投影转换偏移问题:EPSG 3946转WGS84后点位南偏8度
我有一个用于Leaflet地图的.json点位文件,使用proj4js将其从EPSG 3946投影转换为WGS84(EPSG 4326)。转换流程无报错,但点位实际位置偏差约8度南移且略有东移,相同点位在QGIS中显示正常。
使用的.js脚本如下:
var pTransfo; $.getJSON('transfo.json',function(data){ proj4.defs("EPSG:3946", "+proj=lcc +lat_1=43 +lat_2=49 +lat_0=46.5 +lon_0=6 +x_0=1700000 +y_0=6200000 +datum=RGF93 +units=m +no_defs +towgs84=0,0,0"); var fromProj = proj4('EPSG:3946'); var toProj = proj4('EPSG:4326'); function convertCoordinates(coordinates) { var convertedCoords = proj4(fromProj, toProj, [coordinates[0], coordinates[1]]); console.log('Coordonnées originales :', coordinates); console.log('Coordonnées converties :', convertedCoords); return [convertedCoords[0], convertedCoords[1]]; } data.features.forEach(function(feature) { if (feature.geometry.type === "Point") { feature.geometry.coordinates = convertCoordinates(feature.geometry.coordinates); } });
已在HTML中引入proj4js:
<script type="text/javascript" language="javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.6.0/proj4-src.js"></script>
(该脚本位于jquery和leaflet脚本之后)
问题排查与解决方案
1. 坐标顺序错误是核心原因
Leaflet要求WGS84坐标采用**[经度, 纬度]顺序,但EPSG 3946作为投影坐标系,原始数据应为[东向坐标(x), 北向坐标(y)]**。如果你的transfo.json里的Point坐标是反序的(比如误存为[y, x]),或者你在转换时搞反了输入参数,就会出现这种量级的偏移。
检查原始坐标的数值:EPSG 3946的x值应接近1700000,y值接近6200000(对应你定义的x_0和y_0)。如果原始坐标数值不在这个范围,大概率是把地理坐标(经纬度)当成投影坐标传入了,或者顺序完全颠倒。
2. 验证并修复转换逻辑
如果确认原始坐标是[y, x]反序,修改转换函数的输入参数顺序:
function convertCoordinates(coordinates) { // 调换原始坐标的x和y顺序 var convertedCoords = proj4(fromProj, toProj, [coordinates[1], coordinates[0]]); console.log('Coordonnées originales :', coordinates); console.log('Coordonnées converties :', convertedCoords); // 确保返回Leaflet要求的[lon, lat]顺序(proj4js转换结果本身就是这个顺序) return [convertedCoords[0], convertedCoords[1]]; }
3. 额外验证点
你当前使用的EPSG 3946参数是正确的,+towgs84=0,0,0符合RGF93与WGS84的基准面关系,QGIS显示正常也佐证了参数没问题,所以无需调整投影定义。
内容的提问来源于stack exchange,提问作者1936Gloria
相关产品推荐
相关产品推荐

