ArcGIS统计矢量内栅格均值(最小值、最大值)邻域统计

本文介绍如何使用ArcGIS软件统计特定矢量区域内栅格数据的各种统计量,包括均值、最大值、最小值等,并展示了如何将统计结果导出为Excel文件。

ArcGIS统计矢量内栅格均值(最小值、最大值)邻域统计

假如我们要统计矢量内各栅格的均值:

image-20220314211441375

图中的矢量是IPCC提供的全球分区。

栅格是我自己计算得到的热浪频率。

使用以下工具:

image-20220325105106716

这两个工具区别:

  • Zonal Statistics生成矢量的栅格化图,含有统计量的属性
  • as Table生成一张Table,便于后期转Excel或进行空间链接

这里选择as Table

image-20220314212019793

各参数:

  • raster or feature是进行邻域统计的底图,可以是栅格或矢量,这里是矢量
  • Zone field指你统计底图的主键
  • value raster是待统计的栅格
  • 当有空值时,勾选这个可以忽略空值的计算,要勾选

统计的类型有以下几种,一般选择ALL,先看看情况。

Statistic type to be calculated.

  • ALL—All of the statistics will be calculated. This is the default.
  • MEAN—Calculates the average of all cells in the value raster that belong to the same zone as the output cell.
  • MAJORITY—Determines the value that occurs most often of all cells in the value raster that belong to the same zone as the output cell.
  • MAXIMUM—Determines the largest value of all cells in the value raster that belong to the same zone as the output cell.
  • MEDIAN—Determines the median value of all cells in the value raster that belong to the same zone as the output cell.
  • MINIMUM—Determines the smallest value of all cells in the value raster that belong to the same zone as the output cell.
  • MINORITY—Determines the value that occurs least often of all cells in the value raster that belong to the same zone as the output cell.
  • RANGE—Calculates the difference between the largest and smallest value of all cells in the value raster that belong to the same zone as the output cell.
  • STD—Calculates the standard deviation of all cells in the value raster that belong to the same zone as the output cell.
  • SUM—Calculates the total value of all cells in the value raster that belong to the same zone as the output cell.
  • VARIETY—Calculates the number of unique values for all cells in the value raster that belong to the same zone as the output cell.
  • MIN_MAX—Both the minimum and maximum statistics are calculated.
  • MEAN_STD—Both the mean and standard deviation statistics are calculated.
  • MIN_MAX_MEAN—The minimum, maximum and mean statistics are calculated.

image-20220314212332879

统计结果右键——Open就可以打开看了

然后再导出Excel

image-20220325105155378

image-20220314212607100

大功告成!

### 使用 arcpy 实现基于矢量分区对栅格数据进行批处理 以下是通过 `arcpy` 编写的 Python 脚本,用于实现基于矢量分区对多个栅格文件的批量统计操作(包括均值最大值最小值和标准差)。此脚本假设用户已经安装并配置好了 ArcGIS 的环境。 #### 示例代码 ```python import os import arcpy # 设置工作空间 workspace = r"C:\path\to\your\raster_folder" vector_zone_feature = r"C:\path\to\your\zone.shp" # 输出路径 output_workspace = r"C:\path\to\your\output_folder" # 检查许可 if not arcpy.CheckExtension("Spatial"): raise Exception("Spatial Analyst extension is not available.") # 启用 Spatial Analyst 许可 arcpy.CheckOutExtension("Spatial") # 获取工作目录下的所有栅格文件 rasters = arcpy.ListRasters("*", "TIF") # 只获取 .tif 文件 for raster in rasters: try: # 定义输入栅格路径 input_raster_path = os.path.join(workspace, raster) # 定义输出表名 output_table_name = f"{os.path.splitext(raster)[0]}_stats.dbf" output_table_path = os.path.join(output_workspace, output_table_name) # 执行 Zonal Statistics as Table 工具 arcpy.sa.Zone(vector_zone_feature, "ZoneField", input_raster_path, output_table_path, "DATA", ["MEAN", "MAXIMUM", "MINIMUM", "STD"]) print(f"成功完成 {raster} 的统计分析.") except Exception as e: print(f"处理 {raster} 时发生错误: {str(e)}") # 解除 Spatial Analyst 许可 arcpy.CheckInExtension("Spatial") ``` --- #### 参数说明 1. **`workspace`**: 存放待处理栅格文件的工作目录。 2. **`vector_zone_feature`**: 矢量区域文件(即分区边界),需包含一个字段作为区号标识[^1]。 3. **`output_workspace`**: 统计结果保存的目标目录。 4. **`Zonal Statistics as Table`**: 这是一个核心工具,能够针对每个矢量区域内的栅格像元执行多种统计运算,支持的操作包括但不限于 MEAN (均值)、MAXIMUM (最大值)、MINIMUM (最小值) 和 STD (标准差)[^1]。 --- #### 注意事项 - 需要确保已启用 Spatial Analyst 扩展模块,否则会抛出许可证不可用异常。 - 输入矢量文件应具有唯一的区号字段(如 `"ZoneField"`),该字段定义了不同的分区。 - 如果存在大量栅格文件,建议优化内存管理以防止资源耗尽。 ---
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

地学万事屋

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值