Expose `min_size` in configurable schema (#421)

Co-authored-by: Mike Barry <msb5014@gmail.com>
pull/630/head
Oliver Wipfli 2023-07-18 12:09:46 +02:00 zatwierdzone przez GitHub
rodzic 4c1503e9f2
commit 68c2d7f417
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
11 zmienionych plików z 52 dodań i 0 usunięć

Wyświetl plik

@ -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.
@ -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.

Wyświetl plik

@ -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"
}
}
},

Wyświetl plik

@ -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": [

Wyświetl plik

@ -84,6 +84,7 @@ public class ConfiguredFeature {
}
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();
}

Wyświetl plik

@ -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,

Wyświetl plik

@ -55,6 +55,7 @@ public record SchemaSpecification(List<Example> examples) {
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

Wyświetl plik

@ -208,6 +208,7 @@ public class SchemaValidator {
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) -> {

Wyświetl plik

@ -221,6 +221,7 @@ examples:
- layer: streets
geometry: line
min_zoom: 8
min_size: 0
tags:
bridge: false
kind: primary
@ -262,6 +263,7 @@ examples:
geometry: line
min_zoom: 8
allow_extra_tags: false
min_size: 0
tags:
bridge: false
kind: primary
@ -291,6 +293,7 @@ examples:
geometry: line
min_zoom: 8
allow_extra_tags: false
min_size: 0
tags:
bridge: false
kind: rail
@ -707,6 +710,7 @@ examples:
layer: boundaries
geometry: line
min_zoom: 0
min_size: 0
tags:
maritime: true
admin_level: 2
@ -723,6 +727,7 @@ examples:
layer: boundaries
geometry: line
min_zoom: 7
min_size: 0
tags:
maritime: false
admin_level: 4

Wyświetl plik

@ -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:
@ -379,6 +380,7 @@ layers:
features:
- source: osm
geometry: line
min_size: 0
min_zoom:
default_value: 13
overrides:

Wyświetl plik

@ -1022,4 +1022,29 @@ class ConfiguredFeatureTest {
)));
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);
}
}

Wyświetl plik

@ -77,6 +77,7 @@ class SchemaValidatorTest {
features:
- source: osm
geometry: polygon
min_size: 10
include_when:
natural: water
attributes:
@ -121,6 +122,9 @@ class SchemaValidatorTest {
"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 {