0
点赞
收藏
分享

微信扫一扫

如何利用 GDAL-Python裁剪栅格数据(DEM等)

Yaphets_巍 2022-02-25 阅读 67

ARCGIS裁剪数据量比较大的栅格很容易卡死,故用gdal。

可批量裁剪多个shp的组合。

翻阅了一些博客,这么一个简单的功能写得很复杂。提供代码供有需要的各位参考。

from osgeo import gdal
 
input_raster = r"F:\JUNK\dem90.tif"
# 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"F:\JUNK\gla-shp.shp" # or any other format
output_raster=r'F:\JUNK\test2.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.

 这是小编裁剪好的DEM高程数据,精度为12.5m。

目前已裁剪为全国分省市县的12.5高程dem。

数据下载链接:数据下载链接   

数据来源地址:地理科学生态网 ,网站地址www.csdn.store

举报

相关推荐

0 条评论