YouTube | Facebook | X(Twitter) | RSS

FeatureCursorBuffer を使用したバッファー作成

2016/9/1 (木)

' ワークスペースの名前を作成
Dim pWorkspaceName As IWorkspaceName = New WorkspaceName
Dim factoryType As Type = Type.GetTypeFromProgID("esriDataSourcesGDB.ScratchWorkspaceFactory")
Dim pScracthWorkspaceFactory As IScratchWorkspaceFactory2 = CType(Activator.CreateInstance(factoryType), IScratchWorkspaceFactory2)
Dim pWorkspace As IWorkspace = pScracthWorkspaceFactory.CreateNewScratchWorkspace()
Dim pDataset As IDataset = CType(pWorkspace, IDataset)
 
' フィーチャクラスの名前を作成
Dim pFeatureClassName As IFeatureClassName = New FeatureClassName
With pFeatureClassName
    .FeatureType = esriFeatureType.esriFTSimple
    .ShapeFieldName = "Shape"
    .ShapeType = esriGeometryType.esriGeometryPolygon
End With
 
' データセットの名前を作成
Dim pDatasetName As IDatasetName = pFeatureClassName
With pDatasetName
    .Name = "test"
    .WorkspaceName = pDataset.FullName
End With
 
' TOC の最上位レイヤを取得
Dim pMxDocument As IMxDocument = My.ArcMap.Document
Dim pMap As IMap = pMxDocument.FocusMap
Dim pLayer As ILayer = pMap.Layer(0)
Dim pFeatureLayer As IFeatureLayer = pLayer
 
' レイヤの空間参照を取得
Dim pGeoDataset As IGeoDataset = pFeatureLayer
Dim pSpatialReference As ISpatialReference = pGeoDataset.SpatialReference
 
' レイヤのカーソルを取得
Dim pFeatureCursor As IFeatureCursor = pFeatureLayer.Search(Nothing, True)
 
' FeatureCursorBuffer オブジェクトの取得 
Dim pFeatureCursorBuffer As IFeatureCursorBuffer2 = New FeatureCursorBuffer
 
' バッファ プロセスのプロパティを設定
Dim pBufferProcessingParameter As IBufferProcessingParameter = pFeatureCursorBuffer
With pBufferProcessingParameter
    .AdjustCirclesForProjection = False
    .BufferSpatialReference = esriBufferSpatialReferenceType.esriFeatureSetOptimizedSpatialReference
    .FeatureClass = pFeatureLayer.FeatureClass
    .GenerateRings = False
    .InputHasPolygons = False
    .SaveAsGraphics = False
    .SimplifyShapes = False
    .TargetSpatialReference = esriBufferSpatialReferenceType.esriFeatureSetOptimizedSpatialReference
End With
 
' FeatureCursorBuffer のプロパティを設定
With pFeatureCursorBuffer
    .PolygonBufferType = esriBufferType.esriBufferAll
    .Dissolve = False
    .CancelTrack = Nothing
    .FeatureCursor = pFeatureCursor
    .ValueDistance = 100000
    .SpatialReference = pSpatialReference
    .Units(esriUnits.esriMeters) = esriUnits.esriMeters
    .BufferSpatialReference = pSpatialReference
    .DataFrameSpatialReference = pSpatialReference
    .TargetSpatialReference = pSpatialReference
    .Buffer(pFeatureClassName) ' バッファの実行
End With
 
Dim pFCName As IName = CType(pFeatureClassName, IName)
Dim pFeatureClass As IFeatureClass = CType(pFCName.Open(), IFeatureClass)
Dim pFeatureCursor2 As IFeatureCursor = pFeatureClass.Search(Nothing, True)
Dim pFeature As IFeature = pFeatureCursor2.NextFeature()
Dim pGeometryBag As IGeometryCollection = New GeometryBagClass
 
While Not pFeature Is Nothing
    pGeometryBag.AddGeometry(pFeature.ShapeCopy)
    pFeature = pFeatureCursor2.NextFeature()
End While
  • この記事を書いた人

羽田 康祐

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

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