How to use the mercantile.Tile function in mercantile

To help you get started, we’ve selected a few mercantile 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 mapbox / mercantile / tests / test_funcs.py View on Github external
        mercantile.Tile(10, 10, 10),
    ],
)
def test_tiles_roundtrip(t):
    """tiles(bounds(tile)) gives the tile"""
    res = list(mercantile.tiles(*mercantile.bounds(t), zooms=[t.z]))
    assert len(res) == 1
    val = res.pop()
    assert val.x == t.x
    assert val.y == t.y
    assert val.z == t.z
github mapbox / mercantile / tests / test_funcs.py View on Github external
def test_empty_quadkey_to_tile():
    qk = ""
    expected = mercantile.Tile(0, 0, 0)
    assert mercantile.quadkey_to_tile(qk) == expected
github mapbox / robosat / tests / test_tiles.py View on Github external
def test_slippy_map_directory(self):
        root = "tests/fixtures/images"
        tiles = [tile for tile in tiles_from_slippy_map(root)]
        self.assertEqual(len(tiles), 3)

        tile, path = tiles[0]
        self.assertEqual(type(tile), mercantile.Tile)
        self.assertEqual(path, "tests/fixtures/images/18/69105/105093.jpg")
github mojodna / marblecutter / examples / buffered_normal_tile.py View on Github external
tile = Tile(0, 0, zoom)
    (headers, data) = tiling.render_tile(
        tile,
        PostGISCatalog(),
        format=PNG(),
        transformation=Normal(collar=2),
        scale=2)

    print("Headers: ", headers)

    with open("tmp/{}_{}_{}_buffered_normal.png".format(
            tile.z, tile.x, tile.y), "w") as f:
        f.write(data)

    tile = Tile(0, 2**zoom - 1, zoom)
    (headers, data) = tiling.render_tile(
        tile,
        PostGISCatalog(),
        format=PNG(),
        transformation=Normal(collar=2),
        scale=2)

    print("Headers: ", headers)

    with open("tmp/{}_{}_{}_buffered_normal.png".format(
            tile.z, tile.x, tile.y), "w") as f:
        f.write(data)

    tile = Tile(2**2 - 1, 2**zoom - 1, zoom)
    (headers, data) = tiling.render_tile(
        tile,
github mojodna / marblecutter / examples / tile.py View on Github external
# noqa
# coding=utf-8
from __future__ import print_function

import logging

from marblecutter import tiling
from marblecutter.catalogs import PostGISCatalog
from marblecutter.formats import GeoTIFF
from mercantile import Tile

logging.basicConfig(level=logging.INFO)

if __name__ == "__main__":
    tile = Tile(324, 787, 11)
    (headers, data) = tiling.render_tile(
        tile, PostGISCatalog(), format=GeoTIFF(), scale=2)

    print("headers: ", headers)

    with open("tmp/11_324_787.tif", "w") as f:
        f.write(data)
github cogeotiff / rio-tiler / rio_tiler / main.py View on Github external
Returns
    -------
    data : numpy ndarray
    mask: numpy array

    """
    with rasterio.open(address) as src:
        bounds = transform_bounds(src.crs, "epsg:4326", *src.bounds, densify_pts=21)

        if not utils.tile_exists(bounds, tile_z, tile_x, tile_y):
            raise TileOutsideBounds(
                "Tile {}/{}/{} is outside image bounds".format(tile_z, tile_x, tile_y)
            )

        mercator_tile = mercantile.Tile(x=tile_x, y=tile_y, z=tile_z)
        tile_bounds = mercantile.xy_bounds(mercator_tile)
        return utils.tile_read(src, tile_bounds, tilesize, **kwargs)
github DHI-GRAS / terracotta / terracotta / tile.py View on Github external
raise TileNotFoundError('dataset {} is timestepped, but no timestep provided'
                                    .format(dataset))

        if timestep:
            try:
                fname = ds['timesteps'][timestep]
            except KeyError:
                raise TileNotFoundError('no such timestep in dataset {}'.format(dataset))
        else:
            fname = ds['file']

        if not tile_exists(ds['meta']['wgs_bounds'], tile_z, tile_x, tile_y):
            raise TileOutOfBoundsError('Tile {}/{}/{} is outside image bounds'
                                       .format(tile_z, tile_x, tile_y))

        mercator_tile = mercantile.Tile(x=tile_x, y=tile_y, z=tile_z)
        tile_bounds = mercantile.xy_bounds(mercator_tile)
        tile = self._load_tile(fname, tile_bounds, tilesize)

        alpha_mask = self._alpha_mask(tile, dataset, tilesize)

        return tile, alpha_mask