How to use the tilecloud.BoundingPyramid function in tilecloud

To help you get started, we’ve selected a few tilecloud examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github camptocamp / tilecloud / tilecloud / store / geometry.py View on Github external
def list(self):
        bbox = self.geom.bounds
        bounds = {}
        for zoom in range(0, len(self.metatile_configuration.resolutions)):
            x_bounds = Bounds(self.unit_to_metatile(bbox[0], zoom, self.metatile_configuration.max_extent[0]),
                self.unit_to_metatile(bbox[2], zoom, self.metatile_configuration.max_extent[0]) + 1)
            y_bounds = Bounds(self.unit_to_metatile(bbox[1], zoom, self.metatile_configuration.max_extent[1]),
                self.unit_to_metatile(bbox[3], zoom, self.metatile_configuration.max_extent[1]) + 1)
            bounds[zoom] = (x_bounds, y_bounds)

        bounding_pyramid = BoundingPyramid(bounds)
        for tilecoord in bounding_pyramid:
            zoom, meta_x, meta_y = tilecoord.z, tilecoord.x, tilecoord.y
            for x in range(meta_x * self.metatile_configuration.size,
                    meta_x * self.metatile_configuration.size + self.metatile_configuration.size):
                for y in range(meta_y * self.metatile_configuration.size,
                        meta_y * self.metatile_configuration.size + self.metatile_configuration.size):
                    extent = loads_wkt(self.polygon((
                            self.tile_to_unit(x, zoom, self.metatile_configuration.max_extent[0]),
                            self.tile_to_unit(y, zoom, self.metatile_configuration.max_extent[1]),
                            self.tile_to_unit(x + 1, zoom, self.metatile_configuration.max_extent[0]),
                            self.tile_to_unit(y + 1, zoom, self.metatile_configuration.max_extent[1])
                    )))
                    tile = Tile(TileCoord(zoom, x, y), meta=tilecoord)
                    if extent.intersects(self.geom):
                        yield self.get_one(tile)
github camptocamp / tilecloud / tilecloud / store / mask.py View on Github external
def __init__(self, z, bounds, file=None, **kwargs):
        TileStore.__init__(self, **kwargs)
        self.z = z
        self.xbounds, self.ybounds = bounds
        self.width = self.xbounds.stop - self.xbounds.start
        self.height = self.ybounds.stop - self.ybounds.start
        if "bounding_pyramid" not in kwargs:
            self.bounding_pyramid = BoundingPyramid({self.z: (self.xbounds, self.ybounds)})
        if file:
            self.image = PIL.Image.open(file)
            assert self.image.mode == "1"
            assert self.image.size == (self.width, self.height)
        else:
            self.image = PIL.Image.new("1", (self.width, self.height))
        self.pixels = self.image.load()
github camptocamp / tilecloud / tilecloud.py View on Github external
def __init__(self, bounding_pyramid=None):
        self.bounding_pyramid = bounding_pyramid or BoundingPyramid()
github camptocamp / tilecloud / tilecloud / store / boundingpyramid.py View on Github external
def __init__(self, bounding_pyramid=None, **kwargs):
        TileStore.__init__(self, **kwargs)
        self.bounding_pyramid = bounding_pyramid or BoundingPyramid()
