From 3d222e365000e4a9e326c28a03ab7917c4775d7e Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 20 Feb 2025 17:40:56 +0100 Subject: [PATCH 1/3] don't return degenerate geometries in fast intersects operation 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 https://github.com/GIScience/ohsome-api/issues/339 --- .../oshdb/util/geometry/fip/FastPolygonOperations.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java index 0d2a1bfb4..dd3cf58b7 100644 --- a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java +++ b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java @@ -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()); } } } From 85ec4ffdddade7d1f1c2a24cb69390527a404827 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 20 Feb 2025 17:51:08 +0100 Subject: [PATCH 2/3] fix missing GeometryFactory --- .../oshdb/util/geometry/fip/FastPolygonOperations.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java index dd3cf58b7..3df340b64 100644 --- a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java +++ b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java @@ -34,6 +34,8 @@ public class FastPolygonOperations implements Serializable { private final double envWidth; private final double envHeight; + private final GeometryFactory gf = new GeometryFactory(); + /** * Constructor using a given geometry {@code geom} and geometry type {@code P}. * @@ -50,8 +52,6 @@ public

FastPolygonOperations(P geom) { envWidth = env.getMaxX() - env.getMinX(); envHeight = env.getMaxY() - env.getMinY(); - GeometryFactory gf = new GeometryFactory(); - Geometry[] result = new Geometry[numBands * numBands]; traverseQuads(bandIterations, 0, 0, env, geom, gf, result); @@ -184,7 +184,6 @@ public Geometry intersection(Geometry other) { } assert intersector != null; - Geometry result; if (other instanceof GeometryCollection) { result = other.intersection(intersector); From 37ee3a6fb81c675e56635f68a4f0f05cc7d9a120 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 20 Feb 2025 18:21:43 +0100 Subject: [PATCH 3/3] add missing return --- .../ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java | 1 + 1 file changed, 1 insertion(+) diff --git a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java index 3df340b64..6e85a9929 100644 --- a/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java +++ b/oshdb-util/src/main/java/org/heigit/ohsome/oshdb/util/geometry/fip/FastPolygonOperations.java @@ -193,5 +193,6 @@ public Geometry intersection(Geometry other) { if (result.getDimension() != other.getDimension()) { return gf.createEmpty(other.getDimension()); } + return result; } }