YouTube | Facebook | X(Twitter) | RSS

SDEWorkspace に新規フィーチャクラスの作成

2016/9/1 (木)

Public Sub subCreateFeatureClass()
    Dim pWSFactory As IWorkspaceFactory
    Set pWSFactory = New SdeWorkspaceFactory
     
    'SDE接続情報
    Dim Server As String
    Dim Instance As String
    Dim Database As String
    Dim User As String
    Dim Password As String
    Dim Version As String
     
    Server = ""
    Instance = "5151"
    Database = ""
    User = ""
    Password = ""
    Version = "SDE.DEFAULT"
     
     
    Dim pPropertySet As IPropertySet
    Set pPropertySet = New PropertySet
    With pPropertySet
        .SetProperty "SERVER", Server
        .SetProperty "INSTANCE", Instance
        .SetProperty "DATABASE", Database
        .SetProperty "USER", User
        .SetProperty "PASSWORD", Password
        .SetProperty "VERSION", Version
    End With
     
    Dim pFWorkspace As IFeatureWorkspace
    Set pFWorkspace = pWSFactory.Open(pPropertySet, Application.hWnd)
     
     
    'Fieldsの作成
     
    '空間参照の定義
    Dim pSR As ISpatialReference
    Set pSR = New UnknownCoordinateSystem
    pSR.SetDomain 0, 21474.83645, 0, 21474.83645
    pSR.SetFalseOriginAndUnits 0, 0, 100000
     
    'ジオメトリの定義
    Dim pGeometryDef As IGeometryDefEdit
    Set pGeometryDef = New GeometryDef
    pGeometryDef.GeometryType = esriGeometryPolygon
    Set pGeometryDef.SpatialReference = pSR
    pGeometryDef.GridCount = 1
    pGeometryDef.GridSize(0) = 10
    pGeometryDef.AvgNumPoints = 2
    pGeometryDef.HasM = False
    pGeometryDef.HasZ = False
     
    'Fieldの追加(ジオメトリ)
    Dim pField1 As IFieldEdit
    Set pField1 = New Field
    pField1.Name = "Shape"
    pField1.Type = esriFieldTypeGeometry
    Set pField1.GeometryDef = pGeometryDef  '先にFieldTypeを設定する必要あり
     
    'Fieldの追加(その他)
    Dim pField2 As IFieldEdit
    Set pField2 = New Field
    pField2.Name = "aaa"
    pField2.Type = esriFieldTypeDouble
    pField2.Length = 16
     
    'Fieldのコレクションを作成
    Dim pFields As IFieldsEdit
    Set pFields = New Fields
    pFields.AddField pField1
    pFields.AddField pField2
     
    'フィーチャクラスの作成
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFWorkspace.CreateFeatureClass("test", pFields, Nothing, Nothing, esriFTSimple, "Shape", "")
     
    MsgBox "フィーチャクラスを作成しました"
 
End Sub
  • この記事を書いた人

羽田 康祐

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

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