Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the NE min zoom to cull places at low zooms. #1693

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions integration-test/1687-fewer-places-at-low-zoom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# -*- encoding: utf-8 -*-
from . import FixtureTest


class LowZoomPlacesTest(FixtureTest):

def test_zoom_1(self):
import dsl

z, x, y = (3, 7, 3)

self.generate_fixtures(
dsl.way(607976629, dsl.tile_centre_shape(z, x, y), {
"min_zoom": 1,
"__ne_max_zoom": 10,
"__ne_min_zoom": 3,
"area": 0,
"place": "country",
"name": "Guam",
"population": 185427,
"source": "openstreetmap.org",
}),
)

# should exist at zoom 3 (the min zoom from NE)
self.assert_has_feature(
z, x, y, 'places', {
'id': 607976629,
'kind': 'country',
'name': 'Guam',
})

# should exist at zoom 2 (one past the min zoom)
self.assert_has_feature(
z-1, x//2, y//2, 'places', {
'id': 607976629,
'kind': 'country',
'name': 'Guam',
})

# should not exist at zoom 1
self.assert_no_matching_feature(
z-2, x//4, y//4, 'places', {
'id': 607976629,
})
6 changes: 6 additions & 0 deletions queries.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,12 @@ post_process:
params:
layer: places

# after we have the NE min zoom, drop features which we won't be displaying
# at this zoom.
- fn: vectordatasource.transform.min_zoom_filter
params:
layers: [places]

- fn: vectordatasource.transform.overlap
params:
base_layer: buildings
Expand Down
26 changes: 26 additions & 0 deletions vectordatasource/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -7336,6 +7336,32 @@ def max_zoom_filter(ctx):
return None


def min_zoom_filter(ctx):
"""
For features with a min_zoom, remove them if it's > nominal zoom + 1.
"""

params = _Params(ctx, 'min_zoom_filter')
layers = params.required('layers', typ=list)
nominal_zoom = ctx.nominal_zoom

for layer_name in layers:
layer = _find_layer(ctx.feature_layers, layer_name)

features = layer['features']
new_features = []

for feature in features:
_, props, _ = feature
min_zoom = props.get('min_zoom')
if min_zoom is not None and min_zoom <= nominal_zoom + 1:
new_features.append(feature)

layer['features'] = new_features

return None


def tags_set_ne_min_max_zoom(ctx):
"""
Override the min zoom and max zoom properties with __ne_* variants from
Expand Down