之前说过GDAL能进行遥感影像裁剪,很简单就是看裁剪完之后的得到的对象是否为空
这就是Warp函数返回的对象,若为None就表示没有裁剪到,那肯定不在矢量范围内(这里不考虑裁剪失败的其他错误)
porj, geo,data = read_tiff(workspace2)
input_raster = gdal.Open(workspace2)
output_raster = workspace2.replace('.tif', '.cut.tif')
ds = gdal.Warp(output_raster,
input_raster,
format='GTiff',
cropToCutline=True, # True,
cutlineDSName=workspace1, # or any other file format
# cutlineWhere="FID_1 = 'whatever'",#根据shp属性表字段类型进行裁切
# optionally you can filter your cutline (shapefile) based on attribute values
dstNodata=-9999)
print(ds)
# data,datatype,geo,porj = read_tif(r"workspace2")
# print(data.shape)
if ds != None:
xxxx执行流程
else:
print(f"该影像和研究区不存在交集,请检查影像")