github camptocamp / tilecloud-chain / tilecloud_chain / __init__.py View on Github external
" than the 'min_resolution_seed' %s of layer %s, ignored." %
                            (
                                zoom, resolution, layer['min_resolution_seed'], layer['name']
                            )
                        )
                self.options.zoom = [
                    z for z in self.options.zoom if
                    resolutions[z] >= layer['min_resolution_seed']
                ]

        if self.options.zoom is None:
            self.options.zoom = [z for z, r in enumerate(resolutions)]

        # fill the bounding pyramid
        tilegrid = layer['grid_ref']['obj']
        bounding_pyramid = BoundingPyramid(tilegrid=tilegrid)
        for zoom in self.options.zoom:
            if zoom in self.geoms:
                extent = self.geoms[zoom].bounds

                if len(extent) == 0:
                    logger.warning("bounds empty for zoom {}".format(zoom))
                else:
                    minx, miny, maxx, maxy = extent
                    px_buffer = layer['px_buffer']
                    m_buffer = px_buffer * resolutions[zoom]
                    minx -= m_buffer
                    miny -= m_buffer
                    maxx += m_buffer
                    maxy += m_buffer
                    bounding_pyramid.add(tilegrid.tilecoord(
                        zoom,
github camptocamp / tilecloud / tilecloud / store / tilejson.py View on Github external
def __init__(self, tile_json, urls_key="tiles", **kwargs):
        # FIXME schema
        # FIXME version 1.0.0 support
        d = json.loads(tile_json)
        assert "tiles" in d
        assert isinstance(d["tiles"], list)
        assert len(d["tiles"]) > 0
        for key in self.KEYS:
            kwargs.setdefault(key, d.get(key))
        if "bounding_pyramid" not in kwargs:
            zmin, zmax = d.get("minzoom", 0), d.get("maxzoom", 22)
            if "bounds" in d:
                lonmin, latmin, lonmax, latmax = d["bounds"]
                bounding_pyramid = BoundingPyramid.from_wgs84(zmin, zmax, lonmin, lonmax, latmin, latmax)
            else:
                bounding_pyramid = BoundingPyramid.full(zmin, zmax)
            kwargs["bounding_pyramid"] = bounding_pyramid
        urls = d[urls_key]
        if "content_type" not in kwargs:
            exts = set(os.path.splitext(urlparse(url1).path)[1] for url1 in urls)
            content_types = set(mimetypes.types_map.get(ext) for ext in exts)
            assert len(content_types) == 1
            kwargs["content_type"] = content_types.pop()
        templates = [re.sub(r"\{([xyz])\}", lambda m: "%({0!s})d".format(m.group(1)), url2) for url2 in urls]
        tilelayouts = map(TemplateTileLayout, templates)
        URLTileStore.__init__(self, tilelayouts, **kwargs)
github camptocamp / tilecloud / tilecloud / store / tilejson.py View on Github external
def __init__(self, tile_json, urls_key="tiles", **kwargs):
        # FIXME schema
        # FIXME version 1.0.0 support
        d = json.loads(tile_json)
        assert "tiles" in d
        assert isinstance(d["tiles"], list)
        assert len(d["tiles"]) > 0
        for key in self.KEYS:
            kwargs.setdefault(key, d.get(key))
        if "bounding_pyramid" not in kwargs:
            zmin, zmax = d.get("minzoom", 0), d.get("maxzoom", 22)
            if "bounds" in d:
                lonmin, latmin, lonmax, latmax = d["bounds"]
                bounding_pyramid = BoundingPyramid.from_wgs84(zmin, zmax, lonmin, lonmax, latmin, latmax)
            else:
                bounding_pyramid = BoundingPyramid.full(zmin, zmax)
            kwargs["bounding_pyramid"] = bounding_pyramid
        urls = d[urls_key]
        if "content_type" not in kwargs:
            exts = set(os.path.splitext(urlparse(url1).path)[1] for url1 in urls)
            content_types = set(mimetypes.types_map.get(ext) for ext in exts)
            assert len(content_types) == 1
            kwargs["content_type"] = content_types.pop()
        templates = [re.sub(r"\{([xyz])\}", lambda m: "%({0!s})d".format(m.group(1)), url2) for url2 in urls]
        tilelayouts = map(TemplateTileLayout, templates)
        URLTileStore.__init__(self, tilelayouts, **kwargs)
github camptocamp / tilecloud / tilecloud / store / mbtiles.py View on Github external
def get_cheap_bounding_pyramid(self):
        bounds = {}
        for z, xstart, xstop, ystart, ystop in query(self.connection, self.BOUNDING_PYRAMID_SQL):
            bounds[z] = (Bounds(xstart, xstop), Bounds(ystart, ystop))
        return BoundingPyramid(bounds)