YouTube | Facebook | X(Twitter) | RSS

クエリ レイヤーの作成

2016/9/1 (木)

VBA
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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
  • この記事を書いた人

羽田 康祐

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

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

S