1

I'm trying to reproject an envelope from EPSG:4326 to EPSG:32632. I code down some tests and run them. They works, fine. Then I run again my tests with mvn clean test and they fails. This is weird. Here is a unit test to reproduce the issue:

import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.referencing.CRS;
import org.junit.Test;

public class EnvelopeTransformationTests {

  @Test
  public void envelopeFromEPSG32632ToEPSG4326() throws Exception {
    System.out.println("Now running envelopeFromEPSG32632ToEPSG4326 test.");
    ReferencedEnvelope inputEnvelope = new ReferencedEnvelope(452173.571888, 632038.902180, 4979218.777039, 5157585.195277,
    CRS.decode("EPSG:32632"));
    ReferencedEnvelope outputEnvelope = inputEnvelope.transform(CRS.decode("EPSG:4326"), true);
    System.out.println(outputEnvelope.toString());
  }

  @Test
  public void envelopeFromEPSG4326ToEPSG32632() throws Exception {
    System.out.println("Now running envelopeFromEPSG4326ToEPSG32632 test.");
    ReferencedEnvelope inputEnvelope = new ReferencedEnvelope(-180, 0, -90, 90, CRS.decode("EPSG:4326"));
    ReferencedEnvelope outputEnvelope = inputEnvelope.transform(CRS.decode("EPSG:32632"), true);
    System.out.println(outputEnvelope.toString());
  }

  @Test
  public void envelopeFromMaybeInvertedEPSG4326ToEPSG32632() throws Exception {
    System.out.println("Now running envelopeFromMaybeInvertedEPSG4326ToEPSG32632 test.");
    ReferencedEnvelope inputEnvelope = new ReferencedEnvelope(-90, 90, -180, 0, CRS.decode("EPSG:4326"));
    ReferencedEnvelope outputEnvelope = inputEnvelope.transform(CRS.decode("EPSG:32632"), true);
    System.out.println(outputEnvelope.toString());
  }
}

As in Eclipse the above tests runs fine, this is what I get as I run them by maven:

Running edu.my.geotools.sandbox.factory.EnvelopeTransformationTests
Now running envelopeFromEPSG4326ToEPSG32632 test.
--  INFO [hsqldb.db.HSQLDB4AD417742A.ENGINE] dataFileCache open start
ott 18, 2017 3:54:49 PM org.geotools.referencing.operation.projection.TransverseMercator transform
AVVERTENZA: Possible use of "Transverse_Mercator" projection outside its valid area.
Latitude 180°00.0'S is out of range (±90°).
Now running envelopeFromMaybeInvertedEPSG4326ToEPSG32632 test.
Now running envelopeFromEPSG32632ToEPSG4326 test.
ReferencedEnvelope[44.9541384522599 : 46.57182640008404, 8.375903726838398 : 10.722656250087342]
Tests run: 3, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 0.893 sec <<< FAILURE! - in edu.my.geotools.sandbox.factory.EnvelopeTransformationTests
envelopeFromEPSG4326ToEPSG32632(edu.my.geotools.sandbox.factory.EnvelopeTransformationTests)  Time elapsed: 0.839 sec  <<< ERROR!
org.geotools.referencing.operation.projection.ProjectionException: The transform result may be 10,018,754.171 meters away from the expected position. Are you sure that the input coordinates are inside this map projection area of validity? The point is located 0°00.0'E away from the central meridian and 90°00.0'S away from the latitude of origin. The projection is "Transverse_Mercator".
    at org.geotools.referencing.operation.projection.MapProjection.checkReciprocal(MapProjection.java:708)
    at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:903)
    at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
    at org.geotools.referencing.operation.transform.AbstractMathTransform.transform(AbstractMathTransform.java:237)
    at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:68)
    at org.geotools.referencing.CRS.transform(CRS.java:1345)
    at org.geotools.referencing.CRS.transform(CRS.java:1413)
    at org.geotools.geometry.jts.ReferencedEnvelope.transform(ReferencedEnvelope.java:689)
    at org.geotools.geometry.jts.ReferencedEnvelope.transform(ReferencedEnvelope.java:635)
    at edu.my.geotools.sandbox.factory.EnvelopeTransformationTests.envelopeFromEPSG4326ToEPSG32632(EnvelopeTransformationTests.java:22)

