Skip to content

Question - empty intersection of polygons which meet at an edge? #301

Closed

Description

@DavidHollman

(The code below is C# as I'm using the library https://github.com/EchoParkLabs/geometry-api-cs)

This program creates two triangles which share the edge (10000, 0) ⟺ (5000, 5000).

I was expecting the get this edge back as the result of intersecting the triangles, but instead it returns an empty multipolygon; yet they are not disjoint.

How can I get the expected intersection result?

Thanks!


            var p1 = new Polygon();
            p1.StartPath(5000, 0);
            p1.LineTo(5000, 5000);
            p1.LineTo(10000, 0);

            // returns "MULTIPOLYGON (((5000 0, 10000 0, 5000 5000, 5000 0)))"
            var textP1 = ToWkt(p1);

            var p2 = new Polygon();
            p2.StartPath(10000, 0);
            p2.LineTo(5000, 5000);
            p2.LineTo(10000, 5000);

            // returns "MULTIPOLYGON (((10000 0, 10000 5000, 5000 5000, 10000 0)))"
            var textP2 = ToWkt(p2);

            var intersection = GeometryEngine.Intersect(p1, p2, null);

**          // returns "MULTIPOLYGON EMPTY"
            var text = ToWkt(intersection);

**          // returns false
            var areDisjoint = GeometryEngine.Disjoint(p1, p2, null);

and the helper function:

        static string ToWkt(Geometry g) => OperatorExportToWkt.Local().Execute(0, g, null);

Activity

  1. stolstov commented on May 24, 2023

    @stolstov
    Member

    @DaveInCaz Use this method instead

    public abstract GeometryCursor execute(GeometryCursor input_geometries,

    Pass dimensionMask parameter that reflects the topological dimension of the result you want. See javadoc for description.

  2. DavidHollman commented on May 25, 2023

    @DavidHollman
    ContributorAuthor

    So, I guess GeometryEngine.Intersect() is making an assumption about the dimension mask to be used? Depending on the types of geometries passed to it, what is it assuming?

    We use it fairly widely so I can't necessarily swap to the other one, at least not without understanding the differences it may cause.

    Thanks

  3. stolstov commented on May 25, 2023

    @stolstov
    Member

    @DaveInCaz GeometryEngine.Intersect() passes -1 to the dimensionMask parameter.

             *Note, when the dimensionMask is -1, then for each intersected pair of geometries,
    	 *the result has the lower of dimentions of the two geometries. That is, the dimension of the Polyline/Polyline intersection
    	 *is always 1 (that is, for polylines it never returns crossing points, but the overlaps only).
    

    Which also means means returning a polygon when inputs are polygons.

    If you want the intersection to contain all possible dimensions, pass 7, then you'll get points where corners touch, lines where sides touch, and polygons where polygons overlap.

  4. DavidHollman commented on May 25, 2023

    @DavidHollman
    ContributorAuthor

    Thanks very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions