一、数据库创建属性域。
sdk3.1 以下的开发版本不支持,不能使用 Pro SDK 向域添加新的编码值,可以使用地理处理工具:
'创建属性域
Dim va As IReadOnlyList(Of String)
Dim gpResult As ArcGIS.Desktop.Core.Geoprocessing.IGPResult
Dim environments = Geoprocessing.MakeEnvironmentArray(overwriteoutput:=True)
Dim executeFlags As GPExecuteToolFlags = GPExecuteToolFlags.AddOutputsToMap
Dim pgdbPath As String = Project.Current.DefaultGeodatabasePath
va = Geoprocessing.MakeValueArray(pgdbPath, "JZX_WZ", "界址线位置", "TEXT", "CODED")
Await Geoprocessing.ExecuteToolAsync("Management.CreateDomain", va, environments, Nothing, Nothing, executeFlags)
Dim domDict = New Dictionary(Of Integer, String)
domDict.Add(1, "左")
domDict.Add(2, "中")
domDict.Add(3, "右")
For Each code In domDict
Await Geoprocessing.ExecuteToolAsync("management.AddCodedValueToDomain", Geoprocessing.MakeValueArray(pgdbPath, "JZX_WZ", code.Key, code.Value))
Next
'作业于要素类、字段
va = Geoprocessing.MakeValueArray(pgdbPath & "\界址线", "JZX_WZ", "JZX_WZ")
Await Geoprocessing.ExecuteToolAsync("Management.AssignDomainToField", va)
实例见下图:
二、读取属性域
Dim tlxl As IReadOnlyList(Of Domain)
Dim domDict_jzx_xz = New Dictionary(Of Integer, String)
Pgeodatabase = New Geodatabase(New FileGeodatabaseConnectionPath(New Uri(pgdbPath)))
tlxl = Pgeodatabase.GetDomains
For Each pDict As Domain In tlxl
If pDict.GetName = "JZX_WZ" Then
Dim cvd As CodedValueDomain = pDict
Dim domDict_jzx As SortedList(Of Object, String) = cvd.GetCodedValuePairs
For Each item In domDict_jzx
domDict_jzx_wz.Add(item.Key, item.Value)
Next
End If
Next