?? updatepolyid.py
字號:
#--------------------------------------------------------------------------
# Tool Name: UpdatePolyID
# Source Name: UpdatePolyID.py
# Version: ArcGIS 9.0
# Author: ESRI
# Usage: UpdatePolyID <input_fc> <field_name>
#
# Purpose: Assigns a unique value to and input field for groups of polygon features that
# have duplicate geometries. This script is useful when working with the results of
# polygon overlays with non-planar inputs.
#--------------------------------------------------------------------------
import sys
# Create the Geoprocessor object
from win32com.client import Dispatch
gp = Dispatch("esriGeoprocessing.GPDispatch.1")
#--------------------------------------------------------------------------
def AssignPolyID(fc, polyid_field):
##
## # Create the new field
## field_type = "long"
## gp.addfield(fc, polyid_field, field_type)
##
##
fcInfo = gp.describe(fc)
shape_field = fcInfo.ShapeFieldName
# Using an UpdateCursor, get the centroid of each polygon and add a unique value to a
# dictionary if a key generated by the centroid XY value does not already exist.
# For all features with the same centroid, update the poly_ID field with the same value.
rows = gp.UpdateCursor(fc)
row = rows.Next()
polyid_list = {}
next_id = 0;
while row:
geometry = row.GetValue(shape_field)
sKey = `geometry.Centroid`
try:
poly_id = polyid_list[sKey]
except:
next_id = next_id + 1
poly_id = next_id
polyid_list[sKey] = poly_id
row.SetValue(polyid_field, poly_id)
rows.UpdateRow(row)
row = rows.Next()
del(rows)
#--------------------------------------------------------------------------
#MAIN
if __name__ == "__main__":
try:
input_fc = sys.argv[1]
if not input_fc:
gp.AddError("An input feature class is required.")
else:
polyid_field = sys.argv[2]
if not polyid_field:
gp.AddError("An input integer field name is required.")
else:
AssignPolyID(input_fc, polyid_field)
except:
gp.AddError(gp.GetMessages(2))
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -