【发布时间】:2022-02-11 20:55:19
【问题描述】:
在geojson 文件上直接在JavaScript 中工作,我找不到任何简单的方法将我的坐标从EPSG3035 转换为地理(Lon,Lat)。我的意思很简单:不安装其他软件,如 QGIS 或类似软件。 proj4和ol我都试过了,都失败了。
我不知道。 [OL解决方案在下面的“t.niese”答案中]
let coordinates = [4035675.373507705517113, 2862363.090465864632279]; // Luxembourg
console.log(coordinates);
// a "well-known text" WKT-OGC definition from https://epsg.io/3035
const WKT3035 = `PROJCS["ETRS89 / LAEA Europe",GEOGCS["ETRS89",DATUM["European_Terrestrial_Reference_System_1989",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6258"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4258"]],PROJECTION["Lambert_Azimuthal_Equal_Area"],PARAMETER["latitude_of_center",52],PARAMETER["longitude_of_center",10],PARAMETER["false_easting",4321000],PARAMETER["false_northing",3210000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","3035"]]`;
// trying OpenLayers
try {
const fromLonLat = ol.proj.getTransform("EPSG:3035", "EPSG:4326");
coordinates = fromLonLat(coordinates);
console.log("using ol.proj", coordinates);
} catch (err) {
console.error(err)
}
try { // trying proj4
coordinates = [4035675.373507705517113, 2862363.090465864632279];
const srcProj = new proj4.Proj(WKT3035);
proj4(srcProj).inverse(coordinates);
console.log("using proj4", coordinates);
} catch (err) {
console.error(err)
}
<script src="https://cdn.jsdelivr.net/gh/openlayers/openlayers.github.io@master/en/v6.8.1/build/ol.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.7.5/proj4.js"></script>
【问题讨论】:
-
你骗了这个解决方案stackoverflow.com/questions/49774309/…。它适用于我的项目
-
好的,我去看看。我正在使用 v2.7.5。
标签: javascript coordinate-transformation