所以我正在使用Arcgis中的Arcpy工具箱将DEM光栅文件转换为特定的处理。但是我需要剪切这些图像,因为原始图像太大而且太长而无法处理。…
您可以使用gdal.Warp()和shapefile作为切割线以更简单的方式实现这一点
from osgeo import gdal input_raster = "path/to/yourDEM.tif" # or as an alternative if the input is already a gdal raster object you can use that gdal object input_raster=gdal.Open("path/to/yourDEM.tif") input_shape = "path/to/yourShapefile.shp" # or any other format output_raster="path/to/outputDEM.tif" #your output raster file 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.