頻度(Frequency) (解析)
サマリ
テーブルと一連のフィールドを読み取り、一意のフィールド値と一意のフィールド値ごとの発生数を含む新しいテーブルを作成します。
使用法
-
出力テーブルには、フィールド [頻度] と、指定した頻度フィールドおよびサマリ フィールドが含まれます。
-
出力テーブルには、指定した頻度フィールドの各属性値の組み合わせについての頻度の計算結果が含まれます。
-
サマリ フィールドが指定されている場合、頻度の計算結果の一意の属性値は、各サマリ フィールドの数値属性によって集計されます。
-
レイヤを使用する場合、計算には現在選択されているフィーチャだけが使用されます。
構文
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,...] (オプション) |
集計して出力テーブルに追加するための属性フィールド。NULL 値はこの計算から除外されます。 | Field |
コードのサンプル
頻度の例(Python ウィンドウ)
次の Python ウィンドウ スクリプトは、イミディエイト モードで頻度関数を使用する方法を示しています。
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"])
頻度の例 2(スタンドアロン スクリプト)
次のスタンドアロン スクリプトは、頻度関数を使用する方法を示しています。
# 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)
頻度の例 3(スタンドアロン スクリプト)
次のスタンドアロン スクリプトは、頻度関数を含む、数多くのジオプロセシング スクリプト関数を使用する方法を示しています。
# 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