def clip_raster_by_shp(dem_fn, shp_fn):
import subprocess
#This is ok when writing to outdir, but clip_raster_by_shp.sh writes to raster dir
#try:
# with open(dem_fn) as f: pass
#except IOError as e:
cmd = ['clip_raster_by_shp.sh', dem_fn, shp_fn]
print(cmd)
subprocess.call(cmd, shell=False)
dem_clip_fn = os.path.splitext(dem_fn)[0]+'_shpclip.tif'
dem_clip_ds = gdal.Open(dem_clip_fn, gdal.GA_ReadOnly)
return dem_clip_ds
#Hack
#extent is xmin ymin xmax ymax
评论列表
文章目录