Skip to content

Commit

Permalink
Expose min_size in configurable schema (#421)
Browse files Browse the repository at this point in the history
Co-authored-by: Mike Barry <[email protected]>
  • Loading branch information
wipfli and msbarry authored Jul 18, 2023
1 parent 4c1503e commit 68c2d7f
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 0 deletions.
4 changes: 4 additions & 0 deletions planetiler-custommap/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,8 @@ A feature is a defined set of objects that meet a specified filter criteria.
- `exclude_when` - A [Boolean Expression](#boolean-expression) which determines if a feature that matched the include
expression should be skipped. If unspecified, no exclusion filter is applied.
- `min_zoom` - An [Expression](#expression) that returns the minimum zoom to render this feature at.
- `min_size` - An [Expression](#expression) that returns the minimum length of line features or square root of the
minimum area of polygon features to emit below the maximum zoom-level of the map.
- `attributes` - An array of [Feature Attribute](#feature-attribute) objects that specify the attributes to be included
on this output feature.

Expand Down Expand Up @@ -672,6 +674,8 @@ docker run -v "$(pwd)/data":/data ghcr.io/onthegomap/planetiler:latest verify /d
- `geometry` - Geometry type of the expected output feature.
- `min_zoom` - Min zoom level that the output feature appears in.
- `max_zoom` - Max zoom level that the output feature appears in.
- `min_size` - Minimum length of line features or square root of the minimum area of polygon features to emit below
the maximum zoom-level of the map.
- `tags` - Attributes expected on the output vector tile feature, or `null` if the attribute should not be set. Use
`allow_extra_tags: true` to fail if any other tags appear besides the ones specified here.
- `allow_extra_tags` - If `true`, then fail when extra attributes besides tags appear on the output feature.
Expand Down
4 changes: 4 additions & 0 deletions planetiler-custommap/planetiler.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,10 @@
"items": {
"$ref": "#/$defs/attribute"
}
},
"min_size": {
"description": "Minimum length of line features or square root of the minimum area of polygon features to emit below the maximum zoom-level of the map",
"$ref": "#/$defs/expression"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions planetiler-custommap/planetilerspec.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@
"description": "Max zoom level that the output feature appears in",
"type": "integer"
},
"min_size": {
"description": "Minimum length of line features or square root of the minimum area of polygon features to emit below the maximum zoom-level of the map",
"type": "number"
},
"tags": {
"description": "Attributes expected on the output vector tile feature, or null if the attribute should not be set. Use allow_extra_tags: true to fail if any other tags appear besides the ones specified here",
"oneOf": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public ConfiguredFeature(String layer, TagValueProducer tagValueProducer, Featur
}
processors.add(makeFeatureProcessor(feature.minZoom(), Integer.class, Feature::setMinZoom));
processors.add(makeFeatureProcessor(feature.maxZoom(), Integer.class, Feature::setMaxZoom));
processors.add(makeFeatureProcessor(feature.minSize(), Double.class, Feature::setMinPixelSize));

featureProcessors = processors.stream().filter(Objects::nonNull).toList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public record FeatureItem(
@JsonFormat(with = JsonFormat.Feature.ACCEPT_SINGLE_VALUE_AS_ARRAY) List<String> source,
@JsonProperty("min_zoom") Object minZoom,
@JsonProperty("max_zoom") Object maxZoom,
@JsonProperty("min_size") Object minSize,
@JsonProperty(required = true) FeatureGeometry geometry,
@JsonProperty("include_when") Object includeWhen,
@JsonProperty("exclude_when") Object excludeWhen,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public record OutputFeature(
GeometryType geometry,
@JsonProperty("min_zoom") Integer minZoom,
@JsonProperty("max_zoom") Integer maxZoom,
@JsonProperty("min_size") Double minSize,
@JsonProperty("at_zoom") Integer atZoom,
@JsonProperty("allow_extra_tags") Boolean allowExtraTags,
@JsonProperty("tags") Map<String, Object> tags
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public static Result validate(Profile profile, SchemaSpecification specification
validate(prefix + ".layer", issues, expected.layer(), actual.getLayer());
validate(prefix + ".minzoom", issues, expected.minZoom(), actual.getMinZoom());
validate(prefix + ".maxzoom", issues, expected.maxZoom(), actual.getMaxZoom());
validate(prefix + ".minsize", issues, expected.minSize(), actual.getMinPixelSizeAtZoom(expected.atZoom()));
validate(prefix + ".geometry", issues, expected.geometry(), GeometryType.typeOf(actual.getGeometry()));
Set<String> tags = new TreeSet<>(actualTags.keySet());
expected.tags().forEach((tag, value) -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ examples:
- layer: streets
geometry: line
min_zoom: 8
min_size: 0
tags:
bridge: false
kind: primary
Expand Down Expand Up @@ -262,6 +263,7 @@ examples:
geometry: line
min_zoom: 8
allow_extra_tags: false
min_size: 0
tags:
bridge: false
kind: primary
Expand Down Expand Up @@ -291,6 +293,7 @@ examples:
geometry: line
min_zoom: 8
allow_extra_tags: false
min_size: 0
tags:
bridge: false
kind: rail
Expand Down Expand Up @@ -707,6 +710,7 @@ examples:
layer: boundaries
geometry: line
min_zoom: 0
min_size: 0
tags:
maritime: true
admin_level: 2
Expand All @@ -723,6 +727,7 @@ examples:
layer: boundaries
geometry: line
min_zoom: 7
min_size: 0
tags:
maritime: false
admin_level: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ layers:
- source: osm
geometry: line
# TODO get min admin level from relations
min_size: 0
min_zoom:
default_value: 7
overrides:
Expand Down Expand Up @@ -379,6 +380,7 @@ layers:
features:
- source: osm
geometry: line
min_size: 0
min_zoom:
default_value: 13
overrides:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1022,4 +1022,29 @@ void testUseArgumentInSourceUrlPath() {
)));
assertEquals("example.com_file.osm.pbf", loadConfig(config).sources().get(0).defaultFileUrl());
}

@ParameterizedTest
@CsvSource("""
10,10
${10+1},11
${feature.tags.key}|9
""")
void setMinSize(String input, double output) {
var config = """
sources:
osm:
type: osm
url: geofabrik:rhode-island
local_path: data/rhode-island.osm.pbf
layers:
- id: testLayer
features:
- source: osm
min_size: %s
geometry: line
""".formatted(input);
testLinestring(config, Map.of("key", 9), feature -> {
assertEquals(output, feature.getMinPixelSizeAtZoom(11));
}, 1);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private String validateCli(Path path) {
features:
- source: osm
geometry: polygon
min_size: 10
include_when:
natural: water
attributes:
Expand Down Expand Up @@ -121,6 +122,9 @@ private Result validateWater(String layer, String geometry, String tags, String
"true,water,polygon,natural: water,allow_extra_tags: false",
"true,water,polygon,,allow_extra_tags: true",
"false,water,polygon,,allow_extra_tags: false",

"true,water,polygon,,min_size: 10",
"false,water,polygon,,min_size: 9",
})
void testValidateWaterPolygon(boolean shouldBeOk, String layer, String geometry, String tags, String allowExtraTags)
throws IOException {
Expand Down

0 comments on commit 68c2d7f

Please sign in to comment.