YouTube | Facebook | Twitter | RSS

フィーチャクラスの作成

Option Explicit

Public Sub CreateFeatureClass()
   
    'フィールドの作成
    Dim pFieldEdit(2) As IFieldEdit
    
    'ObjectID
    Set pFieldEdit(0) = New Field
    pFieldEdit(0).Type = esriFieldType.esriFieldTypeOID
    pFieldEdit(0).Name = "OBJECTID" '既定値は "OBJECTID"
    
    'SpatialReference
    Dim pSpatialReferenceFactory As ISpatialReferenceFactory
    Set pSpatialReferenceFactory = New SpatialReferenceEnvironment
     
    Dim pSpatialReference As ISpatialReference
    Set pSpatialReference = pSpatialReferenceFactory.CreateGeographicCoordinateSystem(esriSRGeoCSType.esriSRGeoCS_WGS1984)
 
    'XY座標精度の設定(9.2以降は設定必須)
    Dim pSpatialReferenceResolution As ISpatialReferenceResolution
    Set pSpatialReferenceResolution = pSpatialReference
    pSpatialReferenceResolution.SetDefaultXYResolution
     
    'XY許容値の設定(9.2以降は設定必須)
    Dim pSpatialReferenceTolerance As ISpatialReferenceTolerance
    Set pSpatialReferenceTolerance = pSpatialReference
    pSpatialReferenceTolerance.SetDefaultXYTolerance
    
    
    'GeometryDef
    Dim pGeometryDefEdit As IGeometryDefEdit
    Set pGeometryDefEdit = New GeometryDef
    pGeometryDefEdit.GeometryType = esriGeometryType.esriGeometryPoint
    pGeometryDefEdit.GridCount = 1
    pGeometryDefEdit.GridSize(0) = 0
    Set pGeometryDefEdit.SpatialReference = pSpatialReference
    
    'Geometry
    Dim strShapeField As String
    strShapeField = "SHAPE"   '既定値は "SHAPE"
    
    Set pFieldEdit(1) = New Field
    pFieldEdit(1).Name = strShapeField
    pFieldEdit(1).Type = esriFieldType.esriFieldTypeGeometry
    Set pFieldEdit(1).GeometryDef = pGeometryDefEdit
    
        
    'その他のフィールド
    Set pFieldEdit(2) = New Field
    pFieldEdit(2).Type = esriFieldType.esriFieldTypeString
    pFieldEdit(2).Name = "TEXT01"
    
    'Fieldsの作成
    Dim pFieldsEdit As IFieldsEdit
    Set pFieldsEdit = New Fields
    pFieldsEdit.AddField pFieldEdit(0)  '既定の順序は、OBJECTID, SHAPE, ...
    pFieldsEdit.AddField pFieldEdit(1)
    pFieldsEdit.AddField pFieldEdit(2)
    
    'ファイル ジオデータベースの作成
    Dim pWorkspaceFacttory As IWorkspaceFactory
    Set pWorkspaceFacttory = New FileGDBWorkspaceFactory
    
    Dim pName As IName
    Set pName = pWorkspaceFacttory.Create("C:\Users\ej2061\Documents\ArcGIS\", "FGDB01.gdb", Nothing, Application.hWnd)
    
    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pName.Open()
    
      
    'フィーチャクラスの作成
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureWorkspace.CreateFeatureClass("FeatureClass01", pFieldsEdit, Nothing, Nothing, esriFTSimple, strShapeField, "")  'フィーチャクラス名
    Dim pClassSchemaEdit As IClassSchemaEdit2
    Set pClassSchemaEdit = pFeatureClass
    pClassSchemaEdit.AlterAliasName "AliasName01"   'エイリアス名

    '現在のドキュメントを取得
    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
      
    'アクティブなデータフレームの取得
    Dim pMap As IMap
    Set pMap = pMxDocument.FocusMap
    
    'フィーチャ レイヤーの作成
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = New FeatureLayer
    pFeatureLayer.Name = pFeatureClass.AliasName
    Set pFeatureLayer.FeatureClass = pFeatureClass
      
    pMap.AddLayer pFeatureLayer
      
    
    MsgBox "Done"
    
End Sub

関連記事

  • この記事を書いた人

羽田 康祐

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

-プログラミング, ArcGIS