YouTube | Facebook | Twitter  Feed

クエリ レイヤーの作成

2016/9/1 (木)

Sub CreateQueryLayer()
    Dim pWorkspaceFactory As IWorkspaceFactory
    Set pWorkspaceFactory = New SqlWorkspaceFactory
     
    Dim pPropertySet As IPropertySet
    Set pPropertySet = New PropertySet
     
    pPropertySet.SetProperty "DBCLIENT", "sqlserver"
    pPropertySet.SetProperty "SERVERINSTANCE", "xxxxxx\sqlexpress"
    pPropertySet.SetProperty "DATABASE", "GeoDatabase"
'    pPropertySet.SetProperty "AUTHENTICATION_MODE", "DBMS"
    pPropertySet.SetProperty "AUTHENTICATION_MODE", "OSA"
'    pPropertySet.SetProperty "USER", "XXX"
'    pPropertySet.SetProperty "PASSWORD", "XXX"
 
'    'SDEジオデータベースをクエリ レイヤで接続したものから取得したPropertySet
'    pPropertySet.SetProperty "SERVER", "xxxxxx"
'    pPropertySet.SetProperty "INSTANCE", "sde:sqlserver:xxxxxx\sqlexpress"
'    pPropertySet.SetProperty "DBCLIENT", "sqlserver"
'    pPropertySet.SetProperty "DB_CONNECTION_PROPERTIES", "xxxxxx\sqlexpress"
'    pPropertySet.SetProperty "DATABASE", "GeoDatabase"
'    pPropertySet.SetProperty "IS_GEODATABASE", "True"
'    pPropertySet.SetProperty "AUTHENTICATION_MODE", "OSA"
'    pPropertySet.SetProperty "CONNPROP-REV", "Rev1.0"
'    pPropertySet.SetProperty "VERSION", "dbo.DEFAULT"
 
    Dim pWorkspace As IWorkspace
    Set pWorkspace = pWorkspaceFactory.Open(pPropertySet, 0)
     
    Dim pSqlWorkspace As ISqlWorkspace
    Set pSqlWorkspace = pWorkspace
     
    'クエリの作成
    Dim pQueryDescription As IQueryDescription
    Set pQueryDescription = pSqlWorkspace.GetQueryDescription("select * from GeoDatabase.dbo.JAPAN")
    pQueryDescription.GeometryType = esriGeometryPolygon        'ジオメトリ タイプ
    pQueryDescription.Srid = "4612"                             '座標系WKID
    Set pQueryDescription.SpatialReference = pSpatialRefernece  '座標系
    pQueryDescription.OIDFields = "OBJECTID"                    'ユニークID識別子
     
    Dim pFeatureWorkaspce As IFeatureWorkspace
    Set pFeatureWorkaspce = pWorkspace
     
    Dim pStringArray As IStringArray
    Set pStringArray = pSqlWorkspace.GetTables
     
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pSqlWorkspace.OpenQueryClass("%" & "JAPAN", pQueryDescription)  'クエリ
     
    'フィーチャ レイヤの追加
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
     
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = New FeatureLayer
    pFeatureLayer.Name = "Query Layer"
    Set pFeatureLayer.FeatureClass = pFeatureClass
     
    pMxDocument.AddLayer pFeatureLayer
 
    pMxDocument.ActiveView.Refresh
    pMxDocument.UpdateContents
 
End Sub

関連記事

  • この記事を書いた人

羽田 康祐

Esri認定インストラクター、GIS上級技術者、測量士補、潜水士。GISy / GISc とその関連分野である地理学・地図学について日々の出来事で学んだ記憶を記録するためにブログを書いています。行動原理は伊達と酔狂。好きな地形は圏谷。好きな地図投影法はパースクインカンシャル図法。呉市生まれ広島市出身。GIS を使った自己紹介はこちら

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

© 2020 WINGFIELD since1981