envelopeFromMaybeInvertedEPSG4326ToEPSG32632(edu.my.geotools.sandbox.factory.EnvelopeTransformationTests)  Time elapsed: 0.002 sec  <<< ERROR!
org.geotools.referencing.operation.projection.ProjectionException: The transform result may be 15,028,131.257 meters away from the expected position. Are you sure that the input coordinates are inside this map projection area of validity? The point is located 0°00.0'E away from the central meridian and 90°00.0'N away from the latitude of origin. The projection is "Transverse_Mercator".
    at org.geotools.referencing.operation.projection.MapProjection.checkReciprocal(MapProjection.java:708)
    at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:903)
    at org.geotools.referencing.operation.projection.MapProjection.transform(MapProjection.java:938)
    at org.geotools.referencing.operation.transform.AbstractMathTransform.transform(AbstractMathTransform.java:237)
    at org.geotools.referencing.operation.transform.ConcatenatedTransformDirect.transform(ConcatenatedTransformDirect.java:68)
    at org.geotools.referencing.CRS.transform(CRS.java:1345)
    at org.geotools.referencing.CRS.transform(CRS.java:1413)
    at org.geotools.geometry.jts.ReferencedEnvelope.transform(ReferencedEnvelope.java:689)
    at org.geotools.geometry.jts.ReferencedEnvelope.transform(ReferencedEnvelope.java:635)
    at edu.my.geotools.sandbox.factory.EnvelopeTransformationTests.envelopeFromMaybeInvertedEPSG4326ToEPSG32632(EnvelopeTransformationTests.java:30)


Results :

Tests in error: 
  EnvelopeTransformationTests.envelopeFromEPSG4326ToEPSG32632:22 » Projection Th...
  EnvelopeTransformationTests.envelopeFromMaybeInvertedEPSG4326ToEPSG32632:30 » Projection

Tests run: 3, Failures: 0, Errors: 2, Skipped: 0

What's wrong? Looks like a classpath issue. What am I missing? I'm usign java 8 and geotools 17.2.

UPDATE This is the maven dependency tree:

[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Transformers 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ Transformers ---
[INFO] edu.my.geotools.sandbox:Transformers:jar:0.0.1-SNAPSHOT
[INFO] +- edu.my.geotools.sandbox:TransformationModel:jar:0.0.1-SNAPSHOT:compile
[INFO] |  +- edu.myresearch:gi-core-datamodel_7_0:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  +- edu.myresearch:ogc-csw-2.0.2-ebrim-1.0:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  +- edu.myresearch:lablib-utils:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  |  +- org.apache.santuario:xmlsec:jar:1.5.6:compile
[INFO] |  |  |  |  \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] |  |  |  +- joda-time:joda-time:jar:2.7:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  +- edu.myresearch:lablib-wms:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  |  +- edu.myresearch:lablib-net:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  |  |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.4:compile
[INFO] |  |  |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.2:compile
[INFO] |  |  |  |  +- org.apache.httpcomponents:httpmime:jar:4.5.2:compile
[INFO] |  |  |  |  +- javax.mail:mail:jar:1.4.1:compile
[INFO] |  |  |  |  |  \- javax.activation:activation:jar:1.1:compile
[INFO] |  |  |  |  +- org.slf4j:jcl-over-slf4j:jar:1.6.0:compile
[INFO] |  |  |  |  \- org.reflections:reflections:jar:0.9.10:compile
[INFO] |  |  |  |     +- org.javassist:javassist:jar:3.19.0-GA:compile
[INFO] |  |  |  \- edu.myresearch:lablib-jaxb:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  |  |     \- com.google.code.findbugs:annotations:jar:2.0.1:compile
[INFO] |  |  |     +- com.sun.xml.bind:jaxb-impl:jar:2.2.3U1:compile
[INFO] |  |  |     |  \- javax.xml.bind:jaxb-api:jar:2.2.2:compile
[INFO] |  |  |     |     \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  |  |     \- jboss.jaxbintros:jboss-jaxb-intros:jar:1.0.2.GA:compile
[INFO] |  |  |        \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  |  +- edu.myresearch:ogc-gml-3.2.0:jar:12.0.8-SNAPSHOT:compile
[INFO] |  |  \- org.slf4j:slf4j-log4j12:jar:1.6.0:compile
[INFO] |  |     \- log4j:log4j:jar:1.2.14:compile
[INFO] |  \- edu.myresearch:lablib-geo:jar:12.0.8-SNAPSHOT:compile
[INFO] |  +- org.geotools:gt-api:jar:17.2:compile
[INFO] +- org.geotools:gt-main:jar:17.2:compile
[INFO] |  +- com.vividsolutions:jts:jar:1.13:compile
[INFO] |  +- org.jdom:jdom:jar:1.1.3:compile
[INFO] |  \- javax.media:jai_core:jar:1.1.3:compile
[INFO] +- org.geotools.xsd:gt-xsd-gml3:jar:17.2:compile
[INFO] |  +- org.geotools:gt-referencing:jar:17.2:compile
[INFO] |  |  +- com.googlecode.efficient-java-matrix-library:core:jar:0.26:compile
[INFO] |  |  \- net.sf.geographiclib:GeographicLib-Java:jar:1.44:compile
[INFO] |  |  +- jgridshift:jgridshift:jar:1.0:compile
[INFO] |  +- org.geotools:gt-coverage:jar:17.2:compile
[INFO] |  |  +- javax.media:jai_imageio:jar:1.1:compile
[INFO] |  |  +- it.geosolutions.imageio-ext:imageio-ext-tiff:jar:1.1.17:compile
[INFO] |  |  |  +- it.geosolutions.imageio-ext:imageio-ext-geocore:jar:1.1.17:compile
[INFO] |  |  |  +- it.geosolutions.imageio-ext:imageio-ext-utilities:jar:1.1.17:compile
[INFO] |  |  |  |  \- it.geosolutions.imageio-ext:imageio-ext-streams:jar:1.1.17:compile
[INFO] |  |  |  \- javax.media:jai_codec:jar:1.1.3:compile
[INFO] |  |  +- org.jaitools:jt-zonalstats:jar:1.4.0:compile
[INFO] |  |  +- org.jaitools:jt-utils:jar:1.4.0:compile
[INFO] |  |  +- it.geosolutions.jaiext.affine:jt-affine:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.algebra:jt-algebra:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.bandmerge:jt-bandmerge:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.bandselect:jt-bandselect:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.bandcombine:jt-bandcombine:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.border:jt-border:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.buffer:jt-buffer:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.crop:jt-crop:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.lookup:jt-lookup:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.iterators:jt-iterators:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.mosaic:jt-mosaic:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.nullop:jt-nullop:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.rescale:jt-rescale:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.scale:jt-scale:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.stats:jt-stats:jar:1.0.15:compile
[INFO] |  |  |  \- com.google.guava:guava:jar:17.0:compile
[INFO] |  |  +- it.geosolutions.jaiext.translate:jt-translate:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.utilities:jt-utilities:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.warp:jt-warp:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.zonal:jt-zonal:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.binarize:jt-binarize:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.format:jt-format:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.colorconvert:jt-colorconvert:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.errordiffusion:jt-errordiffusion:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.orderdither:jt-orderdither:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.colorindexer:jt-colorindexer:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.imagefunction:jt-imagefunction:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.piecewise:jt-piecewise:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.classifier:jt-classifier:jar:1.0.15:compile
[INFO] |  |  +- it.geosolutions.jaiext.rlookup:jt-rlookup:jar:1.0.15:compile
[INFO] |  |  \- it.geosolutions.jaiext.vectorbin:jt-vectorbin:jar:1.0.15:compile
[INFO] |  \- org.geotools.xsd:gt-xsd-gml2:jar:17.2:compile
[INFO] +- org.geotools:gt-shapefile:jar:17.2:compile
[INFO] |  \- org.geotools:gt-data:jar:17.2:compile
[INFO] +- org.geotools:gt-gml:jar:2.5.5:compile
[INFO] +- org.geotools:gt-xml:jar:17.2:compile
[INFO] |  +- org.geotools.xsd:gt-xsd-wfs:jar:17.2:compile
[INFO] |  |  +- org.geotools.xsd:gt-xsd-filter:jar:17.2:compile
[INFO] |  |  +- org.geotools.xsd:gt-xsd-fes:jar:17.2:compile
[INFO] |  |  \- org.geotools.xsd:gt-xsd-ows:jar:17.2:compile
[INFO] |  |     \- org.geotools.ogc:net.opengis.ows:jar:17.2:compile
[INFO] |  +- org.apache.xml:xml-commons-resolver:jar:1.2:compile
[INFO] |  \- org.geotools.ogc:net.opengis.wfs:jar:17.2:compile
[INFO] |     +- org.geotools.ogc:org.w3.xlink:jar:17.2:compile
[INFO] |     \- org.geotools.ogc:net.opengis.fes:jar:17.2:compile
[INFO] +- org.geotools:gt-sample-data:jar:17.2:compile
[INFO] +- org.geotools:gt-geojson:jar:17.2:compile
[INFO] |  +- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.geotools:gt-opengis:jar:17.2:compile
[INFO] |  +- net.java.dev.jsr-275:jsr-275:jar:1.0-beta-2:compile
[INFO] |  \- commons-pool:commons-pool:jar:1.5.4:compile
[INFO] +- org.geotools:gt-metadata:jar:17.2:compile
[INFO] +- org.geotools.xsd:gt-xsd-core:jar:17.2:compile
[INFO] |  +- org.geotools:gt-graph:jar:17.2:compile
[INFO] |  +- picocontainer:picocontainer:jar:1.2:compile
[INFO] |  +- commons-jxpath:commons-jxpath:jar:1.3:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] |  +- commons-io:commons-io:jar:2.1:compile
[INFO] |  +- org.eclipse.emf:common:jar:2.6.0:compile
[INFO] |  +- org.eclipse.emf:ecore:jar:2.6.1:compile
[INFO] |  \- org.eclipse.xsd:xsd:jar:2.6.0:compile
[INFO] +- org.geotools:gt-epsg-hsql:jar:17.2:compile
[INFO] |  \- org.hsqldb:hsqldb:jar:2.3.0:compile
[INFO] +- org.geotools:gt-swing:jar:17.2:compile
[INFO] |  +- org.geotools:gt-render:jar:17.2:compile
[INFO] |  |  \- org.geotools:gt-cql:jar:17.2:compile
[INFO] |  \- com.miglayout:miglayout:jar:swing:3.7:compile
[INFO] +- org.apache.commons:commons-compress:jar:1.14:compile
[INFO] +- org.tukaani:xz:jar:1.6:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.9.1:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.9.1:compile
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] \- org.mockito:mockito-core:jar:2.10.0:test
[INFO]    +- net.bytebuddy:byte-buddy:jar:1.7.4:test
[INFO]    +- net.bytebuddy:byte-buddy-agent:jar:1.7.4:test
[INFO]    \- org.objenesis:objenesis:jar:2.6:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.773 s
[INFO] Finished at: 2017-10-18T16:20:59+02:00
[INFO] Final Memory: 18M/303M
[INFO] ------------------------------------------------------------------------
  • what dependencies do you have in your pom – Ian Turton Oct 18 '17 at 14:16
  • @iant hello! As you suggest, I updated my question. – Francesco Oct 18 '17 at 14:26
0

As before this is a domain of validity issue, you can't convert a polygon going to 180W 90S to EPSG:32632 (UTM 32N), the maths breaks down and GeoTools gives you an error message.

I suspect you also have an axis ordering issue since you don't handle it explicitly and anytime I see EPSG:4326 and no explicit handling I suspect that's the issue.

Here are some tests that work (and have tests in them):

public class EnvelopeTransformationTests {
  static private ReferencedEnvelope Env32632;
  static private ReferencedEnvelope Env4326;

  @BeforeClass
  public static void setup() throws MismatchedDimensionException, NoSuchAuthorityCodeException, FactoryException {
    Env32632 = new ReferencedEnvelope(452710.82074218144, 633986.034306171, 4982950.704191831 , 5162118.78321835,
        CRS.decode("EPSG:32632"));

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

    if (decode.getCoordinateSystem().getAxis(0).getDirection().equals(AxisDirection.NORTH)) {
      Env4326 = new ReferencedEnvelope(45.0, 46.6, 8.4, 10.7,
          decode);
    } else {
      Env4326 = new ReferencedEnvelope(8.4, 10.7, 45.0, 46.6,
          decode);
    }
  }

  @Test
  public void envelopeFromEPSG32632ToEPSG4326() throws Exception {
    System.out.println("Now running envelopeFromEPSG32632ToEPSG4326 test.");

    ReferencedEnvelope outputEnvelope = Env32632.transform(CRS.decode("EPSG:4326"), true);
    System.out.println(outputEnvelope.toString());
    Assert.assertEquals("Wrong xmin",Env4326.getMinX(),outputEnvelope.getMinX(),0.1);
    Assert.assertEquals("Wrong ymin",Env4326.getMinY(),outputEnvelope.getMinY(),0.1);
    Assert.assertEquals("Wrong xmax",Env4326.getMaxX(),outputEnvelope.getMaxX(),0.1);
    Assert.assertEquals("Wrong ymax",Env4326.getMaxY(),outputEnvelope.getMaxY(),0.1);
  }



  @Test
  public void envelopeFromMaybeInvertedEPSG4326ToEPSG32632() throws Exception {
    System.out.println("Now running envelopeFromMaybeInvertedEPSG4326ToEPSG32632 test.");

    ReferencedEnvelope outputEnvelope = Env4326.transform(CRS.decode("EPSG:32632"), true);

    System.out.println(outputEnvelope.toString());
    Assert.assertEquals("Wrong xmin",Env32632.getMinX(),outputEnvelope.getMinX(),0.1);
    Assert.assertEquals("Wrong ymin",Env32632.getMinY(),outputEnvelope.getMinY(),0.1);
    Assert.assertEquals("Wrong xmax",Env32632.getMaxX(),outputEnvelope.getMaxX(),0.1);
    Assert.assertEquals("Wrong ymax",Env32632.getMaxY(),outputEnvelope.getMaxY(),0.1);
  }
}
| improve this answer | |
  • So I can't reproject a (-90,90,-180,180, EPSG:4326) envelope to EPSG:32632 because it does not make sense (so math breaks). I can convert EPSG:4326 envelopes who have sense (does not fall outside) in the target CRS. Right? – Francesco Oct 18 '17 at 17:05
  • 1
    Yes, that is exactly right – Ian Turton Oct 18 '17 at 17:06
  • What about if I have an EPSG:32632 envelope I want to reproject as EPSG:4326? Do I have to handle axis order by hand or transform method can do this for me? – Francesco Oct 19 '17 at 13:29
  • See docs.geotools.org/latest/userguide/library/referencing/… for the full discussion – Ian Turton Oct 19 '17 at 13:30
  • 1
    GeoTools will put them in the correct (or requested order) so try not to worry about it – Ian Turton Oct 26 '17 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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