[geotk] coordinate transformation from 3857 to 4326
juergen sorg
j.sorg at fz-juelich.de
Fri Mar 19 06:27:43 PDT 2021
thanks a lot - that solved my problem
On 19/03/2021 13:21, Alexis Manin wrote:
> Hello,
>
> Geotk referencing engine is strict about CRS definition, and as stated
> by the official EPSG database[1], The 4326 CRS axes order is latitude
> first then longitude.
> If you want a longitude first system, the easiest way is to use "CRS:84"
> code instead of "EPSG:4326", which indicates official OGC CRS for WGS84,
> whose axes order is longitude then latitude.
>
> The jts transform does not update crs definition. You'll have to do it
> yourself by calling JTS.setCRS(geometry, crs)[2];
>
> Regards,
>
> [1] https://epsg.org/crs_4326/WGS-84.html
> [2]
> https://github.com/Geomatys/geotoolkit/blob/97cfa40dca66617069afc23cbb8a21a667e1b5c1/modules/feature/geotk-geometry/src/main/java/org/geotoolkit/geometry/jts/JTS.java#L761
>
>
> Le ven. 19 mars 2021 à 12:48, juergen sorg <j.sorg at fz-juelich.de
> <mailto:j.sorg at fz-juelich.de>> a écrit :
>
> hi,
>
> i have a question about transforming coordinates from epsg:3857
> (google)
> to epsg:4326 (lon lat). (i am not sure if this is the right place to
> ask
> for - but i am using geotk with jts).
> in [0] you can find a code snippet to transform a point and in [1] the
> results.
> my questions are:
>
> 1. why are the coordinates not swapped, because after the
> transformation
> x-coord and the y-coord are at the wrong place.
> 2. do i have to swap it by my own and if yes then how can i do it with
> e.g. polygons
> 3. why the crs is still 3857 after transformation (it should 4326) and
> if i have to change it by my own how this can be accomplished?
>
> thanks in advance
>
> regards,
> juergen
>
>
>
> [0]
>
> WKTReader WKT_READER = new WKTReader(
> new GeometryFactory(new
> PrecisionModel(PrecisionModel.FLOATING), 3857));
> String pt_google="POINT(704377.78268943
> 6533181.663612)";
> Geometry pt_google_geom=WKT_READER.read(pt_google);
>
> Geometry pt_wgs84_geom=JTS.transform(pt_google_geom,
>
> CRS.findOperation(CRS.forCode("EPSG:3857"),
> CRS.forCode("EPSG:4326"), null).getMathTransform());
> Geometry
> pt_google_geom_transformed=JTS.transform(pt_wgs84_geom,
>
> CRS.findOperation(CRS.forCode("EPSG:4326"),
> CRS.forCode("EPSG:3857"), null).getMathTransform());
> System.out.println(pt_google_geom);
> System.out.println(pt_google_geom.getSRID());
> System.out.println(pt_wgs84_geom);
> System.out.println(pt_wgs84_geom.getSRID());
> System.out.println(pt_google_geom_transformed);
> System.out.println(pt_google_geom_transformed.getSRID());
>
>
> [1]
>
> POINT (704377.78268943 6533181.663612)
> 3857
> POINT (50.499200582184564 6.327533279841338)
> 3857
> POINT (704377.7826894299 6533181.663611999)
> 3857
>
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org <mailto:Geotoolkit at lists.osgeo.org>
> https://lists.osgeo.org/mailman/listinfo/geotoolkit
>
>
>
> --
> Alexis Manin,
> Développeur JAVA/JEE.
> Geomatys.
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5335 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.osgeo.org/pipermail/geotoolkit/attachments/20210319/74af19db/attachment-0001.bin>
More information about the Geotoolkit
mailing list