频数 (Analysis)

许可等级:BasicStandardAdvanced

摘要

读取表和一组字段,并创建一个包含唯一字段值以及各唯一字段值所出现次数的新表。

用法

语法

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
arcpy.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
 
# Import system modules
import arcpy
 
# Set environment settings
arcpy.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.
 
# Import system modules
import arcpy
 
# Create variables for the input and output feature classes
inFeatureClass = "c:/data/gdb.gdb/vegetation"
outFeatureClass = "c:/data/gdb.gdb/vegetation_singlepart"

try:
    # Create list of all fields in inFeatureClass
    fieldNameList = [field.name for field in arcpy.ListFields(inFeatureClass)]

    # Add a field to the input this will be used as a unique identifier
    arcpy.AddField_management(inFeatureClass, "tmpUID", "double")
 
    # Determine what the name of the Object ID is 
    OIDFieldName = arcpy.Describe(inFeatureClass).OIDFieldName
   
    # Calculate the tmpUID to the OID
    arcpy.CalculateField_management(inFeatureClass, "tmpUID",
                                    "[" + OIDFieldName + "]")
 
    # 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
    inCount = int(arcpy.GetCount_management(inFeatureClass).getOutput(0))
    outCount = int(arcpy.GetCount_management(outFeatureClass).getOutput(0))
    
    if inCount != outCount:
        # 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("Multipart features from {0}".format(inFeatureClass))
        for row in arcpy.da.SearchCursor(outFeatureClass + "_freq",
                                         ["tmpUID"], "FREQUENCY > 1"):
            print int(row[0])
    else:
        print("No multipart features were found")

except arcpy.ExecuteError:
    print(arcpy.GetMessages())
except Exception as e:
    print(e)

环境

相关主题

许可信息

ArcGIS for Desktop Basic: 否
ArcGIS for Desktop Standard: 否
ArcGIS for Desktop Advanced: 是
5/10/2014