1 votos

La latitud está demasiado cerca de un polo al convertir de EPSG:3857 a EPSG:4326

Estoy intentando convertir EPSG: 3857 a EPSG: 4326 con geotools. Aquí está mi código :

public void convertEPSG3857toEPSG4326() throws FactoryException, TransformException {
    try {
        CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
        CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857");
        MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false);
        GeometryFactory geometryFactory = new GeometryFactory(new PrecisionModel(), 4326);
        Point point = geometryFactory.createPoint(new Coordinate(x, y));
        Point targetPoint = (Point) JTS.transform(point, transform);
    } catch (Exception e) {
        e.printStackTrace();
        System.out.println("Problem for : x = " + x + " y = " + y);
    }
}

Para el geojson :

{"crs":{"type":"name","properties":{"name":"urn:ogc:def:crs:EPSG::3857"}},"type":"FeatureCollection","features":[{"type":"Feature","properties":{"FID":123,"TEXT":"yolo","attaches":[]},"geometry":{"type":"Polygon","coordinates":[[[9830100,3500101.25],[9699943,2332626],[10394759,2332626],[9830100,3500101.25]]]}}]}

Sigo recibiendo este error :

Problem for : x = 9830100.0 y = 3500101.25
Problem for : x = 9699943.0 y = 2332626.0
Problem for : x = 1.0394759E7 y = 2332626.0
2017-05-15T10:59:39.710+0530  WARNING  Possible use of "Popular Visualisation Pseudo Mercator" projection outside its valid area.
Longitude 3499741°15.0'E is out of range (±180°).
Latitude 9829740°00.0'N is out of range (±90°).
org.geotools.referencing.operation.projection.ProjectionException: Latitude 9829740°00.0'N is too close to a pole.
at org.geotools.referencing.operation.projection.Mercator$Spherical.transformNormalized(Mercator.java:209)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:897)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:81)
at org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:295)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:282)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:148)
at org.geotools.geometry.jts.JTS.transform(JTS.java:442)
at gis.GISCoordinate.convertEPSG3857toEPSG4326(GISCoordinate.java:52)
at gis.FeatureCollector.getAllGisFeature(FeatureCollector.java:65)
at MergeGis.main(MergeGis.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

org.geotools.referencing.operation.projection.ProjectionException: Latitude 9699583°00.0'N is too close to a pole.
at org.geotools.referencing.operation.projection.Mercator$Spherical.transformNormalized(Mercator.java:209)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:897)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:81)
at org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:295)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:282)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:148)
at org.geotools.geometry.jts.JTS.transform(JTS.java:442)
at gis.GISCoordinate.convertEPSG3857toEPSG4326(GISCoordinate.java:52)
at gis.FeatureCollector.getAllGisFeature(FeatureCollector.java:65)
at MergeGis.main(MergeGis.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

org.geotools.referencing.operation.projection.ProjectionException: Latitude 10394399°00.0'N is too close to a pole.
at org.geotools.referencing.operation.projection.Mercator$Spherical.transformNormalized(Mercator.java:209)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:897)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:81)
at org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:295)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:282)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:148)
at org.geotools.geometry.jts.JTS.transform(JTS.java:442)
at gis.GISCoordinate.convertEPSG3857toEPSG4326(GISCoordinate.java:52)
at gis.FeatureCollector.getAllGisFeature(FeatureCollector.java:65)
at MergeGis.main(MergeGis.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

org.geotools.referencing.operation.projection.ProjectionException: Latitude 9829740°00.0'N is too close to a pole.
at org.geotools.referencing.operation.projection.Mercator$Spherical.transformNormalized(Mercator.java:209)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:897)
at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:81)
at org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:123)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:295)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:282)
at org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:148)
at org.geotools.geometry.jts.JTS.transform(JTS.java:442)
at gis.GISCoordinate.convertEPSG3857toEPSG4326(GISCoordinate.java:52)
at gis.FeatureCollector.getAllGisFeature(FeatureCollector.java:65)
at MergeGis.main(MergeGis.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)

¿Cuál es el problema?

4voto

Nick Puntos 3115

La razón por la que tus coordenadas te están dando problemas es que estás poniendo tus coordenadas de origen en grados. No tiene nada que ver con la proximidad a los polos (el primer punto problemático está en China y el segundo en la India, y ninguno de los dos está cerca de los polos, ni siquiera del antemeridiano). Lee las líneas quinta y sexta del mensaje de error:

La longitud 3499741°15.0'E está fuera de rango (±180°).
La latitud 9829740°00.0'N está fuera de rango (±90°).

Así, ha introducido las coordenadas EPSG:3857 (que están en metros) como EPSG:4326 que están en grados.

Dado que su función se llama convertEPSG3857toEPSG4326() es probable que desee cambiar estas líneas de código:

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3857");

a:

CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:3857");
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");

i-Ciencias.com

I-Ciencias es una comunidad de estudiantes y amantes de la ciencia en la que puedes resolver tus problemas y dudas.
Puedes consultar las preguntas de otros usuarios, hacer tus propias preguntas o resolver las de los demás.

Powered by:

X