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

Fix fixture source property #257

Merged
merged 2 commits into from
Oct 18, 2017
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
26 changes: 26 additions & 0 deletions tests/test_query_fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,32 @@ def _rel(id, nodes=None, ways=None, rels=None):
_rel(5, rels=[2, 4]),
], 5)

def test_query_source(self):
# check that the 'source' property is preserved for output features.
from shapely.geometry import Point

def min_zoom_fn(shape, props, fid, meta):
return 5

shape = Point(0, 0)
rows = [
(0, shape, {'source': 'testdata'})
]

fetch = self._make(rows, min_zoom_fn, None)

# first, check that it can get the original item back when both the
# min zoom filter and geometry filter are okay.
read_rows = fetch(5, (-1, -1, 1, 1))

self.assertEquals(1, len(read_rows))
read_row = read_rows[0]
self.assertEquals(0, read_row.get('__id__'))
# query processing code expects WKB bytes in the __geometry__ column
self.assertEquals(shape.wkb, read_row.get('__geometry__'))
self.assertEquals({'min_zoom': 5, 'source': 'testdata'},
read_row.get('__testlayer_properties__'))


class TestLabelPlacement(FixtureTestCase):

Expand Down
8 changes: 6 additions & 2 deletions tilequeue/query/fixture.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ def __call__(self, zoom, unpadded_bounds):
if not info.allows_shape_type(shape):
continue

source = lookup_source(props.get('source'))
orig_source = props.get('source')
source = lookup_source(orig_source)
meta = Metadata(source, ways, rels)
min_zoom = info.min_zoom_fn(shape, props, fid, meta)

Expand All @@ -189,7 +190,7 @@ def __call__(self, zoom, unpadded_bounds):
# this removes larger cities at low zooms, and smaller cities
# as the zoom increases and as the OSM cities start to "fade
# in".
if props.get('source') == 'naturalearthdata.com':
if orig_source == 'naturalearthdata.com':
pop_max = int(props.get('pop_max', '0'))
remove = ((zoom >= 8 and zoom < 10 and pop_max > 50000) or
(zoom >= 10 and zoom < 11 and pop_max > 20000) or
Expand All @@ -207,6 +208,9 @@ def __call__(self, zoom, unpadded_bounds):
layer_props = layer_properties(
fid, shape, props, layer_name, zoom, self.osm)

if orig_source:
layer_props['source'] = orig_source

layer_props['min_zoom'] = min_zoom
props_name = '__%s_properties__' % layer_name
read_row[props_name] = layer_props
Expand Down