Search code examples
c#openlayersspatialclipping

Openlayers STContains, intersecting lines


I have an app running OpenLayers and have come across an interesting problem.

I create a polygon, called Project. Then I have sub-projects that are inside that polygon.

The first time you create a sub-project, I clip the sub-project so that it is inside the Project.

SpatialManager.ClipShape(subShape, projectShape);

When you go to edit a project, I want to make sure that you keep the sub-project inside the Project.

if(projectShape.STContains(subShape).isFalse)

The problem comes with the clipping/contains. When clipping, the project and sub-project share the same boundary lines.

STContains wont be true because they share lines.

Is there anyway to check if a polygon contains a percentage of another shape, or contains with sharing lines?

Thanks.

clipping


Solution

  • You are looking for STIntersects, which will return true if either polygon has any point in common with the other, including on an edge. You might also find STTouches useful, which will return true if two polygons touch, even at a single point, but do not have any interior points inside the other. STContains isn't working for you because the polygons share a common boundary, or to quote from the DE-9IM explained below:

    Geometry b lies in the interior of a. Another definition: "a 'contains' b iff no points of b lie in the exterior of a, and at least one point of the interior of b lies in the interior of a

    There is something with the slightly scary name of Dimensionally Extended nine-Intersection Model, which is abbreviated to DE-9IM for obvious reasons, which explains the underlying theory of spatial predicates.