From 5e8682622961fe41652e5e40414cd7afbf6fdedf Mon Sep 17 00:00:00 2001 From: Mike Barry Date: Thu, 19 Dec 2024 08:59:12 -0500 Subject: [PATCH 1/3] filter out points when min size is set --- .../planetiler/render/FeatureRenderer.java | 2 +- .../planetiler/PlanetilerTests.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/FeatureRenderer.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/FeatureRenderer.java index 451b01afe9..a29477ee6e 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/render/FeatureRenderer.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/render/FeatureRenderer.java @@ -83,7 +83,7 @@ public void accept(FeatureCollector.Feature feature) { } else { if (minSize > 0) { if (geometry instanceof Puntal) { - if (!feature.source().isPoint() && feature.getSourceFeaturePixelSizeAtZoom(zoom) < minSize) { + if (feature.getSourceFeaturePixelSizeAtZoom(zoom) < minSize) { // don't emit points if the line or polygon feature it came from was too small continue; } diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java index eb6b9ba5ce..f0245f2062 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java @@ -430,6 +430,49 @@ void testLabelGridLimit() throws Exception { ), results.tiles); } + + @Test + void testMinSize() throws Exception { + double x = 0.5 + Z14_WIDTH / 4; + double y = 0.5 + Z14_WIDTH / 4; + double lat = GeoUtils.getWorldLat(y); + double lng = GeoUtils.getWorldLon(x); + double delta = 5e-5; + + var results = runWithReaderFeatures( + Map.of("threads", "1", "maxzoom", "15"), + List.of( + newReaderFeature(newPoint(lng, lat), Map.of( + "type", "point" + )), + newReaderFeature(rectangle(lng - delta, lat - delta, lng + delta, lat + delta), Map.of( + "type", "poly" + )), + newReaderFeature(newLineString(lng - delta, lat, lng + delta, lat), Map.of( + "type", "line" + )) + ), + (in, features) -> features.centroid("layer") + .setZoomRange(13, 15) + .setMinPixelSizeAtAllZooms(1) + .inheritAttrFromSource("type") + ); + + assertSubmap(Map.of( + TileCoord.ofXYZ(Z15_TILES / 2, Z15_TILES / 2, 15), List.of( + feature(newPoint(128, 128), Map.of("type", "line")), + feature(newPoint(128, 128), Map.of("type", "poly")) + // omit point when min size is set + ), + TileCoord.ofXYZ(Z14_TILES / 2, Z14_TILES / 2, 14), List.of( + feature(newPoint(64, 64), Map.of("type", "line")), + feature(newPoint(64, 64), Map.of("type", "poly")) + ) + ), results.tiles); + // features are too small at z13 + assertEquals(List.of(), results.tiles.keySet().stream().filter(d -> d.z() < 14).toList()); + } + @ParameterizedTest @CsvSource({ "false,RETAIN_IMPORTANT_POINTS", From 38b9c603b955d805ff2911812911150356fbb0a2 Mon Sep 17 00:00:00 2001 From: Michael Barry Date: Thu, 19 Dec 2024 19:16:09 -0500 Subject: [PATCH 2/3] Update PlanetilerTests.java --- .../java/com/onthegomap/planetiler/PlanetilerTests.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java index f0245f2062..ed8c231734 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java @@ -458,7 +458,7 @@ void testMinSize() throws Exception { .inheritAttrFromSource("type") ); - assertSubmap(Map.of( + assertEquals(Map.of( TileCoord.ofXYZ(Z15_TILES / 2, Z15_TILES / 2, 15), List.of( feature(newPoint(128, 128), Map.of("type", "line")), feature(newPoint(128, 128), Map.of("type", "poly")) @@ -467,10 +467,8 @@ void testMinSize() throws Exception { TileCoord.ofXYZ(Z14_TILES / 2, Z14_TILES / 2, 14), List.of( feature(newPoint(64, 64), Map.of("type", "line")), feature(newPoint(64, 64), Map.of("type", "poly")) - ) + ), // features are too small at z13 ), results.tiles); - // features are too small at z13 - assertEquals(List.of(), results.tiles.keySet().stream().filter(d -> d.z() < 14).toList()); } @ParameterizedTest From 5b946745cbf304831ca3cc938401cef4bef78049 Mon Sep 17 00:00:00 2001 From: Michael Barry Date: Thu, 19 Dec 2024 19:20:50 -0500 Subject: [PATCH 3/3] Update PlanetilerTests.java --- .../test/java/com/onthegomap/planetiler/PlanetilerTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java index ed8c231734..305b472a84 100644 --- a/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/PlanetilerTests.java @@ -467,7 +467,7 @@ void testMinSize() throws Exception { TileCoord.ofXYZ(Z14_TILES / 2, Z14_TILES / 2, 14), List.of( feature(newPoint(64, 64), Map.of("type", "line")), feature(newPoint(64, 64), Map.of("type", "poly")) - ), // features are too small at z13 + ) // features are too small at z13 ), results.tiles); }