Skip to content

Commit b10de25

Browse files
committed
Exclude buffered land polygons from changes made in #362.
We include buffered land into the boundaries table, but we want to keep it as a polygon, not turn it into a set of outer/inner ring linestrings.
1 parent c410aa5 commit b10de25

2 files changed

Lines changed: 82 additions & 1 deletion

File tree

tests/test_query_rawr.py

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,3 +819,80 @@ def _tile_triangle(bounds):
819819
self.assertEqual(props.get('boundary'), 'administrative')
820820
# check no area
821821
self.assertIsNone(props.get('area'))
822+
823+
824+
class TestBufferedLand(RawrTestCase):
825+
826+
def test_buffered_land(self):
827+
# the buffered land is a polygon in the boundaries table (sort of),
828+
# but we shouldn't turn it into linestrings of the exterior ring. it
829+
# should stay as a polygon otherwise the border features won't be
830+
# correctly assigned maritime boundary properties, and they'll all
831+
# appear to be maritime boundaries. :-(
832+
from tilequeue.query.common import LayerInfo
833+
from tilequeue.query.rawr import make_rawr_data_fetcher
834+
from tilequeue.tile import coord_to_mercator_bounds
835+
from ModestMaps.Core import Coordinate
836+
from shapely.geometry import Polygon
837+
import shapely.wkb
838+
839+
top_zoom = 10
840+
max_zoom = top_zoom + 6
841+
842+
def min_zoom_fn(shape, props, fid, meta):
843+
return 8
844+
845+
def props_fn(shape, props, fid, meta):
846+
props['kind'] = 'maritime'
847+
return props
848+
849+
z, x, y = (max_zoom, 0, 0)
850+
tile = Coordinate(zoom=z, column=x, row=y)
851+
top_tile = tile.zoomTo(top_zoom).container()
852+
853+
bounds = coord_to_mercator_bounds(tile)
854+
shape = Polygon([
855+
[bounds[0], bounds[1]],
856+
[bounds[0], bounds[3]],
857+
[bounds[2], bounds[1]],
858+
[bounds[0], bounds[1]],
859+
])
860+
861+
props = {
862+
'kind': 'maritime',
863+
'maritime_boundary': True,
864+
'source': 'tilezen.org',
865+
'min_zoom': 0,
866+
}
867+
868+
source = 'tilezen.org'
869+
tables = TestGetTable({
870+
'buffered_land': [
871+
(1, shape.wkb, props),
872+
],
873+
}, source)
874+
875+
layers = {
876+
'boundaries': LayerInfo(min_zoom_fn, props_fn),
877+
}
878+
storage = ConstantStorage(tables)
879+
index_cfg = [{
880+
'type': 'simple',
881+
'table': 'buffered_land',
882+
'layer': 'boundaries',
883+
}]
884+
fetch = make_rawr_data_fetcher(
885+
top_zoom, max_zoom, storage, layers, index_cfg)
886+
887+
for fetcher, _ in fetch.fetch_tiles(_wrap(top_tile)):
888+
read_rows = fetcher(tile.zoom, coord_to_mercator_bounds(tile))
889+
890+
self.assertEqual(len(read_rows), 1)
891+
props = read_rows[0]['__boundaries_properties__']
892+
893+
self.assertEqual(props.get('kind'), 'maritime')
894+
# check no special boundaries geometry - should just be the polygon
895+
self.assertIsNone(read_rows[0].get('__boundaries_geometry__'))
896+
897+
shape = shapely.wkb.loads(read_rows[0]['__geometry__'])
898+
self.assertEqual(shape.geom_type, 'Polygon')

tilequeue/query/rawr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,11 @@ def _parse_row(self, zoom, unpadded_bounds, bbox, source, fid, shape,
745745
# and inner) of the polygon features in the polygons table - which are
746746
# also called the "boundary" of the polygon. the hack below replicates
747747
# the process we have in the SQL query.
748-
if read_row and '__boundaries_properties__' in read_row:
748+
#
749+
# note: we shoe-horn buffered land into boundaries, so we have to
750+
# disable this special processing for those features.
751+
if read_row and '__boundaries_properties__' in read_row and \
752+
read_row['__boundaries_properties__'].get('kind') != 'maritime':
749753
if shape.geom_type in ('LineString', 'MultiLineString'):
750754
read_row.pop('__boundaries_properties__')
751755

0 commit comments

Comments
 (0)