當前位置: 首頁>>代碼示例>>Python>>正文


Python mercantile.tile方法代碼示例

本文整理匯總了Python中mercantile.tile方法的典型用法代碼示例。如果您正苦於以下問題:Python mercantile.tile方法的具體用法?Python mercantile.tile怎麽用?Python mercantile.tile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mercantile的用法示例。


在下文中一共展示了mercantile.tile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_tiles

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def add_tiles(self, zMin, zMax):
        zooms = np.arange(zMax - zMin + 2) + zMin - 1

        obj = {
            zMin - 1: [mercantile.tile(-122.4, 37.5, zMin - 1)]
        }

        basepath = '%s/jpg' % (self.path)
        if not os.path.isdir(basepath):
            os.mkdir(basepath)

        for i in range(1, len(zooms)):
            tiles = []
            os.mkdir("%s/%s" % (basepath, zooms[i]))
            for t in obj[zooms[i - 1]]:
                for tt in mercantile.children(t):
                    tiles.append(tt)
                    if os.path.isdir("%s/%s/%s" % (basepath, zooms[i], tt.x)):
                        shutil.copy(self.imgs[int(np.random.rand() + 0.1)],
                                    "%s/%s/%s/%s.jpg" % (basepath, zooms[i], tt.x, tt.y))
                    else:
                        os.mkdir("%s/%s/%s" % (basepath, zooms[i], tt.x))
                        shutil.copy(self.imgs[int(np.random.rand() + 0.1)],
                                    "%s/%s/%s/%s.jpg" % (basepath, zooms[i], tt.x, tt.y))
            obj[zooms[i]] = tiles 
開發者ID:mapbox,項目名稱:untiler,代碼行數:27,代碼來源:test_cli.py

示例2: test_diff_zooms

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def test_diff_zooms():
    with TestTiler() as testtiles:
        testtiles.add_tiles(15, 16)
        testtiles.add_tiles(17, 18)
        tmp = testtiles.path
        runner = CliRunner()

        runner.invoke(cli, ['streamdir', tmp, tmp, '-c', '15'])

        with rio.open(os.path.join(tmp, '15-5242-12697-tile.tif')) as src:
            assert src.shape == (2048, 2048)
            assert src.count == 4

        with rio.open(os.path.join(tmp, '15-5242-12696-tile.tif')) as src:
            assert src.shape == (512, 512)
            assert src.count == 4 
開發者ID:mapbox,項目名稱:untiler,代碼行數:18,代碼來源:test_cli.py

示例3: get_bbox

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def get_bbox(minlon, minlat, maxlon, maxlat, data_url_template=None):
    ''' Get a single Frames instance of SharedStreets entities in an area.
    '''
    bounds = (minlon, minlat, maxlon, maxlat)
    ul = mercantile.tile(minlon, maxlat, tile.DATA_ZOOM)
    lr = mercantile.tile(maxlon, minlat, tile.DATA_ZOOM)
    
    tiles = [
        tile.get_tile(tile.DATA_ZOOM, x, y, data_url_template) for (x, y)
        in itertools.product(range(ul.x, lr.x+1), range(ul.y, lr.y+1))
        ]
    
    all_geometries = functools.reduce(lambda d, t: dict(d, **t.geometries), tiles, {})
    all_intersections = functools.reduce(lambda d, t: dict(d, **t.intersections), tiles, {})

    return _make_frames(all_intersections.values(), all_geometries.values(), bounds) 
開發者ID:sharedstreets,項目名稱:sharedstreets-python,代碼行數:18,代碼來源:__init__.py

示例4: _tile_range

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def _tile_range(min_tile, max_tile):
    """
    Given a min and max tile, return an iterator of
    all combinations of this tile range

    Parameters
    -----------
    min_tile: list
        [x, y, z] of minimun tile
    max_tile:
        [x, y, z] of minimun tile

    Returns
    --------
    tiles: iterator
        iterator of [x, y, z] tiles
    """
    min_x, min_y, _ = min_tile
    max_x, max_y, _ = max_tile

    return itertools.product(range(min_x, max_x + 1), range(min_y, max_y + 1)) 
開發者ID:mapbox,項目名稱:rio-rgbify,代碼行數:23,代碼來源:mbtiler.py

示例5: tile_extrema

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def tile_extrema(bounds, zoom):
    minimumTile = mercantile.tile(bounds[0], bounds[3], zoom)
    maximumTile = mercantile.tile(bounds[2], bounds[1], zoom)

    return {
        'x': {
            'min': minimumTile.x,
            'max': maximumTile.x + 1
            },
        'y': {
            'min': minimumTile.y,
            'max': maximumTile.y + 1
            }
        } 
開發者ID:mapbox,項目名稱:supermercado,代碼行數:16,代碼來源:burntiles.py

