geometry-api-java: OGCGeometry#union of geometries of different dimensions is incorrect
I’m seeing incorrect results when calling OGCGeometry#union
on geometries of different dimensions, e.g. point and linestring, linestring and polygon, etc.
For example, the following tests
public class TestOGCUnion
{
@Test
public void testPoint()
{
assertUnion("POINT (1 2)", "LINESTRING EMPTY", "POINT (1 2)");
}
@Test
public void testPointWithLinestring()
{
assertUnion("POINT (1 2)", "LINESTRING (3 4, 5 6)", "GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6))");
}
@Test
public void testLinestring()
{
assertUnion("LINESTRING (1 2, 3 4)", "POLYGON EMPTY", "LINESTRING (1 2, 3 4)");
}
@Test
public void testLinestringWithPolygon()
{
assertUnion("LINESTRING (1 2, 3 4)", "POLYGON ((0 0, 1 1, 0 1, 0 0))", "GEOMETRYCOLLECTION (LINESTRING (1 2, 3 4), POLYGON ((0 0, 1 1, 0 1, 0 0)))");
}
private void assertUnion(String leftWkt, String rightWkt, String expectedWkt)
{
OGCGeometry union = OGCGeometry.fromText(leftWkt).union(OGCGeometry.fromText(rightWkt));
assertEquals(expectedWkt, union.asText());
}
}
fail with
Expected :POINT (1 2)
Actual :MULTILINESTRING EMPTY
at com.esri.core.geometry.TestOGCUnion.testPoint(TestOGCUnion.java:26)
Expected :GEOMETRYCOLLECTION (POINT (1 2), LINESTRING (3 4, 5 6))
Actual :LINESTRING (3 4, 5 6)
at com.esri.core.geometry.TestOGCUnion.testPointWithLinestring(TestOGCUnion.java:32)
Expected :LINESTRING (1 2, 3 4)
Actual :MULTIPOLYGON EMPTY
at com.esri.core.geometry.TestOGCUnion.testLinestring(TestOGCUnion.java:38)
Expected :GEOMETRYCOLLECTION (LINESTRING (1 2, 3 4), POLYGON ((0 0, 1 1, 0 1, 0 0)))
Actual :POLYGON ((0 0, 1 1, 0 1, 0 0))
at com.esri.core.geometry.TestOGCUnion.testLinestringWithPolygon(TestOGCUnion.java:44)
I’m also seeing union of POLYGON ((0 0, 1 1, 0 1, 0 0))
and POLYGON ((0.5 0.5, 0.7 0.7, 0.5 0.7, 0.5 0.5))
being POLYGON ((0.7 0.7, 1 1, 0 1, 0 0, 0.5 0.5, 0.7 0.7))
and not POLYGON ((0 0, 1 1, 0 1, 0 0))
. The shapes are the same, but union result has redundant points. Is this expected?
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 17 (15 by maintainers)
@jgravois John, thanks for explaining. @stolstov Looks like Sergey’s PR https://github.com/Esri/geometry-api-java/pull/178 improves
union
method to perform simplification inline. With these change, we’ll be able to useunion
in Presto directly.@mbasmanova Nothing else, unless you would like to do more verification.
@mbasmanova The asText method does not round. Those numbers are due to floating point calculations. The OperatorExportToWKT allows rounding though (see WktExportFlags.java), but OGCGeometry.asText does not have the control.