本文整理汇总了Python中rasterio.vrt方法的典型用法代码示例。如果您正苦于以下问题:Python rasterio.vrt方法的具体用法?Python rasterio.vrt怎么用?Python rasterio.vrt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rasterio
的用法示例。
在下文中一共展示了rasterio.vrt方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cog_translate_warpedvrt
# 需要导入模块: import rasterio [as 别名]
# 或者: from rasterio import vrt [as 别名]
def test_cog_translate_warpedvrt(runner):
"""Should work as expected (create cogeo from an open memfile)."""
with runner.isolated_filesystem():
with rasterio.open(raster_path_rgb) as dataset:
with WarpedVRT(dataset) as vrt:
cog_translate(vrt, "cogeo.tif", jpeg_profile, quiet=True)
with rasterio.open("cogeo.tif") as src:
_validate_translated_rgb_jpeg(src)
示例2: _get_vrt
# 需要导入模块: import rasterio [as 别名]
# 或者: from rasterio import vrt [as 别名]
def _get_vrt(src: DatasetReader, rs_method: int) -> WarpedVRT:
from terracotta.drivers.raster_base import RasterDriver
target_crs = RasterDriver._TARGET_CRS
vrt_transform, vrt_width, vrt_height = calculate_default_transform(
src.crs, target_crs, src.width, src.height, *src.bounds
)
vrt = WarpedVRT(
src, crs=target_crs, resampling=rs_method, transform=vrt_transform,
width=vrt_width, height=vrt_height
)
return vrt
示例3: _rasterio_read
# 需要导入模块: import rasterio [as 别名]
# 或者: from rasterio import vrt [as 别名]
def _rasterio_read(
input_file=None,
indexes=None,
dst_bounds=None,
dst_shape=None,
dst_crs=None,
resampling=None,
src_nodata=None,
dst_nodata=None,
):
def _read(
src, indexes, dst_bounds, dst_shape, dst_crs, resampling, src_nodata, dst_nodata
):
height, width = dst_shape[-2:]
if indexes is None:
dst_shape = (len(src.indexes), height, width)
indexes = list(src.indexes)
src_nodata = src.nodata if src_nodata is None else src_nodata
dst_nodata = src.nodata if dst_nodata is None else dst_nodata
dst_left, dst_bottom, dst_right, dst_top = dst_bounds
with WarpedVRT(
src,
crs=dst_crs,
src_nodata=src_nodata,
nodata=dst_nodata,
width=width,
height=height,
transform=affine_from_bounds(
dst_left, dst_bottom, dst_right, dst_top, width, height
),
resampling=Resampling[resampling]
) as vrt:
return vrt.read(
window=vrt.window(*dst_bounds),
out_shape=dst_shape,
indexes=indexes,
masked=True
)
if isinstance(input_file, str):
logger.debug("got file path %s", input_file)
try:
with rasterio.open(input_file, "r") as src:
return _read(
src, indexes, dst_bounds, dst_shape, dst_crs, resampling, src_nodata,
dst_nodata
)
except RasterioIOError as e:
try:
if path_exists(input_file):
raise e
except:
raise e
raise FileNotFoundError("%s not found" % input_file)
else:
logger.debug("assuming file object %s", input_file)
return _read(
input_file, indexes, dst_bounds, dst_shape, dst_crs, resampling,
src_nodata, dst_nodata
)