示例6: shape

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def shape(self):
        if self._bounds is None:
            _tile = mercantile.tile(180, -85.05, self.zoom_level)
            nx = _tile.x * self._tile_size
            ny = _tile.y * self._tile_size
            return tuple([self._nbands] + [ny, nx])
        else:
            return self._shape 
開發者ID:DigitalGlobe,項目名稱:gbdxtools,代碼行數:10,代碼來源:tms_image.py

示例7: _tile_coords

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def _tile_coords(self, bounds):
        """ convert mercator bbox to tile index limits """
        tfm = pyproj.Transformer.from_crs(3857, 4326, always_xy=True)
        bounds = ops.transform(tfm.transform, box(*bounds)).bounds

        # because tiles have a common corner, the tiles that cover a
        # given tile includes the adjacent neighbors.
        # https://github.com/mapbox/mercantile/issues/84#issuecomment-413113791

        west, south, east, north = bounds
        epsilon = 1.0e-10
        if east != west and north != south:
            # 2D bbox
            # shrink the bounds a small amount so that
            # shapes/tiles round trip.
            west += epsilon
            south += epsilon
            east -= epsilon
            north -= epsilon

        params = [west, south, east, north, [self.zoom_level]]
        tile_coords = [(tile.x, tile.y) for tile in mercantile.tiles(*params)]
        xtiles, ytiles = zip(*tile_coords)
        minx = min(xtiles)
        miny = min(ytiles)
        maxx = max(xtiles) 
        maxy = max(ytiles)
        return minx, miny, maxx, maxy 
開發者ID:DigitalGlobe,項目名稱:gbdxtools,代碼行數:30,代碼來源:tms_image.py

示例8: test_cog_translate_webZooms

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def test_cog_translate_webZooms():
    """
    Test Web-Optimized COG.

    - Test COG size is a multiple of 256 (mercator tile size)
    - Test COG bounds are aligned with mercator grid at max zoom
    - Test high resolution internal tiles are equal to mercator tile using
      cogdumper and rio-tiler
    - Test overview internal tiles are equal to mercator tile using
      cogdumper and rio-tiler
    """

    runner = CliRunner()
    with runner.isolated_filesystem():
        web_profile = cog_profiles.get("raw")
        web_profile.update({"blockxsize": 256, "blockysize": 256})
        config = dict(GDAL_TIFF_OVR_BLOCKSIZE="128")

        cog_translate(
            raster_path_north,
            "cogeo.tif",
            web_profile,
            quiet=True,
            web_optimized=True,
            config=config,
        )
        with rasterio.open("cogeo.tif") as out_dst:
            assert get_max_zoom(out_dst) == 8

        cog_translate(
            raster_path_north,
            "cogeo.tif",
            web_profile,
            quiet=True,
            web_optimized=True,
            latitude_adjustment=False,
            config=config,
        )
        with rasterio.open("cogeo.tif") as out_dst:
            assert get_max_zoom(out_dst) == 10 
開發者ID:cogeotiff,項目名稱:rio-cogeo,代碼行數:42,代碼來源:test_web.py

示例9: test_cli_streamdir_all_ok

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def test_cli_streamdir_all_ok():
    with TestTiler() as testtiles:
        testtiles.add_tiles(15, 18)
        tmp = testtiles.path
        runner = CliRunner()
        result = runner.invoke(cli, ['streamdir', tmp, tmp, '-c', '14'])
        assert result.output.rstrip() == os.path.join(tmp, '14-2621-6348-tile.tif')
        with rio.open(result.output.rstrip()) as src:
            assert src.shape == (4096, 4096)  # matches z18
            assert src.count == 4 
開發者ID:mapbox,項目名稱:untiler,代碼行數:12,代碼來源:test_cli.py

示例10: test_cli_streamdir_mixed_ok

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def test_cli_streamdir_mixed_ok():
    with TestTiler() as testtiles:
        testtiles.add_tiles(15, 16)
        testtiles.add_tiles(17, 18)
        tmp = testtiles.path
        runner = CliRunner()
        result = runner.invoke(cli, ['streamdir', tmp, tmp, '-c', '14'])
        assert result.output.rstrip() == os.path.join(tmp, '14-2621-6348-tile.tif')

        with rio.open(result.output.rstrip()) as src:
            assert src.shape == (4096, 4096)  # matches z18
            assert src.count == 4 
開發者ID:mapbox,項目名稱:untiler,代碼行數:14,代碼來源:test_cli.py

示例11: get_tile

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def get_tile(*args, **kwargs):
    ''' Get a single Frames instance for a tile of SharedStreets entities.
    
        All arguments are passed to tile.get_tile().
    '''
    logging.debug('get_tile', args, kwargs)
    T = tile.get_tile(*args, **kwargs)

    return _make_frames(T.intersections.values(), T.geometries.values()) 
開發者ID:sharedstreets,項目名稱:sharedstreets-python,代碼行數:11,代碼來源:__init__.py

