【发布时间】:2021-02-11 06:33:33
【问题描述】:
我有一个大型的全局 .nc 文件数据集,我正在尝试将它们剪辑到一个较小的区域。我将此区域存储为 .shp 文件。
我曾尝试使用 Qgis 中的 gdal,但需要通过转换每个变量来做到这一点,并且我必须为所有文件一一选择每个变量和相同的形状,并且每个变量有 400 个文件似乎不是最好的主意。这也返回分离的 .tiff 文件,而不是我想要的 .nc 文件。
我有这个小脚本,但它没有做我需要的事情
import glob
import subprocess
import os
ImageList = sorted(glob.glob('*.nc'))
print('number of images to process: ', len(ImageList))
Shapefile = 'NHAF-250m.shp'
# Create output directory
OutDir = './Clipped_Rasters/'
if not os.path.exists(OutDir):
os.makedirs(OutDir)
for Image in ImageList:
print('Processing ' + Image)
OutImage = OutDir + Image.replace('.nc', '_BurnedArea_Clipped.tif') # Defines Output Image
# Clip image
subprocess.call('gdalwarp -q -cutline /Users/path/to/file/NHAF-250-vector/ -tr 0.25 0.25 -of GTiff NETCDF:'+Image+":burned_area "+OutImage, shell=True)
print('Done.' + '\n')
print('All images processed.')
提前谢谢你
【问题讨论】:
标签: python gis gdal netcdf qgis