def mercator_point_to_coord(z, x, y): coord = Coordinate( column=x + half_earth_circum, row=half_earth_circum - y, zoom=coord_mercator_point_zoom, ) coord = coord.zoomTo(z).container() return coord
def mercator_point_to_coord_fractional(z, x, y): coord = Coordinate( column=x + half_earth_circum, row=half_earth_circum - y, zoom=coord_mercator_point_zoom, ) coord = coord.zoomTo(z) return coord
def mercator_point_to_coord(z, x, y): coord = Coordinate( column=x + half_earth_circum, row=half_earth_circum - y, zoom=coord_mercator_point_zoom, ) coord = coord.zoomTo(z).container() return coord
def mercator_point_to_coord_fractional(z, x, y): coord = Coordinate( column=x + half_earth_circum, row=half_earth_circum - y, zoom=coord_mercator_point_zoom, ) coord = coord.zoomTo(z) return coord
def _fetch_data(self, shape_fn, source_table): from tilequeue.query.common import LayerInfo from tilequeue.query.rawr import make_rawr_data_fetcher from tilequeue.tile import coord_to_mercator_bounds from ModestMaps.Core import Coordinate top_zoom = 10 max_zoom = top_zoom + 6 def min_zoom_fn(shape, props, fid, meta): return top_zoom def props_fn(shape, props, fid, meta): return {'kind': 'country'} z, x, y = (max_zoom, 0, 0) tile = Coordinate(zoom=z, column=x, row=y) top_tile = tile.zoomTo(top_zoom).container() bounds = coord_to_mercator_bounds(tile) shape = shape_fn(bounds) props = { 'name': 'Foo', 'admin_level': '2', 'boundary': 'administrative', } source = 'test' tables = TestGetTable({ source_table: [ (1, shape.wkb, props), ], }, source) layers = { 'boundaries': LayerInfo(min_zoom_fn, props_fn), } storage = ConstantStorage(tables) fetch = make_rawr_data_fetcher(top_zoom, max_zoom, storage, layers, [dict(type="osm")]) for fetcher, _ in fetch.fetch_tiles(_wrap(top_tile)): read_rows = fetcher(tile.zoom, coord_to_mercator_bounds(tile)) return read_rows
def test_tilequeue_explode_and_intersect(self): from tilequeue.command import explode_and_intersect from tilequeue.tile import coord_marshall_int from tilequeue.tile import coord_unmarshall_int from ModestMaps.Core import Coordinate sample_coord = Coordinate(zoom=14, column=250, row=250) sample_coord_int = coord_marshall_int(sample_coord) tiles_of_interest = [sample_coord_int] for i in (10, 11, 12, 13): coord = sample_coord.zoomTo(i) coord_int = coord_marshall_int(coord) tiles_of_interest.append(coord_int) exploded = explode_and_intersect([sample_coord_int], tiles_of_interest, until=11) coord_ints = list(exploded) for coord_int in coord_ints: coord = coord_unmarshall_int(coord_int) self.failUnless(coord.zoom > 10) self.assertEqual(4, len(coord_ints))
def _test(self, layer_name, props): from ModestMaps.Core import Coordinate from tilequeue.tile import coord_to_mercator_bounds from shapely.geometry import box from tilequeue.query.rawr import TilePyramid top_zoom = 10 max_zoom = top_zoom + 6 def min_zoom_fn(shape, props, fid, meta): return top_zoom tile = Coordinate(zoom=15, column=0, row=0) top_tile = tile.zoomTo(top_zoom).container() tile_pyramid = TilePyramid(top_zoom, top_tile.column, top_tile.row, max_zoom) bounds = coord_to_mercator_bounds(tile) shape = box(*bounds) tables = TestGetTable( {'planet_osm_polygon': [ (1, shape.wkb, props), ]}) label_placement_layers = { 'polygon': set([layer_name]), } fetch = self._make(min_zoom_fn, None, tables, tile_pyramid, layer_name=layer_name, label_placement_layers=label_placement_layers) for fetcher, _ in fetch.fetch_tiles(_wrap(top_tile)): read_rows = fetcher(tile.zoom, bounds) return read_rows
def test_tilequeue_explode_and_intersect(self): from tilequeue.command import explode_and_intersect from tilequeue.tile import coord_marshall_int from tilequeue.tile import coord_unmarshall_int from ModestMaps.Core import Coordinate sample_coord = Coordinate(zoom=14, column=250, row=250) sample_coord_int = coord_marshall_int(sample_coord) tiles_of_interest = [sample_coord_int] for i in (10, 11, 12, 13): coord = sample_coord.zoomTo(i) coord_int = coord_marshall_int(coord) tiles_of_interest.append(coord_int) exploded, metrics = explode_and_intersect( [sample_coord_int], tiles_of_interest, until=11) coord_ints = list(exploded) for coord_int in coord_ints: coord = coord_unmarshall_int(coord_int) self.failUnless(coord.zoom > 10) self.assertEqual(4, len(coord_ints)) self.assertEqual(4, metrics['hits']) self.assertEqual(0, metrics['misses']) self.assertEqual(4, metrics['total'])
def test_buffered_land(self): # the buffered land is a polygon in the boundaries table (sort of), # but we shouldn't turn it into linestrings of the exterior ring. it # should stay as a polygon otherwise the border features won't be # correctly assigned maritime boundary properties, and they'll all # appear to be maritime boundaries. :-( from tilequeue.query.common import LayerInfo from tilequeue.query.rawr import make_rawr_data_fetcher from tilequeue.tile import coord_to_mercator_bounds from ModestMaps.Core import Coordinate from shapely.geometry import Polygon import shapely.wkb top_zoom = 10 max_zoom = top_zoom + 6 def min_zoom_fn(shape, props, fid, meta): return 8 def props_fn(shape, props, fid, meta): props['kind'] = 'maritime' return props z, x, y = (max_zoom, 0, 0) tile = Coordinate(zoom=z, column=x, row=y) top_tile = tile.zoomTo(top_zoom).container() bounds = coord_to_mercator_bounds(tile) shape = Polygon([ [bounds[0], bounds[1]], [bounds[0], bounds[3]], [bounds[2], bounds[1]], [bounds[0], bounds[1]], ]) props = { 'kind': 'maritime', 'maritime_boundary': True, 'source': 'tilezen.org', 'min_zoom': 0, } source = 'tilezen.org' tables = TestGetTable({ 'buffered_land': [ (1, shape.wkb, props), ], }, source) layers = { 'boundaries': LayerInfo(min_zoom_fn, props_fn), } storage = ConstantStorage(tables) index_cfg = [{ 'type': 'simple', 'table': 'buffered_land', 'layer': 'boundaries', }] fetch = make_rawr_data_fetcher(top_zoom, max_zoom, storage, layers, index_cfg) for fetcher, _ in fetch.fetch_tiles(_wrap(top_tile)): read_rows = fetcher(tile.zoom, coord_to_mercator_bounds(tile)) self.assertEqual(len(read_rows), 1) props = read_rows[0]['__boundaries_properties__'] self.assertEqual(props.get('kind'), 'maritime') # check no special boundaries geometry - should just be the polygon self.assertIsNone(read_rows[0].get('__boundaries_geometry__')) shape = shapely.wkb.loads(read_rows[0]['__geometry__']) self.assertEqual(shape.geom_type, 'Polygon')