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 |
クエリ レイヤーの作成
2016/9/1 (木)