Skip to content

Commit

Permalink
filter out points when min size is set
Browse files Browse the repository at this point in the history
  • Loading branch information
msbarry committed Dec 19, 2024
1 parent 581824a commit 5e86826
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5e86826

Please sign in to comment.