'住所ロケータの取得 Dim t As System.Type = Type.GetTypeFromProgID("esriLocation.LocatorManager") Dim obj As System.Object = Activator.CreateInstance(t) 'シングルトン Dim pLocatorManager As ILocatorManager2 = TryCast(obj, ILocatorManager2) Dim pLocatorWorkspace As ILocatorWorkspace = pLocatorManager.GetLocatorWorkspace("<ロケータを含むのジオデータベースのパス>") Dim pLocator As ILocator = pLocatorWorkspace.GetLocator("<ロケータ名>") '入力住所文字列の設定 Dim pAddressInputs As IAddressInputs = TryCast(pLocator, IAddressInputs) Dim pFields As IFields = pAddressInputs.AddressFields Dim pPropertySet As IPropertySet = New PropertySetClass() pPropertySet.SetProperty(pFields.Field(0).Name, Me.AddressTextBox.Text) 'アドレスマッチング Dim pAddressGeocoding As IAddressGeocoding = TryCast(pLocator, IAddressGeocoding) Dim resultPropertySet As IPropertySet = pAddressGeocoding.MatchAddress(pPropertySet) '複数候補を取得する場合 Dim pAddressCandidates As IAddressCandidates = CType(pAddressGeocoding, IAddressCandidates) Dim pArray As IArray = pAddressCandidates.FindAddressCandidates(pPropertySet) Dim resultCount As Integer = pArray.Count '結果件数 resultPropertySet = pArray.Element(0) '結果の要素取得 '出力 Dim names As Object = Nothing Dim values As Object = Nothing resultPropertySet.GetAllProperties(names, values) Dim namesArray() As String = TryCast(names, String()) Dim valuesArray() As Object = TryCast(values, Object()) Dim length As Integer = namesArray.Length Dim pPoint As IPoint = Nothing Dim outString As String = "" For i As Integer = 0 To length - 1 If namesArray(i) <> "Shape" Then outString += namesArray(i) + " :" + Constants.vbTab + valuesArray(i).ToSnstants.vbLf Else pPoint = TryCast(valuesArray(i), IPoint) If pPoint IsNot Nothing AndAlso (Not pPoint.IsEmpty) Then outString &= "X:" & Constants.vbTab & pPoint.X.ToString() + Constants.vbLf outString &= "Y:" & Constants.vbTab & pPoint.Y.ToString() + Constants.vbLf End If End If Next i outString += Constants.vbLf
住所ロケータでアドレスマッチングする方法
2016/9/1 (木)