在Python中将雷达图像与shapefile重叠和裁剪可以通过以下步骤实现:
import geopandas as gpd
import rasterio
from rasterio.mask import mask
from shapely.geometry import mapping
shapefile = 'path/to/shapefile.shp'
gdf = gpd.read_file(shapefile)
image_file = 'path/to/radar_image.tif'
raster = rasterio.open(image_file)
geoms = gdf.geometry.values
geometry = mapping(geoms[0])
out_image, out_transform = mask(raster, [geometry], crop=True)
out_meta = raster.meta.copy()
out_meta.update({"driver": "GTiff",
"height": out_image.shape[1],
"width": out_image.shape[2],
"transform": out_transform})
output_file = 'path/to/output_image.tif'
with rasterio.open(output_file, "w", **out_meta) as dest:
dest.write(out_image)
这样,你就可以在Python中将雷达图像与shapefile重叠和裁剪了。请注意,以上代码仅为示例,实际使用时需要根据具体情况进行调整。
领取专属 10元无门槛券
手把手带您无忧上云