1

I have a bounding box given in EPSG:4326 and I want to reproject it into EPSG:3035. How should I be doing it?

Here’s what I tried:

try {
    CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
    CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:3035");
    MathTransform trans4326to3035 = CRS.findMathTransform(sourceCRS, targetCRS);
    ReferencedEnvelope bounds4326 = new ReferencedEnvelope(5.0, 15.0, 47.0, 55.0, sourceCRS);
    Envelope bounds3035 = JTS.transform(bounds4326, trans4326to3035);
    System.out.println(bounds3035);
} catch (Exception e) {
    e.printStackTrace(System.err);
}

Result:

Env[-917569.8210525657 : 536626.7649395498, 8365819.661985753 : 9500037.05372034]

But these coordinate values are not what I expected. Cross-checking in QGIS, the values should be approximately 3900000 : 4700000, 2600000 : 3600000. This makes sense, because the center of projection of EPSG:3035 is 10°E, 52°N and the false easting/northing is 4321000/3210000, so the reprojected bounding box should be around that.

My Geotools version is 15.1.

marked as duplicate by Ian Turton Dec 15 '17 at 10:21

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

It’s a classic problem: The crazy Axis Order in Geotools.

Need to set

System.setProperty("org.geotools.referencing.forceXY", "true");
  • It's not so crazy, you just didn't check before you jumped in. – Ian Turton Dec 15 '17 at 10:20
  • My lesson learned: If this property is set in the main program, be sure to set it in the unit test as well. – hfs Dec 22 '17 at 22:24

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