Skip to content

Commit

Permalink
Merge pull request #380 from tilezen/zerebubuth/fix-boundary-from-pol…
Browse files Browse the repository at this point in the history
…y-rawr

Fix problems with disputed boundaries from RAWR tiles
  • Loading branch information
zerebubuth authored May 23, 2019
2 parents c6a8272 + 3bf900c commit 5534cc1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
17 changes: 4 additions & 13 deletions tests/test_query_rawr.py
Original file line number Diff line number Diff line change
Expand Up @@ -783,19 +783,6 @@ def props_fn(shape, props, fid, meta):

return read_rows

def test_linestrings_dropped(self):
# test that linestrings in the RAWR tile don't make it into the tile.
from shapely.geometry import LineString

def _tile_diagonal(bounds):
return LineString([
[bounds[0], bounds[1]],
[bounds[2], bounds[3]],
])

read_rows = self._fetch_data(_tile_diagonal, 'planet_osm_line')
self.assertEqual(read_rows, [])

def test_boundaries_from_polygons(self):
# check that a polygon in the RAWR tile contributes its oriented
# (anti-clockwise) boundary to the tile data.
Expand All @@ -819,6 +806,8 @@ def _tile_triangle(bounds):
self.assertEqual(props.get('boundary'), 'administrative')
# check no area
self.assertIsNone(props.get('area'))
# check we set the flag
self.assertTrue(props.get('mz_boundary_from_polygon'))

def test_boundaries_from_multipolygons(self):
# check that the boundary extraction code also works for multipolygons
Expand Down Expand Up @@ -861,6 +850,8 @@ def _tile_squares(bounds):
self.assertEqual(props.get('boundary'), 'administrative')
# check no area
self.assertIsNone(props.get('area'))
# check we set the flag
self.assertTrue(props.get('mz_boundary_from_polygon'))


class TestBufferedLand(RawrTestCase):
Expand Down
11 changes: 5 additions & 6 deletions tilequeue/query/rawr.py
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,7 @@ def _parse_row(self, zoom, unpadded_bounds, bbox, source, fid, shape,
# disable this special processing for those features.
if read_row and '__boundaries_properties__' in read_row and \
read_row['__boundaries_properties__'].get('kind') != 'maritime':
if shape.geom_type in ('LineString', 'MultiLineString'):
read_row.pop('__boundaries_properties__')

elif shape.geom_type in ('Polygon', 'MultiPolygon'):
if shape.geom_type in ('Polygon', 'MultiPolygon'):
# make sure boundary rings are oriented in the correct
# direction; anti-clockwise for outers and clockwise for
# inners, which means the interior should be on the left.
Expand All @@ -815,12 +812,14 @@ def _parse_row(self, zoom, unpadded_bounds, bbox, source, fid, shape,
clip_shape = _lines_only(boundaries_shape.intersection(bbox))
read_row['__boundaries_geometry__'] = bytes(clip_shape.wkb)

boundary_props = read_row['__boundaries_properties__']
# we don't want area on boundaries
read_row['__boundaries_properties__'].pop('area', None)
boundary_props.pop('area', None)
boundary_props.pop('way_area', None)

# set a flag to indicate that we transformed this from a
# polygon to a boundary.
read_row['mz_boundary_from_polygon'] = True
boundary_props['mz_boundary_from_polygon'] = True

if read_row:
read_row['__id__'] = fid
Expand Down

0 comments on commit 5534cc1

Please sign in to comment.