本文将介绍通过 ArcGIS Pro 的 Python 模块(arcpy)对栅格数据定义投影及裁剪的方法。

1 数据来源及介绍

降水量数据:国家青藏高原科学数据中心的 中国1km分辨率逐月降水量数据集

行政区数据:天地图行政区划数据中的吉林省边界面数据,该数据为 GeoJSON 格式,可通过 QGIS 等软件将其转换为 shapefile 格式文件。

中国1km分辨率逐月降水量数据集为 NetCDF 格式,通过《NetCDF 文件批量转栅格并导出栅格各波段》文中的方法转换后的 tif 格式数据没有确定坐标系,而数据官网中对于坐标系统建议使用 WGS84,故本文通过 arcpy 的 DefineProjection 函数批量定义栅格投影后,通过 ExtractByMask 函数根据吉林省边界面数据裁剪得到吉林省范围的降水量数据。

2 示例代码

2.1 定义栅格投影

import os
import arcpy

# "TIF":栅格数据文件夹相对路径
for fileName in os.listdir("TIF"):
    # 遍历文件夹中所有后缀名为 .tif 的文件
    if fileName[-4:] == ".tif":
        # 读取栅格数据文件路径
        raster = os.path.join("TIF", fileName)
        # 定义栅格投影为 WGS 1984
        sr = arcpy.SpatialReference("WGS 1984")
        arcpy.DefineProjection_management(raster, sr)
        print(f"{fileName[:-4]} conversion successful!")

将定义投影后的数据导入 ArcGIS,其空间参考信息如下:

image

2.2 按掩膜提取

import os
import arcpy
from arcpy import sa

# 如果在代码同级文件夹中没有结果数据库,则创建该数据库
if "Pre_Jilin.gdb" not in os.listdir("."):
    print("即将为您创建用于保存结果栅格的文件地理数据库(Pre_Jilin.gdb)……")
    arcpy.CreateFileGDB_management(".", "Pre_Jilin")
    print("数据库创建完成!")

for fileName in os.listdir("TIF"):
    if fileName[-4:] == ".tif":
        # 读取输入栅格及掩膜数据的文件路径,可根据实际情况调整
        inRaster = os.path.join("TIF", fileName)
        inMaskData = "Data/Jilin.shp"
        # 执行按掩膜提取,并将提取结果保存至数据库
        # 结果文件名称与不包含后缀部分的原始文件名称相同
        sa.ExtractByMask(inRaster, inMaskData).save(f"Pre_Jilin.gdb/{fileName[:-4]}")
        print(f"{fileName[:-4]} conversion successful!")

按掩膜提取结果栅格如下所示:

image

3 降水数据参考文献格式

3.1 数据的引用

彭守璋. (2020). 中国1km分辨率逐月降水量数据集(1901-2023). 国家青藏高原数据中心. https://doi.org/10.5281/zenodo.3114194.

Peng, S. (2020). 1-km monthly precipitation dataset for China (1901-2023). National Tibetan Plateau / Third Pole Environment Data Center. https://doi.org/10.5281/zenodo.3114194.

3.2 文章的引用

1、Peng, S.Z., Ding, Y.X., Wen, Z.M., Chen, Y.M., Cao, Y., & Ren, J.Y. (2017). Spatiotemporal change and trend analysis of potential evapotranspiration over the Loess Plateau of China during 2011-2100. Agricultural and Forest Meteorology, 233, 183-194. https://doi.org/10.1016/j.agrformet.2016.11.129

2、Ding, Y.X., & Peng, S.Z. (2020). Spatiotemporal trends and attribution of drought across China from 1901–2100. Sustainability, 12(2), 477.

3、Peng, S.Z., Ding, Y.X., Liu, W.Z., & Li, Z. (2019). 1 km monthly temperature and precipitation dataset for China from 1901 to 2017. Earth System Science Data, 11, 1931–1946. https://doi.org/10.5194/essd-11-1931-2019

4、Peng, S., Gang, C., Cao, Y., & Chen, Y. (2017). Assessment of climate change trends over the loess plateau in china from 1901 to 2100. International Journal of Climatology.