Skip to content

Commit

Permalink
Fix RelateNG self-noding check
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-jts committed Aug 20, 2024
1 parent 79005be commit 28aa77d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,32 @@ public int locateWithDim(Coordinate pt) {
return loc;
}

public boolean isPointsOrPolygons() {
return geom instanceof Point
/**
* Indicates whether the geometry requires self-noding
* for correct evaluation of specific spatial predicates.
* Self-noding is required for geometries which may self-cross
* - i.e. lines, and overlapping polygons in GeometryCollections.
* Self-noding is not required for polygonal geometries,
* since they can only touch at vertices.
* This ensures that the coordinates of nodes created by
* crossing segments are computed explicitly.
* This ensures that node locations match in situations
* where a self-crossing and mutual crossing occur at the same logical location.
* E.g. a self-crossing line tested against a single segment
* identical to one of the crossed segments.
*
* @return true if self-noding is required for this geometry
*/
public boolean isSelfNodingRequired() {
if (geom instanceof Point
|| geom instanceof MultiPoint
|| geom instanceof Polygon
|| geom instanceof MultiPolygon;
|| geom instanceof MultiPolygon)
return false;
//-- GC with a single polygon does not need noding
if (hasAreas && geom.getNumGeometries() == 1)
return false;
return true;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ public boolean isAreaArea() {
* for correct evaluation of specific spatial predicates.
* Self-noding is required for geometries which may self-cross
* - i.e. lines, and overlapping polygons in GeometryCollections.
* Self-noding is not required for polygonal geometries.
* This ensures that the locations of nodes created by
* Self-noding is not required for polygonal geometries,
* since they can only touch at vertices.
* This ensures that the coordinates of nodes created by
* crossing segments are computed explicitly.
* This ensures that node locations match in situations
* where a self-crossing and mutual crossing occur at the same logical location.
Expand All @@ -130,9 +131,8 @@ public boolean isAreaArea() {
* @return true if self-noding is required
*/
public boolean isSelfNodingRequired() {
//TODO: change to testing for lines or GC with > 1 polygon
if (geomA.isPointsOrPolygons()) return false;
if (geomB.isPointsOrPolygons()) return false;
if (geomA.isSelfNodingRequired()) return true;
if (geomB.isSelfNodingRequired()) return true;
return predicate.requireSelfNoding();
}

Expand All @@ -141,6 +141,7 @@ public boolean isExteriorCheckRequired(boolean isA) {
}

private void updateDim(int locA, int locB, int dimension) {
//System.out.println(Location.toLocationSymbol(locA) + "/" + Location.toLocationSymbol(locB) + ": " + dimension);
predicate.updateDimension(locA, locB, dimension);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ public boolean requireSelfNoding() {
return pred.requireSelfNoding();
}

public boolean requireInteraction() {
return pred.requireInteraction();
}

@Override
public boolean requireCovers(boolean isSourceA) {
return pred.requireCovers(isSourceA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,17 @@ public void testEmptyMultiPointElements() {
checkIntersectsDisjoint(a, b, true);
}

public void testPolygonContainingPointsInBoundary() {
String a = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
String b = "GEOMETRYCOLLECTION (POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)), MULTIPOINT ((0 2), (0 5)))";
checkEquals(a, b, true);
}

public void testPolygonContainingLineInBoundary() {
String a = "POLYGON ((0 0, 0 10, 10 10, 10 0, 0 0))";
String b = "GEOMETRYCOLLECTION (POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0)), LINESTRING (0 2, 0 5))";
checkEquals(a, b, true);
}


}

0 comments on commit 28aa77d

Please sign in to comment.