From 22aef0eb7958183af54955755e3d9005475e07c3 Mon Sep 17 00:00:00 2001 From: Martin Raifer Date: Thu, 31 Aug 2023 13:18:03 +0200 Subject: [PATCH] fix: areaOfInterest should not override previously set bbox (#512) --- .../oshdb/api/mapreducer/MapReducer.java | 2 +- .../oshdb/api/tests/OSMDataFiltersTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapReducer.java b/oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapReducer.java index 7fcd0bb15..49117a887 100644 --- a/oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapReducer.java +++ b/oshdb-api/src/main/java/org/heigit/ohsome/oshdb/api/mapreducer/MapReducer.java @@ -228,7 +228,7 @@ public MapReducer tagInterpreter(TagInterpreter tagInterpreter) { public MapReducer areaOfInterest(@NotNull OSHDBBoundingBox bboxFilter) { MapReducer ret = this.copy(); if (this.polyFilter == null) { - ret.bboxFilter = bboxFilter.intersection(bboxFilter); + ret.bboxFilter = ret.bboxFilter.intersection(bboxFilter); } else { ret.polyFilter = Geo.clip(ret.polyFilter, bboxFilter); ret.bboxFilter = OSHDBGeometryBuilder.boundingBoxOf(ret.polyFilter.getEnvelopeInternal()); diff --git a/oshdb-api/src/test/java/org/heigit/ohsome/oshdb/api/tests/OSMDataFiltersTest.java b/oshdb-api/src/test/java/org/heigit/ohsome/oshdb/api/tests/OSMDataFiltersTest.java index 2d6a90ca9..3491bf5b3 100644 --- a/oshdb-api/src/test/java/org/heigit/ohsome/oshdb/api/tests/OSMDataFiltersTest.java +++ b/oshdb-api/src/test/java/org/heigit/ohsome/oshdb/api/tests/OSMDataFiltersTest.java @@ -45,6 +45,28 @@ void bbox() throws Exception { assertEquals(2, result.intValue()); } + @Test + void bboxesNotIntersecting() throws Exception { + Integer result = createMapReducerOSMEntitySnapshot() + .filter("type:node") + .areaOfInterest(OSHDBBoundingBox.bboxWgs84Coordinates(0, 0, 1, 1)) + .areaOfInterest(bbox) + .timestamps(timestamps1) + .count(); + assertEquals(0, result.intValue()); + } + + @Test + void bboxesIntersecting() throws Exception { + Integer result = createMapReducerOSMEntitySnapshot() + .filter("type:node") + .areaOfInterest(OSHDBBoundingBox.bboxWgs84Coordinates(-180, -90, 180, 90)) + .areaOfInterest(bbox) + .timestamps(timestamps1) + .count(); + assertEquals(2, result.intValue()); + } + @Test void polygon() throws Exception { Integer result = createMapReducerOSMEntitySnapshot()