arcgis 属性表 汇总_汇总统计数据 (分析)

本文通过Python脚本展示了如何使用ArcGIS进行属性表的统计分析,包括使用Statistics_analysis工具进行汇总,如求和统计,并给出了多个示例,涉及缓冲区、裁剪、JoinField及Summary Statistics等操作。

代码示例统计数据示例(Python 窗口)

以下 Python 窗口脚本演示了如何在即时模式下使用 Statistics 工具。

import arcpy

arcpy.env.workspace = "C:/data/Habitat_Analysis.gdb"

arcpy.Statistics_analysis("futrds", "C:/output/output.gdb/stats", [["Shape_Length", "SUM"]], "NM")统计数据示例 2(独立脚本)

以下独立脚本汇总了主要道路 150 英尺范围内的植被区域。

# Description: Summarize the vegetation by area within 150 feet of major roads

# Import system modules

import arcpy

# Set environment settings

arcpy.env.workspace = "C:/data"

# Set local variables

inRoads = "majorrds.shp"

outBuffer = "C:/output/output.gdb/buffer_out"

bufferDistance = "250 feet"

inVegetation = "Habitat_Analysis.gdb/vegtype"

outClip = "C:/output/output.gdb/clip_out"

joinField = "HOLLAND95"

joinTable = "c:/data/vegtable.dbf"

joinedField = "HABITAT"

outStatsTable = "C:/output/output.gdb/stats_out"

statsFields = [["Shape_Area", "SUM"]]

# Execute Buffer to get a buffer of major roads

arcpy.Buffer_analysis(inRoads, outBuffer, bufferDistance, dissolve_option="ALL")

# Execute Clip using the buffer output to get a clipped feature class

# of vegetation

arcpy.Clip_analysis(inVegetation, outBuffer, outClip)

# Execute JoinField to add the vegetation type

arcpy.JoinField_management(outClip, joinField, joinTable, joinField, joinedField)

# Execute Statistics to get the area of each vegetation type within

# the clipped buffer.

arcpy.Statistics_analysis(outClip, outStatsTable, statsFields, joinedField)统计数据示例 3(独立脚本)

以下独立脚本循环遍历数据集的属性字段并构造 statistics_fields 参数,从而计算各个数值字段的 SUM 统计量。

# Description: Script that runs the Summary Statistic tool to calculate the

# Sum statistic for every numeric field based on a unique case field

# Import system modules

import arcpy

# Set environment settings

arcpy.env.workspace = "C:/data/f.gdb"

# Set local variables

intable = "intable"

outtable = "sumstats"

casefield = "Name"

stats = []

# Loop through all fields in the Input Table

for field in arcpy.ListFields(intable):

# Just find the fields that have a numeric type

if field.type in ("Double", "Integer", "Single", "SmallInteger"):

# Add the field name and Sum statistic type

# to the list of fields to summarize

stats.append([field.name, "Sum"])

# Correct formatting of stats [["Field1", "Sum"], ["Field2", "Sum"], ...]

# Run the Summary Statistics tool with the stats list

arcpy.Statistics_analysis(intable, outtable, stats, casefield)Statistics 示例 4(独立脚本)

以下脚本使用 pandas DataFrame 来访问和显示 Statistics 工具的表格结果。

import arcpy

import pandas

import os

arcpy.env.overwriteOutput = True

in_table = r"d:\data\states.shp"

out_table = r"in_memory\stats_table"

stat_fields = [['POP1990', 'SUM'], ['POP1997', 'SUM']]

stats = arcpy.Statistics_analysis(in_table, out_table, stat_fields,

case_field='SUB_REGION')

# Get a list of field names to display

field_names = [i.name for i in arcpy.ListFields(out_table) if i.type != 'OID']

# Open a cursor to extract results from stats table

cursor = arcpy.da.SearchCursor(out_table, field_names)

# Create a pandas dataframe to display results

df = pandas.DataFrame(data=[row for row in cursor],

columns=field_names)

print(df)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值