当前位置: 首页>>代码示例>>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;未经允许,请勿转载。