研究有1990-2020的栅格格式的月降水数据,来源于国外的网站,同时又1990-2020的站点月降水数据,使用站点月降水数据与栅格月降水数据进行精度分析。
参考arcgis pro 空间分析— 提取分析工具箱——sample函数官方指导文件:
https://pro.arcgis.com/zh-cn/pro-app/2.8/tool-reference/spatial-analyst/sample.htm
或使用提取值至点函数:
https://pro.arcgis.com/zh-cn/pro-app/2.8/tool-reference/spatial-analyst/extract-values-to-points.htm
ListFeatureClasses
https://pro.arcgis.com/es/pro-app/2.8/arcpy/functions/listfeatureclasses.htm
ListRasters
https://pro.arcgis.com/es/pro-app/latest/arcpy/functions/listrasters.htm
我这里使用了提取值到点函数:
这种双层for循环的方法比较慢,不知道有没有大佬能够指点指点
# -*- coding: utf-8 -*-
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True # 允许覆盖之前产生的数据集,便于测试
#设置工作空间
arcpy.env.workspace = r"D:\DELL\E\R_FACTOR_zong\sample_mouth"
ex_out = r"D:\DELL\E\R_FACTOR_zong\sample_mouth_out"# 提取值到点的输出路径
excel_out = r"D:\DELL\E\R_FACTOR_zong\sample_mouth_excel"# shp转excel输出路径
for tif_file in arcpy.ListRasters("*.tif"):
tifname=tif_file[:-4]
print(tifname)
for shp_file in arcpy.ListFeatureClasses("*.shp"):
shpname=shp_file[:-4]
if tifname==shpname:
print(shpname)
ExtractValuesToPoints(shp_file, tif_file,
ex_out+"/"+shpname+".shp")
arcpy.conversion.TableToExcel(ex_out+"/"+shpname+".shp", excel_out+"/"+shpname+".xlsx")
得到的结果的格式为这种结构,我们实际需要的仅仅是最后两列,在我的实验中,最后两列是站点降水量与栅格数据的降水量。我们使用最后两列数据进行。
后续还需进行精度分析