示例12: triangulate

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def triangulate(zoom, output, bounds, tile, tableid):
    if bounds:
        bounds = np.array(bounds).astype(np.float64)
    elif tile:
        epsilon = 1.0e-10
        tile = np.array(tile).astype(np.uint16)
        tBounds = mercantile.bounds(*tile)
        bounds = np.array([
            tBounds.west + epsilon,
            tBounds.south + epsilon,
            tBounds.east - epsilon,
            tBounds.north - epsilon
            ])
    else:
        sys.exit('Error: A bounds or tile must be specified')

    tileMin = mercantile.tile(bounds[0], bounds[3], zoom)
    tileMax = mercantile.tile(bounds[2], bounds[1], zoom)

    pGet = facetParent()

    if tableid:
        gJSON = createDBinit(tileMin, tileMax, zoom, pGet, tableid)
    else:
        gJSON = createFacets(tileMin, tileMax, zoom, pGet)

    if output:
        with open(output, 'w') as oFile:
            for feat in gJSON:
                oFile.write(json.dumps(feat) + '\n')
    else:
        for feat in gJSON:
            click.echo(json.dumps(feat)) 
開發者ID:mapbox,項目名稱:make-surface,代碼行數:35,代碼來源:triangulate_raster.py

示例13: _encode_as_png

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def _encode_as_png(data, profile, dst_transform):
    """
    Uses rasterio's virtual file system to encode a (3, 512, 512)
    array as a png-encoded bytearray.

    Parameters
    -----------
    data: ndarray
        (3 x 512 x 512) uint8 RGB array
    profile: dictionary
        dictionary of kwargs for png writing
    affine: Affine
        affine transform for output tile

    Returns
    --------
    contents: bytearray
        png-encoded bytearray of the provided input data
    """
    profile["affine"] = dst_transform

    with rasterio.open("/vsimem/tileimg", "w", **profile) as dst:
        dst.write(data)

    contents = bytearray(virtual_file_to_buffer("/vsimem/tileimg"))

    return contents 
開發者ID:mapbox,項目名稱:rio-rgbify,代碼行數:29,代碼來源:mbtiler.py

示例14: _make_tiles

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def _make_tiles(bbox, src_crs, minz, maxz):
    """
    Given a bounding box, zoom range, and source crs,
    find all tiles that would intersect

    Parameters
    -----------
    bbox: list
        [w, s, e, n] bounds
    src_crs: str
        the source crs of the input bbox
    minz: int
        minumum zoom to find tiles for
    maxz: int
        maximum zoom to find tiles for

    Returns
    --------
    tiles: generator
        generator of [x, y, z] tiles that intersect
        the provided bounding box
    """
    w, s, e, n = transform_bounds(*[src_crs, "epsg:4326"] + bbox, densify_pts=0)

    EPSILON = 1.0e-10

    w += EPSILON
    s += EPSILON
    e -= EPSILON
    n -= EPSILON

    for z in range(minz, maxz + 1):
        for x, y in _tile_range(mercantile.tile(w, n, z), mercantile.tile(e, s, z)):
            yield [x, y, z] 
開發者ID:mapbox,項目名稱:rio-rgbify,代碼行數:36,代碼來源:mbtiler.py

示例15: get_tile_data

# 需要導入模塊: import mercantile [as 別名]
# 或者: from mercantile import tile [as 別名]
def get_tile_data(driver: Driver,
                  keys: Union[Sequence[str], Mapping[str, str]],
                  tile_xyz: Tuple[int, int, int] = None,
                  *, tile_size: Tuple[int, int] = (256, 256),
                  preserve_values: bool = False,
                  asynchronous: bool = False) -> Any:
    """Retrieve raster image from driver for given XYZ tile and keys"""

    if tile_xyz is None:
        # read whole dataset
        return driver.get_raster_tile(
            keys, tile_size=tile_size, preserve_values=preserve_values,
            asynchronous=asynchronous
        )

    # determine bounds for given tile
    metadata = driver.get_metadata(keys)
    wgs_bounds = metadata['bounds']

    tile_x, tile_y, tile_z = tile_xyz

    if not tile_exists(wgs_bounds, tile_x, tile_y, tile_z):
        raise exceptions.TileOutOfBoundsError(
            f'Tile {tile_z}/{tile_x}/{tile_y} is outside image bounds'
        )

    mercator_tile = mercantile.Tile(x=tile_x, y=tile_y, z=tile_z)
    target_bounds = mercantile.xy_bounds(mercator_tile)

    return driver.get_raster_tile(
        keys, tile_bounds=target_bounds, tile_size=tile_size,
        preserve_values=preserve_values, asynchronous=asynchronous
    ) 
開發者ID:DHI-GRAS,項目名稱:terracotta,代碼行數:35,代碼來源:xyz.py


注:本文中的mercantile.tile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。