本文整理汇总了Python中mercantile.Tile方法的典型用法代码示例。如果您正苦于以下问题:Python mercantile.Tile方法的具体用法?Python mercantile.Tile怎么用?Python mercantile.Tile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mercantile
的用法示例。
在下文中一共展示了mercantile.Tile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: tiles_from_csv
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def tiles_from_csv(path):
"""Read tiles from a line-delimited csv file.
Args:
file: the path to read the csv file from.
Yields:
The mercantile tiles from the csv file.
"""
with open(path) as fp:
reader = csv.reader(fp)
for row in reader:
if not row:
continue
yield mercantile.Tile(*map(int, row))
示例2: adjacent_tile
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def adjacent_tile(tile, dx, dy, tiles):
"""Retrieves an adjacent tile from a tile store.
Args:
tile: the original tile to get an adjacent tile for.
dx: the offset in tile x direction.
dy: the offset in tile y direction.
tiles: the tile store to get tiles from; must support `__getitem__` with tiles.
Returns:
The adjacent tile's image or `None` if it does not exist.
"""
x, y, z = map(int, [tile.x, tile.y, tile.z])
other = mercantile.Tile(x=x + dx, y=y + dy, z=z)
try:
path = tiles[other]
return Image.open(path).convert("RGB")
except KeyError:
return None
示例3: tile
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def tile(z, x, y):
# Todo: predictor should take care of zoom levels
if z != 18:
abort(404)
tile = mercantile.Tile(x, y, z)
url = tiles.format(x=tile.x, y=tile.y, z=tile.z)
res = fetch_image(session, url)
if not res:
abort(500)
image = Image.open(res)
mask = predictor.segment(image)
return send_png(mask)
示例4: test_tile_read_extmask
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def test_tile_read_extmask():
"""Read masked area."""
# non-boundless tile covering the masked part
mercator_tile = mercantile.Tile(x=876431, y=1603669, z=22)
bounds = mercantile.xy_bounds(mercator_tile)
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="TRUE"):
with rasterio.open(S3_EXTMASK_PATH) as src_dst:
arr, mask = reader.part(src_dst, bounds, 256, 256)
assert arr.shape == (3, 256, 256)
assert mask.shape == (256, 256)
assert not mask.all()
# boundless tile covering the masked part
mercator_tile = mercantile.Tile(x=876431, y=1603668, z=22)
bounds = mercantile.xy_bounds(mercator_tile)
with rasterio.Env(GDAL_DISABLE_READDIR_ON_OPEN="EMPTY_DIR"):
with rasterio.open(S3_MASK_PATH) as src_dst:
arr, mask = reader.part(src_dst, bounds, 256, 256)
assert arr.shape == (3, 256, 256)
assert not mask.all()
示例5: __init__
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def __init__(self, url, zoom=18, bounds=None):
self.zoom_level = zoom
self._name = "image-{}".format(str(uuid.uuid4()))
self._url = url
_first_tile = mercantile.Tile(z=self.zoom_level, x=0, y=0)
_last_tile = mercantile.Tile(z=self.zoom_level, x=180, y=-85.05)
g = box(*mercantile.xy_bounds(_first_tile)).union(box(*mercantile.xy_bounds(_last_tile)))
self._full_bounds = g.bounds
# TODO: populate rest of fields automatically
self._tile_size = 256
self._nbands = 3
self._dtype = "uint8"
self.bounds = self._expand_bounds(bounds)
示例6: get_assets_from_json
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def get_assets_from_json(
tiles: Dict, quadkey_zoom: int, x: int, y: int, z: int
) -> List[str]:
"""Find assets."""
mercator_tile = mercantile.Tile(x=x, y=y, z=z)
quadkeys = find_quadkeys(mercator_tile, quadkey_zoom)
assets = list(itertools.chain.from_iterable([tiles.get(qk, []) for qk in quadkeys]))
# check if we have a mosaic in the url (.json/.gz)
return list(
itertools.chain.from_iterable(
[
get_assets_from_json(tiles, quadkey_zoom, x, y, z)
if os.path.splitext(asset)[1] in [".json", ".gz"]
else [asset]
for asset in assets
]
)
)
示例7: tiles_from_slippy_map
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def tiles_from_slippy_map(root):
"""Loads files from an on-disk slippy map directory structure.
Args:
root: the base directory with layout `z/x/y.*`.
Yields:
The mercantile tiles and file paths from the slippy map directory.
"""
# The Python string functions (.isdigit, .isdecimal, etc.) handle
# unicode codepoints; we only care about digits convertible to int
def isdigit(v):
try:
_ = int(v) # noqa: F841
return True
except ValueError:
return False
for z in os.listdir(root):
if not isdigit(z):
continue
for x in os.listdir(os.path.join(root, z)):
if not isdigit(x):
continue
for name in os.listdir(os.path.join(root, z, x)):
y = os.path.splitext(name)[0]
if not isdigit(y):
continue
tile = mercantile.Tile(x=int(x), y=int(y), z=int(z))
path = os.path.join(root, z, x, name)
yield tile, path
示例8: test_getitem
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def test_getitem(self):
inputs = ["tests/fixtures/images/"]
target = "tests/fixtures/labels/"
transform = JointCompose([JointTransform(ImageToTensor(), MaskToTensor())])
dataset = SlippyMapTilesConcatenation(inputs, target, transform)
images, mask, tiles = dataset[0]
self.assertEqual(tiles[0], mercantile.Tile(69105, 105093, 18))
self.assertEqual(type(images), torch.Tensor)
self.assertEqual(type(mask), torch.Tensor)
示例9: test_slippy_map_directory
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
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")
示例10: test_read_tiles
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def test_read_tiles(self):
filename = "tests/fixtures/tiles.csv"
tiles = [tile for tile in tiles_from_csv(filename)]
self.assertEqual(len(tiles), 3)
self.assertEqual(tiles[0], mercantile.Tile(69623, 104945, 18))
示例11: test_burn_with_feature
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def test_burn_with_feature(self):
parking_fc = get_parking()
# The tile below has a parking lot in our fixtures.
tile = mercantile.Tile(70762, 104119, 18)
rasterized = burn(tile, parking_fc["features"], 512)
rasterized = Image.fromarray(rasterized, mode="P")
# rasterized.save('rasterized.png')
self.assertEqual(rasterized.size, (512, 512))
# Tile has a parking feature in our fixtures, thus sum should be non-zero.
self.assertNotEqual(np.sum(rasterized), 0)
示例12: test_burn_without_feature
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def test_burn_without_feature(self):
parking_fc = get_parking()
# This tile does not have a parking lot in our fixtures.
tile = mercantile.Tile(69623, 104946, 18)
rasterized = burn(tile, parking_fc["features"], 512)
rasterized = Image.fromarray(rasterized, mode="P")
self.assertEqual(rasterized.size, (512, 512))
# Tile does not have a parking feature in our fixture, the sum of pixels is zero.
self.assertEqual(np.sum(rasterized), 0)
示例13: _expand_bounds
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def _expand_bounds(self, bounds):
if bounds is None:
return bounds
min_tile_x, min_tile_y, max_tile_x, max_tile_y = self._tile_coords(bounds)
ul = box(*mercantile.xy_bounds(mercantile.Tile(z=self.zoom_level, x=min_tile_x, y=max_tile_y)))
lr = box(*mercantile.xy_bounds(mercantile.Tile(z=self.zoom_level, x=max_tile_x, y=min_tile_y)))
return ul.union(lr).bounds
示例14: 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
)
示例15: read_tile
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import Tile [as 别名]
def read_tile(self, z, x, y):
"""Read raster tile data and mask."""
mercator_tile = mercantile.Tile(x=x, y=y, z=z)
tile_bounds = mercantile.xy_bounds(mercator_tile)
data, mask = tile_read(
self.path,
tile_bounds,
self.tiles_size,
indexes=self.indexes,
nodata=self.nodata,
)
data = (data[0] + data[1]) / 2
return data.astype(numpy.uint8), mask