arcpy批量化操作

1. 创建Feature Class。

//新建Feature类
Create_Feature_Class()

2. Add Field。

# Name: AddField_Example2.py
# Description: Add a pair of new fields to a table
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
env.workspace = "C:/data/airport.gdb"
 
# Set local variables
inFeatures = "schools"
fieldName1 = "ref_ID"
fieldPrecision = 9
fieldAlias = "refcode"
fieldName2 = "status"
fieldLength = 10
 
# Execute AddField twice for two new fields
arcpy.AddField_management(inFeatures, fieldName1, "LONG", fieldPrecision, "", "",
                          fieldAlias, "NULLABLE")
arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength)

右键ArcToolbox查看Help里有:

3. 创建domain。

import arcpy
 
try:
    # Set the workspace (to avoid having to type in the full path to the data every time)
    arcpy.env.workspace = r'Database ConnectionsConnection to wuhan.sde'
 
    # Set local parameters
    domName = "管道层级"
    gdb = r'Database ConnectionsConnection to wuhan.sde'
    inFeatures = r'Database ConnectionsConnection to wuhan.sdesss.SDE.排水管'
    inField = "Pipe_Level"
 
    # Process: Create the coded value domain
    arcpy.CreateDomain_management(gdb, domName, "按管道层级", "SHORT", "CODED")
    
    #Store all the domain values in a dictionary with the domain code as the "key" and the 
    #domain description as the "value" (domDict[code])
    domDict = {"1":"入户线", "2": "支线", "3": "干线", 
                "4": "主干线"}
    
    # Process: Add valid material types to the domain
    #use a for loop to cycle through all the domain codes in the dictionary
    for code in domDict:        
        arcpy.AddCodedValueToDomain_management(gdb, domName, code, domDict[code])
    
    # Process: Constrain the material value of distribution mains
    arcpy.AssignDomainToField_management(inFeatures, inField, domName)
 
except Exception as err:
    print(err.args[0])

>>在服务器端操作时上面的连接sde的字符串也可能是

Database Connectionswuhan.sde

在服务器端赋域给属性时要注意先停止服务。

4. 将Domain赋值给属性

//Assign Domain to field

5. 为属性添加Alias

》》

1.比对属性是否相同。-->Excel

2.备份线上的数据库。

3.更新现在的数据库。

4.上传到线上数据库。

5.编写文档。

原文地址:https://www.cnblogs.com/2008nmj/p/14240329.html