question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

OGCGeometry#union of geometries of different dimensions is incorrect

See original GitHub issue

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?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (15 by maintainers)

github_iconTop GitHub Comments

2reactions
mbasmanovacommented, May 30, 2018

@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 use union in Presto directly.

1reaction
stolstovcommented, Jun 21, 2018

@mbasmanova Nothing else, unless you would like to do more verification.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Check Geometry—ArcGIS Pro | Documentation
The Check Geometry check finds features that contain invalid geometry. This includes features that contain null or empty geometries, empty envelopes, ...
Read more >
Class Geometry | NetTopologySuite - NTS Topology Suite
Linear geometries are simple if they do not self-intersect at points other than boundary points. Zero-dimensional geometries (points) are simple if they have...
Read more >
Simple feature access - Part 1 - OGC Portal
represented as the union of other geometric primitives of smaller dimension within the same set. NOTE The geometric primitives in the set ...
Read more >
GEOS API - Django documentation
Unioning a set of Polygon s will always return a Polygon or MultiPolygon geometry (unlike GEOSGeometry.union() , which may return geometries of lower...
Read more >
OGRGeometry Class Reference - GDAL
Returns if two geometries are different. ... Attempts to make an invalid geometry valid without losing vertices. More. ... Compute union using cascading....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found