How to use the tilecloud.TileLayout 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 / layout / wmts.py View on Github external
from tilecloud import TileLayout


class WMTSTileLayout(TileLayout):
    def __init__(
        self,
        url="",
        layer=None,
        style=None,
        format=None,
        tile_matrix_set=None,
        tile_matrix=str,
        dimensions_name=(),
        request_encoding="KVP",
    ):
        self.url = url
        self.layer = layer
        self.style = style
        self.format = format
        self.tile_matrix_set = tile_matrix_set
github camptocamp / tilecloud / tilecloud.py View on Github external
"""Return the filename for the given tile coordinate"""
        raise NotImplementedError

    def tilecoord(self, filename):
        """Return the tile coordinate for the given filename"""
        match = self.filename_re.match(filename)
        if not match:
            raise RuntimeError # FIXME
        return self._tilecoord(match)

    def _tilecoord(self, match):
        raise NotImplementedError



class OSMTileLayout(TileLayout):
    """OpenStreetMap tile layout"""

    PATTERN = r'[0-9]+/[0-9]+/[0-9]+'
    RE = re.compile(r'([0-9]+)/([0-9]+)/([0-9]+)\Z')

    def __init__(self):
        TileLayout.__init__(self, self.PATTERN, self.RE)

    def filename(self, tilecoord):
        return '%d/%d/%d' % (tilecoord.z, tilecoord.x, tilecoord.y)

    def _tilecoord(self, match):
        return TileCoord(*map(int, match.groups()))
github camptocamp / tilecloud / tilecloud.py View on Github external
PATTERN = r'[0-9]+/[0-9]+/[0-9]+'
    RE = re.compile(r'([0-9]+)/([0-9]+)/([0-9]+)\Z')

    def __init__(self):
        TileLayout.__init__(self, self.PATTERN, self.RE)

    def filename(self, tilecoord):
        return '%d/%d/%d' % (tilecoord.z, tilecoord.x, tilecoord.y)

    def _tilecoord(self, match):
        return TileCoord(*map(int, match.groups()))



class I3DTileLayout(TileLayout):
    """I3D (FHNW/OpenWebGlobe) tile layout"""

    PATTERN = r'(?:[0-3]{2}/)*[0-3]{1,2}'
    RE = re.compile(PATTERN + r'\Z')

    def __init__(self):
        TileLayout.__init__(self, self.PATTERN, self.RE)

    def filename(self, tilecoord):
        return '/'.join(re.findall(r'[0-3]{1,2}', I3DTileLayout.quadcode_from_tilecoord(tilecoord)))

    def _tilecoord(self, match):
        return I3DTileLayout.tilecoord_from_quadcode(re.sub(r'/', '', match.group()))

    @staticmethod
    def quadcode_from_tilecoord(tilecoord):
github camptocamp / tilecloud / tilecloud / layout / wms.py View on Github external
from urllib.parse import urlencode

from tilecloud import TileLayout


class WMSTileLayout(TileLayout):
    def __init__(self, url, layers, srs, format, tilegrid, border=0, params=None):
        if params is None:
            params = {}
        self.tilegrid = tilegrid
        self.url = url
        self.border = border
        self.params = {
            "LAYERS": layers,
            "FORMAT": format,
            "TRANSPARENT": "TRUE" if format == "image/png" else "FALSE",
            "SERVICE": "WMS",
            "VERSION": "1.1.1",
            "REQUEST": "GetMap",
            "STYLES": "",
            "SRS": srs,
        }
github camptocamp / tilecloud / tilecloud / layout / re_.py View on Github external
from tilecloud import TileLayout


class RETileLayout(TileLayout):
    def __init__(self, pattern, filename_re):
        self.pattern = pattern
        self.filename_re = filename_re

    def tilecoord(self, filename):
        match = self.filename_re.match(filename)
        if not match:
            raise ValueError(
                "invalid literal for {0!s}.tilecoord(): {1!r}".format(self.__class__.__name__, filename)
            )
        return self._tilecoord(match)

    @staticmethod
    def _tilecoord(match):  # pragma: no cover
        raise NotImplementedError
github camptocamp / tilecloud / tilecloud / layout / wrapped.py View on Github external
import re

from tilecloud import TileLayout


class WrappedTileLayout(TileLayout):
    """A tile layout with an option prefix and/or suffix"""

    def __init__(self, tilelayout, prefix="", suffix=""):
        self.tilelayout = tilelayout
        self.prefix = prefix
        self.suffix = suffix
        prefix_re = re.escape(self.prefix)
        suffix_re = re.escape(self.suffix)
        self.pattern = "".join((prefix_re, tilelayout.pattern, suffix_re))
        filename_pattern = "".join((prefix_re, r"(", self.tilelayout.pattern, r")", suffix_re, r"\Z"))
        self.filename_re = re.compile(filename_pattern)

    def filename(self, tilecoord, metadata=None):
        return "".join((self.prefix, self.tilelayout.filename(tilecoord, metadata), self.suffix))

    def tilecoord(self, filename):
github camptocamp / tilecloud / tilecloud.py View on Github external
def __init__(self):
        TileLayout.__init__(self, self.PATTERN, self.RE)