YouTube | Facebook | Twitter  Feed

フィーチャの移動

2016/9/1 (木)

'ArcMapで編集セッションを有効にして移動対象のフィーチャを選択しておく
'http://edndoc.esri.com/arcobjects/8.3/Samples/Editing/MoveFeatures.htm
Public Sub MoveFeatures()
  Dim pEditor As IEditor
  Dim pEndPoint As IPoint
  Dim pEnumFeature As IEnumFeature
  Dim pFeature As IFeature
  Dim pFeatureEdit As IFeatureEdit
  Dim pID As New UID
  Dim pInvalidArea As IInvalidArea
  Dim pLine As ILine
  Dim pMoveSet As ISet
  Dim pSpatialReference As ISpatialReference
  Dim pStartPoint As IPoint
   
  Dim origX As Double
  Dim origY As Double
  Dim Count As Integer
  Dim bInOperation As Boolean
   
  On Error GoTo ErrorHandler
 
  'Get a reference to the editor extension
  pID = "esriCore.Editor"
  Set pEditor = Application.FindExtensionByCLSID(pID)
 
  'Create an edit operation enabling undo for the operation
  pEditor.StartOperation
  bInOperation = True
   
  'Make sure something has been selected
  If pEditor.SelectionCount = 0 Then Exit Sub
 
  'Add all the editor's selected features to a new set
  Set pEnumFeature = pEditor.EditSelection
   
'  'Flag those areas of the display that need refreshing
'  Set pInvalidArea = New InvalidArea
'  Set pInvalidArea.Display = pEditor.Display
'  pInvalidArea.Add pEnumFeature
 
  Set pMoveSet = New esriSystem.Set
  pEnumFeature.Reset
  For Count = 0 To pEditor.SelectionCount - 1
    Set pFeature = pEnumFeature.Next
    pMoveSet.Add pFeature
  Next Count
     
  'Reset the Set
  pMoveSet.Reset
     
  'MoveSet requires a line to specify the new location'Use the selection anchor as a starting point for the line
  Set pStartPoint = pEditor.SelectionAnchor.Point
  Set pLine = New Line
  pStartPoint.QueryCoords origX, origY
  Set pEndPoint = New Point
  pEndPoint.PutCoords (origX + 1050), (origY + 0) 'offset the selection by 50 units in the x direction
  pLine.PutCoords pStartPoint, pEndPoint
     
  'Get the spatial reference from the map and assign it to the new line
  Set pSpatialReference = pEditor.Map.SpatialReference
  Set pLine.SpatialReference = pSpatialReference 'Set the spatial reference of the new line'Do the move while looping through the set
  Set pFeatureEdit = pMoveSet.Next
  Do While Not pFeatureEdit Is Nothing
    pFeatureEdit.MoveSet pMoveSet, pLine  'Move all the selected features 50 units to the right
    Set pFeatureEdit = pMoveSet.Next
  Loop
     
  'Stop the Edit Operation
  pEditor.StopOperation "Move Selection"
  bInOperation = False
   
  Dim pMxDocument As IMxDocument
  Set pMxDocument = ThisDocument
  pMxDocument.ActiveView.Refresh
   
   
'  pInvalidArea.Invalidate esriAllScreenCaches
   
  'Additionally move the selection anchor
  pEditor.SelectionAnchor.MoveTo pEndPoint, pEditor.Display
   
  Exit Sub
   
ErrorHandler:
  If bInOperation Then
    pEditor.AbortOperation
    MsgBox "Error moving features.  Check selected features for topological associations."
  End If
  
End Sub

関連記事

  • この記事を書いた人

羽田 康祐

Esri認定インストラクター、GIS上級技術者、測量士補、潜水士。GISy / GISc とその関連分野である地理学・地図学について日々の出来事で学んだ記憶を記録するためにブログを書いています。行動原理は伊達と酔狂。好きな地形は圏谷。好きな地図投影法はパースクインカンシャル図法。呉市生まれ広島市出身。GIS を使った自己紹介はこちら

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

© 2020 WINGFIELD since1981