Skip to content

Commit

Permalink
don't return degenerate geometries in fast intersects operation
Browse files Browse the repository at this point in the history
when a geometry only touches the clipping polygon (and has no points inside the poly), `intersector.intersection()` will produce a "degenerate" version of the original geometry: a (multi)linestring when the geometry was a polygon, or a (multi)point when the geometry was a linestring.
This can lead to inconsistencies when a geometry-type filter is used (e.g. `geometry: polygon`), as the output will then potentially also contain geometries that don't match the filter.

Fixes GIScience/ohsome-api#339
  • Loading branch information
tyrasd authored Feb 20, 2025
1 parent a196cc9 commit 3d222e3
Showing 1 changed file with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,15 @@ public Geometry intersection(Geometry other) {
}

assert intersector != null;

Geometry result;
if (other instanceof GeometryCollection) {
return other.intersection(intersector);
result = other.intersection(intersector);
} else {
return intersector.intersection(other);
result = intersector.intersection(other);
}
if (result.getDimension() != other.getDimension()) {
return gf.createEmpty(other.getDimension());
}
}
}

0 comments on commit 3d222e3

Please sign in to comment.