使用python与采样工具,批量对栅格进行采样,并将采样结果转excel后进行精度分析

研究有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")

得到的结果的格式为这种结构,我们实际需要的仅仅是最后两列,在我的实验中,最后两列是站点降水量与栅格数据的降水量。我们使用最后两列数据进行。
在这里插入图片描述
后续还需进行精度分析

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值