本文整理汇总了Python中mercantile.xy方法的典型用法代码示例。如果您正苦于以下问题:Python mercantile.xy方法的具体用法?Python mercantile.xy怎么用?Python mercantile.xy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mercantile
的用法示例。
在下文中一共展示了mercantile.xy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_make_tiles_tile_bounds
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def test_make_tiles_tile_bounds(x, y):
'''
Test if children tiles from z10 are created correctly
'''
test_bounds = mercantile.bounds(x, y, 10)
test_bbox = list(mercantile.xy(test_bounds.west, test_bounds.south)) + list(mercantile.xy(test_bounds.east, test_bounds.north))
test_crs = 'epsg:3857'
test_minz = 10
test_maxz = 13
created_tiles_gen = _make_tiles(test_bbox, test_crs, test_minz, test_maxz)
assert isinstance(created_tiles_gen, types.GeneratorType)
created_tiles = list(created_tiles_gen)
assert len(created_tiles) == 85
示例2: union
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def union(inputtiles, parsenames):
tiles = sutils.tile_parser(inputtiles, parsenames)
xmin, xmax, ymin, ymax = sutils.get_range(tiles)
zoom = sutils.get_zoom(tiles)
# make an array of shape (xrange + 3, yrange + 3)
burn = sutils.burnXYZs(tiles, xmin, xmax, ymin, ymax, 0)
nw = mercantile.xy(*mercantile.ul(xmin, ymin, zoom))
se = mercantile.xy(*mercantile.ul(xmax + 1, ymax + 1, zoom))
aff = Affine(((se[0] - nw[0]) / float(xmax - xmin + 1)), 0.0, nw[0],
0.0, -((nw[1] - se[1]) / float(ymax - ymin + 1)), nw[1])
unprojecter = sutils.Unprojecter()
unionedTiles = [
{
'geometry': unprojecter.unproject(feature),
'properties': {},
'type': 'Feature'
} for feature, shapes in features.shapes(np.asarray(np.flipud(np.rot90(burn)).astype(np.uint8), order='C'), transform=aff) if shapes == 1
]
return unionedTiles
示例3: project_geom
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def project_geom(geom):
return {
'type': geom['type'],
'coordinates': [
[mercantile.xy(*coords) for coords in part]
for part in geom['coordinates']
]
}
示例4: make_transform
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def make_transform(tilerange, zoom):
ulx, uly = mercantile.xy(*mercantile.ul(tilerange['x']['min'], tilerange['y']['min'], zoom))
lrx, lry = mercantile.xy(*mercantile.ul(tilerange['x']['max'], tilerange['y']['max'], zoom))
xcell = (lrx - ulx) / float(tilerange['x']['max'] - tilerange['x']['min'])
ycell = (uly - lry) / float(tilerange['y']['max'] - tilerange['y']['min'])
return Affine(xcell, 0, ulx,
0, -ycell, uly)
示例5: make_src_meta
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def make_src_meta(bounds, size, creation_opts={}):
"""
Create metadata for output tiles
"""
ul = merc.xy(bounds.west, bounds.north)
lr = merc.xy(bounds.east, bounds.south)
aff = make_affine(size, size, ul, lr)
## default values
src_meta = {
'driver': 'GTiff',
'height': size,
'width': size,
'count': 4,
'dtype': np.uint8,
'affine': aff,
"crs": 'EPSG:3857',
'compress': 'JPEG',
'tiled': True,
'blockxsize': 256,
'blockysize': 256
}
for c in creation_opts.keys():
src_meta[c] = creation_opts[c]
return src_meta
示例6: _tile_worker
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def _tile_worker(tile):
"""
For each tile, and given an open rasterio src, plus a`global_args` dictionary
with attributes of `base_val`, `interval`, and a `writer_func`,
warp a continous single band raster to a 512 x 512 mercator tile,
then encode this tile into RGB.
Parameters
-----------
tile: list
[x, y, z] indices of tile
Returns
--------
tile, buffer
tuple with the input tile, and a bytearray with the data encoded into
the format created in the `writer_func`
"""
x, y, z = tile
bounds = [
c
for i in (
mercantile.xy(*mercantile.ul(x, y + 1, z)),
mercantile.xy(*mercantile.ul(x + 1, y, z)),
)
for c in i
]
toaffine = transform.from_bounds(*bounds + [512, 512])
out = np.empty((512, 512), dtype=src.meta["dtype"])
reproject(
rasterio.band(src, 1),
out,
dst_transform=toaffine,
dst_crs="epsg:3857",
resampling=Resampling.bilinear,
)
out = data_to_rgb(out, global_args["base_val"], global_args["interval"])
return tile, global_args["writer_func"](out, global_args["kwargs"].copy(), toaffine)
示例7: process_tile
# 需要导入模块: import mercantile [as 别名]
# 或者: from mercantile import xy [as 别名]
def process_tile(tile):
"""Process a single MBTiles tile
Parameters
----------
tile : mercantile.Tile
Returns
-------
tile : mercantile.Tile
The input tile.
bytes : bytearray
Image bytes corresponding to the tile.
"""
global base_kwds, resampling, src
# Get the bounds of the tile.
ulx, uly = mercantile.xy(
*mercantile.ul(tile.x, tile.y, tile.z))
lrx, lry = mercantile.xy(
*mercantile.ul(tile.x + 1, tile.y + 1, tile.z))
kwds = base_kwds.copy()
kwds['transform'] = transform_from_bounds(ulx, lry, lrx, uly,
kwds['width'], kwds['height'])
src_nodata = kwds.pop('src_nodata', None)
dst_nodata = kwds.pop('dst_nodata', None)
warnings.simplefilter('ignore')
with MemoryFile() as memfile:
with memfile.open(**kwds) as tmp:
# determine window of source raster corresponding to the tile
# image, with small buffer at edges
try:
west, south, east, north = transform_bounds(TILES_CRS, src.crs, ulx, lry, lrx, uly)
tile_window = window_from_bounds(west, south, east, north, transform=src.transform)
adjusted_tile_window = Window(
tile_window.col_off - 1, tile_window.row_off - 1,
tile_window.width + 2, tile_window.height + 2)
tile_window = adjusted_tile_window.round_offsets().round_shape()
# if no data in window, skip processing the tile
if not src.read_masks(1, window=tile_window).any():
return tile, None
except ValueError:
log.info("Tile %r will not be skipped, even if empty. This is harmless.", tile)
reproject(rasterio.band(src, tmp.indexes),
rasterio.band(tmp, tmp.indexes),
src_nodata=src_nodata,
dst_nodata=dst_nodata,
num_threads=1,
resampling=resampling)
return tile, memfile.read()