我有一个文件夹,其中包含具有不同扩展名的文件(例如.TIF,.IMD,.txt),我想检索两个具有相同扩展名的文件(例如B2.TIF和B5.TIF)
from rasterio import Affine as A
from rasterio.warp import reproject, Resampling
#from matplotlib.collections import PatchCollection
fig, ax = plt.subplots(1, 1, figsize=(10, 10), subplot_kw=
{'projection': ccrs.UTM(42)})
ax.set_extent([min(xmin), max(xmax), min(ymin), max(ymax)], ccrs.UTM(42))
bounds.plot(ax=ax, transform=ccrs.PlateCarree())
for image_path in glob(os.path.join(LANDSAT_PATH, '*/*B5.TIF')):
with rasterio.open(image_path) as src:
src_transform = src.transform
# Zoom out by a factor of 2 from the center of the source
# dataset. The destination transform is the product of the
# source transform, a translation down and to the right, and
# a scaling.
dst_transform = src_transform*A.translation(
-src.width/2.0, -src.height/2.0)*A.scale(2.0)
data = src.read()
kwargs = src.meta
kwargs['transform'] = dst_transform
with rasterio.open('zoomed-out.tif', 'w', **kwargs) as dst:
for i, band in enumerate(data, 1):
dest = np.zeros_like(band)
reproject(
band,
dest,
src_transform=src_transform,
src_crs=src.crs,
dst_transform=dst_transform,
dst_crs=src.crs,
resampling=Resampling.nearest)
以下命令仅返回B5.TIF,但我同时需要B2.TIF和B5.TIF,然后分别应用投影
for image_path in glob(os.path.join(LANDSAT_PATH, '*/*B5.TIF')):