Trabajando directamente en JavaScript en un archivo geojson, no pude encontrar ninguna manera fácil de transformar mis coordenadas de EPSG3035 a geográficas (Lon, Lat). Por fácil quiero decir: no instalar otro software como QGIS o similar. Probé proj4 y ol, pero ambos fallaron.
No tengo ni idea. [la solución OL está en la respuesta "t.niese" a continuación]
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>Los errores que obtienes se deben a que proj4 no conoce la proyección EPSG:3035
Si ejecuta console.log(proj4.defs('EPSG:3035')) puede ver que devuelve undefined .
console.log(proj4.defs('EPSG:3035')) <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> Si solo usó proj4 , puede definir la proyección usando:
proj4.defs("EPSG:3035", /* here goes the definition of that projection */); Usar proj4.defs(name, definition) no devuelve nada, define la proyección con ese nombre para que pueda usarse con ese nombre. Después de definir la proyección, puede usar proj4.defs(name) para obtenerla.
Si para OpenLayer también necesita registrar proj4 después de eso:
proj4.defs("EPSG:3035", /* here goes the definition of that projection */); ol.proj.proj4.register(proj4); La definición de proj4 debería ser +proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs (Fuente https://epsg.io/3035 )
proj4.defs("EPSG:3035", '+proj=laea +lat_0=52 +lon_0=10 +x_0=4321000 +y_0=3210000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs'); ol.proj.proj4.register(proj4); let coordinates = [4035675.373507705517113, 2862363.090465864632279]; // Luxembourg console.log(coordinates); try { // trying OpenLayers const fromLonLat = ol.proj.getTransform("EPSG:3035", "EPSG:4326"); console.dir(fromLonLat(coordinates)); } catch (err) { console.error(err) } try { // trying proj4 console.dir(proj4(proj4.defs('EPSG:3035'), proj4.defs('EPSG:4326'), 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>