YouTube | Facebook | X(Twitter) | RSS

始点から各点にラインを引く方法

2016/9/1 (木)

Sub subCreateLine()
 
    Dim pMxDoc As IMxDocument
    Set pMxDoc = ThisDocument
     
    'ポイント
    Dim pFLayer0 As IFeatureLayer
    Set pFLayer0 = pMxDoc.FocusMap.Layer(0)
     
    Dim pFClass0 As IFeatureClass
    Set pFClass0 = pFLayer0.FeatureClass
     
    '作成ライン
    Dim pFLayer1 As IFeatureLayer
    Set pFLayer1 = pMxDoc.FocusMap.Layer(1)
 
    Dim pFClass1 As IFeatureClass
    Set pFClass1 = pFLayer1.FeatureClass
     
     
    'InsertCursor
    Dim pFeatureCursor As IFeatureCursor
Set pFeatureCursor = pFClass1.Insert(True)
 
 
    'フィーチャバッファを使用
    Dim pFeature1 As IFeature
    Set pFeature1 = pFClass1.CreateFeatureBuffer
     
    Dim i As Long   'ループ用
    Dim q As Long   'ObjectID
         
     
    Dim FromID As Long
    FromID = InputBox("中心点とするフィーチャIDを指定してください")
     
    '中心点用Feaeture取得
    Dim pCFeature As IFeature
    Set pCFeature = pFClass0.GetFeature(FromID)
     
    'ラインジオメトリ
    '始点
    Dim pFromPoint As IPoint
     
    '終点
    Dim pToPoint As IPoint
     
    'ライン
    Dim pLine As ILine
     
    Dim pPolyline As IPointCollection
    Dim pPolyCurve As IPolycurve
     
     
    Dim pFcursor0 As IFeatureCursor
    Set pFcursor0 = pFClass0.Search(Nothing, True)
     
    Dim pFeature0 As IFeature
    Set pFeature0 = pFcursor0.NextFeature
     
    Do Until pFeature0 Is Nothing
     
            If Not pFeature0.OID = FromID Then
             
            Set pFromPoint = pCFeature.Shape
            Set pToPoint = pFeature0.Shape
             
            pFromPoint.Project pMxDoc.FocusMap.SpatialReference
            pToPoint.Project pMxDoc.FocusMap.SpatialReference
             
            'ポリラインの作成
            Set pPolyline = New Polyline
             
            Set pPolyCurve = pPolyline
            pPolyCurve.Project pMxDoc.FocusMap.SpatialReference
             
            pPolyline.AddPoint pFromPoint
            pPolyline.AddPoint pToPoint
 
             
            pPolyCurve.Densify 1000, 0
 
             
            '属性情報の入力
            Set pFeature1.Shape = pPolyCurve
             
            'Featureの作成処理
            q = pFeatureCursor.InsertFeature(pFeature1)
     
    End If
     
    Set pFeature0 = pFcursor0.NextFeature
     
    Loop
     
     
    'フィーチャのフラッシュ
 
        pFeatureCursor.Flush
     
     
pMxDoc.ActiveView.Refresh
 
End Sub
  • この記事を書いた人

羽田 康祐

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

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