1

I'm trying to convert from EPSG 26191 to WGS, here is the code im using to transform but it still prints for me when I get the SRID as 26191.

    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:26191");
    CoordinateReferenceSystem targetCRS= CRS.decode("EPSG:4326");
    MathTransform transform = CRS.findMathTransform(targetCRS, sourceCRS);
    var x = JTS.transform(sourceGeometry, transform);
    System.out.println(x.getSRID());
6
  • 1
    do the actual coordinates change? GeoTools (and JTS) don't actually do anything with the SRID stored in the geometry
    – Ian Turton
    Commented Jun 13, 2022 at 10:58
  • related to gis.stackexchange.com/questions/97265/…
    – Ian Turton
    Commented Jun 13, 2022 at 11:00
  • oh yes! you're right thank you SRID doesn't change but my geometry coordinates changed ! Commented Jun 13, 2022 at 12:23
  • But there is still a problem my polygon is not where it supposed to be i don't know why Commented Jun 13, 2022 at 12:24
  • please add an example input and the expected and observed output
    – Ian Turton
    Commented Jun 13, 2022 at 12:41

1 Answer 1

1

After debugging I noticed that the geometry is changed but the SRID is not. As @lan Turton told me, you can update it yourself if you want. One thing I noticed is that the long lat is inversed and for that you just need to add the attribute true to CRS.decode method.

sourceCRS = CRS.decode("EPSG:26195", true);
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326", true);
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
return JTS.transform(sourceGeometry, transform);
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.