使用GDAL中的Warp函数实现了ArcGIS中的按掩膜提取功能,直接上代码:
from osgeo import gdal
input_raster = r"" # 输入栅格路径
# or as an alternative if the input is already a gdal raster object you can use that gdal object
input_raster = gdal.Open(input_raster)
input_shape = r"" # 输入的掩膜路径(可以是.shp文件或者.tif文件)
output_raster = r'' # 输出栅格路径
ds = gdal.Warp(output_raster,
input_raster,
format='GTiff',
cutlineDSName=input_shape, # or any other file format
cutlineWhere="FIELD = 'whatever'",
# optionally you can filter your cutline (shapefile) based on attribute values
dstNodata=-9999) # select the no data value you like
ds = None # do other stuff with ds object, it is your cropped dataset. in this case we only close the dataset.
标签:raster,提取,掩膜,Python,object,input,gdal From: https://www.cnblogs.com/tangjielin/p/16597366.html