⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 updatepolyid.py

📁 esri公司程序事例,主要功能是实现多次复制,实现工具条按钮!
💻 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))
        
    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -