Hi, After upgrading an application from geotools-14.3 to 21.2 I've observed strange behaviour when transforming points from one CRS (EPSG:31251) to another (EPSG:31287). The original code we had dies with an exception, however even two other tries return different results from what I got with 14.3. With an external tool I also get results which are identical to what 14.3 returns.
With 14.3 all 3 tries succeed and return the expected result: > OldWay: POINT (259878.57433310486 377178.60575377225) > Plain: GeneralDirectPosition[259878.57433310486, 377178.60575377225] > JTS: POINT (259878.57433310486 377178.60575377225) With 21.2 the geometryBuilder-based way fails, the two others return consistent but different (wrong?) results: > Plain: GeneralDirectPosition[219916.12907210115, 405574.2553041743] > JTS: POINT (219916.12907210115 405574.2553041743) > java.lang.IllegalArgumentException: DirectPosition cannot have a null CRS > at > org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl.setCRS(DirectPositionImpl.java:155) > at > org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl.<init>(DirectPositionImpl.java:125) > at > org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl.createDirectPosition(PrimitiveFactoryImpl.java:95) > at > org.geotools.geometry.jts.spatialschema.geometry.primitive.PrimitiveFactoryImpl.createPoint(PrimitiveFactoryImpl.java:103) > at > org.geotools.geometry.GeometryBuilder.createPoint(GeometryBuilder.java:352) > at > org.geotools.geometry.GeometryBuilder.createPoint(GeometryBuilder.java:320) Any idea whats going on here? Best regards, Clemens public class CoordinateTransformTest { @Test public void testTransform() throws FactoryException, TransformException { CoordinateReferenceSystem gkCRS = CRS.decode("EPSG:31251"); CoordinateReferenceSystem dbCRS = CRS.decode("EPSG:31287"); MathTransform transform = CRS.findMathTransform(gkCRS, dbCRS, true); DirectPosition2D pos2D = new DirectPosition2D(86765.44, 238436.25); DirectPosition posTransformed = transform.transform(pos2D, null); System.out.println("Plain: "+posTransformed); Point transformedPoint = (Point) JTS.transform(JTS.toGeometry(pos2D.getDirectPosition()), transform); System.out.println("JTS: "+transformedPoint); } @Test public void testOldWay() throws FactoryException, TransformException { CoordinateReferenceSystem gkCRS = CRS.decode("EPSG:31251"); CoordinateReferenceSystem dbCRS = CRS.decode("EPSG:31287"); GeometryBuilder geometryBuilder = new GeometryBuilder(gkCRS); org.opengis.geometry.primitive.Point point = geometryBuilder.createPoint(86765.44, 238436.25); MathTransform mtf = CRS.findMathTransform(gkCRS, dbCRS, true); Point transformedPoint = (Point) JTS.transform(JTS.toGeometry(point.getDirectPosition()), mtf); System.out.println("OldWay: "+transformedPoint); } } _______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users