Пример #1
0
def _make_layer_info(layer_data, process_yaml_cfg):
    from tilequeue.query.common import LayerInfo, ShapeType

    layers = {}
    functions = _parse_yaml_functions(process_yaml_cfg)

    for layer_datum in layer_data:
        name = layer_datum['name']
        min_zoom_fn, props_fn = functions[name]
        shape_types = ShapeType.parse_set(layer_datum['geometry_types'])
        layer_info = LayerInfo(min_zoom_fn, props_fn, shape_types)
        layers[name] = layer_info

    return layers
Пример #2
0
    def _test(self, input_layer_names, expected_layer_names):
        from shapely.geometry import Point
        from tilequeue.query.common import LayerInfo
        from tilequeue.query.fixture import make_fixture_data_fetcher
        from tilequeue.tile import coord_to_mercator_bounds
        from tilequeue.tile import mercator_point_to_coord

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

        def props_fn(shape, props, fid, meta):
            return {}

        shape = Point(0, 0)
        props = {'name': 'Foo', 'name:en': 'Bar'}

        rows = [
            (1, shape, props),
        ]

        layers = {}
        for name in input_layer_names:
            layers[name] = LayerInfo(min_zoom_fn, props_fn)
        fetch = make_fixture_data_fetcher(layers, rows)

        feature_coord = mercator_point_to_coord(16, shape.x, shape.y)
        read_rows = fetch(16, coord_to_mercator_bounds(feature_coord))
        self.assertEqual(1, len(read_rows))

        all_layer_names = set(expected_layer_names) | set(input_layer_names)
        for layer_name in all_layer_names:
            properties_name = '__%s_properties__' % layer_name
            self.assertTrue(properties_name in read_rows[0])
            for key in props.keys():
                actual_name = read_rows[0][properties_name].get(key)
                if layer_name in expected_layer_names:
                    expected_name = props.get(key)
                    self.assertEquals(
                        expected_name,
                        actual_name,
                        msg=('expected=%r, actual=%r for key=%r' %
                             (expected_name, actual_name, key)))
                else:
                    # check the name doesn't appear anywhere else
                    self.assertEquals(
                        None,
                        actual_name,
                        msg=('got actual=%r for key=%r, expected no value' %
                             (actual_name, key)))
Пример #3
0
 def _make(self,
           rows,
           min_zoom_fn,
           props_fn,
           relations=[],
           layer_name='testlayer',
           label_placement_layers={}):
     from tilequeue.query.common import LayerInfo
     from tilequeue.query.fixture import make_fixture_data_fetcher
     layers = {layer_name: LayerInfo(min_zoom_fn, props_fn)}
     return make_fixture_data_fetcher(
         layers,
         rows,
         label_placement_layers=label_placement_layers,
         relations=relations)
Пример #4
0
    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
Пример #5
0
    def _make(self,
              min_zoom_fn,
              props_fn,
              tables,
              tile_pyramid,
              layer_name='testlayer',
              label_placement_layers={},
              min_z=10,
              max_z=16):
        from tilequeue.query.common import LayerInfo
        from tilequeue.query.rawr import make_rawr_data_fetcher

        layers = {layer_name: LayerInfo(min_zoom_fn, props_fn)}
        storage = ConstantStorage(tables)
        indexes_cfg = [dict(type="osm")]
        return make_rawr_data_fetcher(
            min_z,
            max_z,
            storage,
            layers,
            indexes_cfg,
            label_placement_layers=label_placement_layers)
Пример #6
0
    def _test(self, input_layer_names, expected_layer_names):
        from shapely.geometry import Point
        from tilequeue.query.common import LayerInfo
        from tilequeue.query.rawr import make_rawr_data_fetcher
        from tilequeue.tile import coord_to_mercator_bounds
        from tilequeue.tile import mercator_point_to_coord

        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 {}

        shape = Point(0, 0)
        props = {'name': 'Foo', 'name:en': 'Bar'}

        source = 'test'
        tables = TestGetTable({
            'planet_osm_point': [
                (1, shape.wkb, props),
            ],
        }, source)

        tile = mercator_point_to_coord(max_zoom, shape.x, shape.y)
        top_tile = tile.zoomTo(top_zoom).container()

        layers = {}
        for name in input_layer_names:
            layers[name] = 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))
        # the RAWR query goes over features multiple times because of the
        # indexing, so we can't rely on all the properties for one feature to
        # be all together in the same place. this loops over all the features,
        # checking that there's only really one of them and gathering together
        # all the __%s_properties__ from all the rows for further testing.
        all_props = {}
        for row in read_rows:
            self.assertEquals(1, row['__id__'])
            self.assertEquals(shape.wkb, row['__geometry__'])
            for key, val in row.items():
                if key.endswith('_properties__'):
                    self.assertFalse(key in all_props)
                    all_props[key] = val

        all_layer_names = set(expected_layer_names) | set(input_layer_names)
        for layer_name in all_layer_names:
            properties_name = '__%s_properties__' % layer_name
            self.assertTrue(properties_name in all_props)
            for key in props.keys():
                actual_name = all_props[properties_name].get(key)
                if layer_name in expected_layer_names:
                    expected_name = props.get(key)
                    self.assertEquals(
                        expected_name,
                        actual_name,
                        msg=('expected=%r, actual=%r for key=%r' %
                             (expected_name, actual_name, key)))
                else:
                    # check the name doesn't appear anywhere else
                    self.assertEquals(
                        None,
                        actual_name,
                        msg=('got actual=%r for key=%r, expected no value' %
                             (actual_name, key)))
Пример #7
0
    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')