[Jts-topo-suite-user] issue with Geometry.union
Brought to you by:
dr_jts
From: Tomas F <tof...@gm...> - 2012-03-19 11:35:35
|
Hi, I have encountered a result when running Geometry.union which I think is incorrect. There are parts of the input to union that aren't contained in the resulting geometry. The following program reproduces the issue: { WKTReader reader = new WKTReader(); com.vividsolutions.jts.geom.Polygon p1 = (com.vividsolutions.jts.geom.Polygon) reader.read("POLYGON ((42.975 -92.25, 100.0 0.0, -200.0 0.0, 126.0 -184.5, 42.975 -92.25))"); com.vividsolutions.jts.geom.Polygon p2 = (com.vividsolutions.jts.geom.Polygon) reader.read("POLYGON ((126.0 -184.5, -9.0 -34.5, -200.0 -300.0, 126.0 -184.5))"); assert p1.isValid(); assert p2.isValid(); Geometry union = p1.union(p2); double distance0 = union.distance(new GeometryFactory().createPoint(p1.getCoordinates()[0])); double distance1 = union.distance(new GeometryFactory().createPoint(p1.getCoordinates()[1])); double distance2 = union.distance(new GeometryFactory().createPoint(p1.getCoordinates()[2])); double distance3 = union.distance(new GeometryFactory().createPoint(p1.getCoordinates()[3])); System.out.println("Distance from point to union: "+distance0); System.out.println("Distance from point to union: "+distance1); System.out.println("Distance from point to union: "+distance2); System.out.println("Distance from point to union: "+distance3); assert union.covers(p1) : "(p1 U p2) must cover p1"; assert union.covers(p2) : "(p1 U p2) union must cover p2"; } Output: Distance from point to union: 0.0 Distance from point to union: 104.09834518191563 Distance from point to union: 175.19474956680358 Distance from point to union: 0.0 java.lang.AssertionError: (p1 U p2) must cover p1 Best regards /Tomas |