ArcGIS在属性计算和Geoprocessing中都用到了Python。
属性计算请看:https://www.cnblogs.com/2008nmj/p/13813941.html
Geoprocessing下拉框中的Python:
>>ArcGIS开发权威指南:https://www.cnblogs.com/2008nmj/p/13801096.html
用ArcPy创建域Domain:https://desktop.arcgis.com/zh-cn/arcmap/latest/tools/data-management-toolbox/create-domain.htm
命名空间Database Connections\wuhan.sde
>>> arcpy.env.workspace = r'Database Connections\Connection to DESKTOP-NF3M1HO.sde'
语法
CreateDomain(in_workspace, domain_name, {domain_description}, {field_type}, {domain_type}, {split_policy}, {merge_policy})
参数 | 说明 | 数据类型 |
in_workspace
|
将包含新属性域的地理数据库。 |
Workspace |
domain_name
|
要创建的属性域的名称。 |
String |
domain_description
(可选)
|
要创建的属性域的描述。 |
String |
field_type
(可选)
|
要创建的属性域的类型。属性域是描述字段类型合法值的规则。指定的字段类型应与将属性域指定到的字段的数据类型相匹配。
|
String |
domain_type
(可选)
|
要创建的属性域类型:
|
String |
split_policy
(可选)
|
所创建属性域的分割策略。分割要素时,属性值的行为受控于它的分割策略。
|
String |
merge_policy
(可选)
|
所创建属性域的合并策略。在将两个要素合并为一个要素时,合并策略控制着新要素的属性值。
|
String |
代码示例
创建属性域示例(Python 窗口)
以下 Python 窗口脚本演示了如何在即时模式下使用 CreateDomain 函数。
import arcpy
arcpy.env.workspace = "C:/data"
arcpy.CreateDomain_management("montgomery.gdb", "Materials", "Valid pipe materials", "TEXT", "CODED")
创建属性域示例 2(独立脚本)
此独立脚本将 CreateDomain 函数用作工作流的一部分,以创建属性域、为其赋值并将属性域分配给要素类的字段。
# Name: MakeDomain.py
# Description: Create an attribute domain to constrain pipe material values
#Import system modules
import arcpy
try:
# Set the workspace (to avoid having to type in the full path to the data every time)
arcpy.env.workspace = "C:/data"
# Set local parameters
domName = "Material4"
gdb = "montgomery.gdb"
inFeatures = "Montgomery.gdb/Water/Distribmains"
inField = "Material"
# Process: Create the coded value domain
arcpy.CreateDomain_management("montgomery.gdb", domName, "Valid pipe materials", "TEXT", "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 = {"CI":"Cast iron", "DI": "Ductile iron", "PVC": "PVC", \
"ACP": "Asbestos concrete", "COP": "Copper"}
# 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])
除了官网以外,也可以在ArcToolbox的Help中查看帮助:https://jingyan.baidu.com/article/eae07827ba96a51fec548513.html
>>> arcpy.CreateDomain_management(r'C:\Users\Administrator\AppData\Roaming\Esri\Desktop10.2\ArcCatalog\wuhan.sde', "管道层级", "按管道层级", "SHORT", "CODED")
>>> arcpy.AssignDomainToField_management("排水管", "Pipe_Level", "管道层级")
注意:'Database Connections\wuhan.sde'也可以。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)