Hi,
I try to create a buffer of a transformed input geometry. Already the result of the transformation of the input geometry leads to a strange geometry that contains the right coordinate but the wrong SRID. The reason seems to be the GeometryFactory, which is (in my case) specialized to create geometries with a special SRID. I thought this is the best way to create geometries (no need to manually set SRID at the geometry) but now I am not sure about it.
What would be the right way to create a correct geometry (correct SRID and GeometryFactory) as input?
The sample below shows my problem.
public class TransformationTest {
static {
System.setProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE.toString());
}
@Test
public void transform() throws Exception {
int sourceSrid = 4326;
int targetSrid = 25832;
GeometryFactory gf = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), sourceSrid);
Point sourceGeometry = gf.createPoint(new Coordinate(13, 52));
CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:" + sourceSrid);
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:" + targetSrid);
MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS);
Geometry targetGeometry = JTS.transform(sourceGeometry, transform);
assertEquals("targetGeometry SRID not as expected", targetSrid, targetGeometry.getSRID()); // fail
// assertEquals("targetGeometry factory SRID not as expected", targetSrid, targetGeometry.getFactory()
// .getSRID());
Geometry targetBuffer = targetGeometry.buffer(100);
assertEquals("Buffer SRID not as expected", targetSrid, targetBuffer.getSRID()); // fail
}
}
Thanks in advance.
Yours sincerely.
M.Sc. Robin Pradel
Senior Systems Engineer
IVU Traffic Technologies AG
Bundesallee 88, D-12161 Berlin
http://www.ivu.de