YouTube | Facebook | X(Twitter) | RSS

コード値ドメインの利用

2016/9/1 (木)

Sub GetUniqueVal()
  Dim pMxdoc As IMxDocument
  Dim pMap As IMap
  Dim pFLayer As IFeatureLayer
  Dim pFClass As IFeatureClass
  Dim pFCursor As IFeatureCursor
  Set pMxdoc = ThisDocument
  Set pMap = pMxdoc.FocusMap
  Set pFLayer = pMap.Layer(0)
  Set pFClass = pFLayer.FeatureClass
   
  Dim pFields As IFields
  Dim i As Long
  Dim pField As IField
  Dim pDomain As IDomain
  Set pFields = pFClass.Fields
  i = pFields.FindField("FAC_IDFR")
  Set pField = pFields.Field(i)
  Set pDomain = pField.Domain
  'Debug.Print pDomain.Description & "," & pDomain.Name & "," & pDomain.Type
   
  Select Case pDomain.Type
    Case Is = esriDomainType.esriDTCodedValue
      Dim pCVDomain As ICodedValueDomain
      Set pCVDomain = pDomain
'      Dim icnt As Integer
'      For icnt = 0 To pCVDomain.CodeCount - 1
'        Debug.Print (pCVDomain.Name(icnt) & "," & pCVDomain.value(icnt))
'      Next
    Case Is = esriDomainType.esriDTRange
      Dim pRDomain As IRangeDomain
      Set pRDomain = pDomain
    Case Is = esriDomainType.esriDTString
      Dim pSDomain As IStringDomain
      Set pSDomain = pDomain
  End Select
   
'  Dim pFields As IFields
'  Set pFields = pFClass.Fields
'  Dim icnt As Integer
  Dim ufrm As New UserForm3
'  For icnt = 0 To pFields.FieldCount - 1
'    ufrm.lstFileds.AddItem pFields.Field(icnt).Name, icnt
'  Next
 
  Dim pCursor As ICursor
  Set pCursor = pFClass.Search(Nothing, False)
 
  Dim pDatastat As IDataStatistics
  Set pDatastat = New DataStatistics
  pDatastat.Field = "FAC_IDFR"
  Set pDatastat.Cursor = pCursor
 
  Dim pEnumVar As IEnumVariantSimple
  Dim value As Variant
  'Dim pField As IField
  Dim ii As Integer
  Set pEnumVar = pDatastat.UniqueValues
  value = pEnumVar.Next
  Do Until IsEmpty(value)
    'Debug.Print value
    For ii = 0 To pCVDomain.CodeCount - 1
      If pCVDomain.value(ii) = value Then
        ufrm.lstUniqueValue.AddItem pCVDomain.value(ii) & "," & pCVDomain.Name(ii)
      End If
    Next
    'ufrm.lstUniqueValue.AddItem value
     
    value = pEnumVar.Next
  Loop
   
  ufrm.Show
   
   
End Sub
  • この記事を書いた人

羽田 康祐

伊達と酔狂のGISエンジニア。GIS上級技術者、Esri認定インストラクター、CompTIA CTT+ Classroom Trainer、潜水士、PADIダイブマスター、四アマ。WordPress は 2.1 からのユーザーで歴だけは長い。 代表著書『"地図リテラシー入門―地図の正しい読み方・描き方がわかる』 GIS を使った自己紹介はこちら。ESRIジャパン(株)所属、元青山学院大学非常勤講師を兼務。日本地図学会第31期常任委員。発言は個人の見解です。

-プログラミング, ArcGIS
-,