频数 (分析)
摘要
读取表和一组字段,并创建一个包含唯一字段值和每个唯一字段值的出现次数的新表。
用法
-
输出表将包含频率字段和指定的频数字段及汇总字段。
-
输出表将包含所指定频数字段的每个属性值组合的频数计算。
-
如果指定了汇总字段,则频数计算的唯一属性值将由每个汇总字段的数字属性值进行汇总。
-
使用图层时,仅使用当前所选的要素进行计算。
语法
Frequency_analysis (in_table, out_table, frequency_fields, {summary_fields})
参数 | 说明 | 数据类型 |
in_table |
包含将用于计算频数统计数据的字段的表。该表可以是 INFO 或 OLE DB 表、dBASE 或 VPF 表或者是要素类表。 | Table View; Raster Layer |
out_table |
将存储计算的频数统计数据的表。 | Table |
frequency_fields [frequency_fields,...] |
将用于计算频数统计数据的属性字段。 | Field |
summary_fields [summary_fields,...] (可选) |
进行求和或添加到输出表的属性字段。空值被排除在此计算之外。 | Field |
代码示例
Frequency 示例(Python 窗口)
以下 Python 窗口脚本演示了如何在立即模式下使用 Frequency 函数。
import arcpy from arcpy import env env.workspace = "C:/data/Portland.gdb/Taxlots" arcpy.Frequency_analysis("taxlots", "C:/output/output.gdb/tax_frequency",["YEARBUILT", "COUNTY"], ["LANDVAL", "BLDGVAL", "TOTALVAL"])
Frequency 示例 2(独立脚本)
以下独立脚本演示了如何使用 Frequency 函数。
# Name: Frequency_Example2.py # Description: Run Frequency on a table # Author: ESRI # Import system modules import arcpy from arcpy import env # Set environment settings env.workspace = "C:/data/Portland.gdb/Taxlots" # Set local variables inTable = "taxlots" outTable = "C:/output/output.gdb/tax_frequency" frequencyFields = ["YEARBUILT", "COUNTY"] summaryFields = ["LANDVAL", "BLDGVAL", "TOTALVAL"] # Execute Frequency arcpy.Frequency_analysis(inTable, outTable, frequencyFields, summaryFields)
Frequency 示例 3(独立脚本)
以下独立脚本演示了如何使用多个地理处理脚本函数(包括 Frequency 函数)。
# Name: Frequency_Example3.py # Description: Break all multipart features into singlepart features, # and generate a report of which features were separated. # Author: ESRI # Import system modules import arcpy from arcpy import env # Create variables for the input and output feature classes inFeatureClass = "c:/gdb.mdb/vegetation" outFeatureClass = "c:/gdb.mdb/vegetation_singlepart" # Use error trapping in case a problem occurs when running the tools try: # Add a field to the input (if not already present), this will be used as a unique identifier # Create list of all fields in inFeatureClass fieldList = arcpy.ListFields(inFeatureClass) # Create new empty list to hold field names from inFeatureClass fieldNameList = [] # polulate the field name list with field names from inFeatureClass for field in fieldList: fieldNameList = fieldNameList.append(field.name) # if "tmpUID" is not a field name in inFeatureClass, add it if "tmpUID" not in fieldNameList: arcpy.AddField(inFeatureClass, "tmpUID","double") # Determine what the name of the Object ID is describe = arcpy.Describe(inFeatureClass) OidFieldName = describe.OIDFieldName # Calculate the tmpUID to the OID since this is a Personal GDB, wrap the Field inside [] exp = "[" + OidFieldName + "]" arcpy.CalculateField_management(inFeatureClass, "tmpUID", exp) # Run the tool to create a new fc with only singlepart features arcpy.MultipartToSinglepart_management(inFeatureClass,outFeatureClass) # Check if there is a different number of features in the output than there was in the input if (arcpy.GetCount_management(inFeatureClass) == (arcpy.GetCount_management(outFeatureClass)): print "The number of features in the input is the same as in the output, so no multipart features were found" else: # If there is a difference, print out the FID of the input features which were multipart arcpy.Frequency_analysis(outFeatureClass, outFeatureClass + "_freq", "tmpUID") # Use a search cursor to go through the table, and print the tmpUID print "Below is a list of the FIDs of all the multipart features from " + inFeatureClass rows = arcpy.SearchCursor(outFeatureClass + "_freq", "[FREQUENCY] > 1") row = rows.next() while row: print int(row.tmpUID) row = rows.next() except: # If an error occurred, print out the error message print "Error occurred" print arcpy.GetMessages()
相关主题
许可信息
ArcView: 否
ArcEditor: 否
ArcInfo: 是
7/10/2012