@@ -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' )
0 commit comments