ARCGIS PRO SDK VB2022 要素几何独立操作

一、获取要素的几何图形pGeometry

1、创建新要素:例如新建线要素line1 

Dim pts As List(Of MapPoint) = New List(Of MapPoint)
Dim pGeometry As ArcGIS.Core.Geometry.Geometry
pts.Add(MapPointBuilderEx.CreateMapPoint(1.0, 1.0))
pts.Add(MapPointBuilderEx.CreateMapPoint(3.0, 3.0))
pts.Add(MapPointBuilderEx.CreateMapPoint(5.0, 1.0))
Dim line1 As ArcGIS.Core.Geometry.Polyline = PolylineBuilderEx.CreatePolyline(pts)
pGeometry = line1

2、获取加载图层的要素,TK_LINE图层名称

Dim pLayer1 As FeatureLayer = Map.FindLayers("TK_LINE").First()
Dim pfeatureClass As FeatureClass
Dim tableCursor As RowCursor
Dim pGeometry As ArcGIS.Core.Geometry.Geometry

Await QueuedTask.Run(Sub()
                         pfeatureClass = pLayer1.GetFeatureClass
                         tableCursor = pfeatureClass.Search()
                         While tableCursor.MoveNext
                             pfeature = CType(tableCursor.Current, Feature)
                             pGeometry = pfeature.GetShape
                         End While
                     End Sub)

一、平移

Dim pGeometry As ArcGIS.Core.Geometry.Geometry
Dim pGeometry1 As ArcGIS.Core.Geometry.Geometry
Dim dx As Double
Dim dy As Double
'将pGeometry按X、Y方向各自的偏移量,平移pGeometry,得到pGeometry1
pGeometry1 = GeometryEngine.Instance.Move(pGeometry, dx, dy)

二、缩放

Dim pGeometry As ArcGIS.Core.Geometry.Geometry
Dim pGeometry1 As ArcGIS.Core.Geometry.Geometry
Dim Lpoint As MapPoint
Dim dx As Double
Dim dy As Double
Dim Scale_x As Double
Dim Scale_y As Double
Dim px As Double
Dim py As Double
Lpoint = MapPointBuilderEx.CreateMapPoint(px, py)   'origin  缩放点
'将pGeometry以缩放点Lpoint为中心按X、Y方向各自缩放比例,得到pGeometry1
pGeometry1 = GeometryEngine.Instance.Scale(pGeometry, Lpoint, Scale_x, Scale_y)

三、旋转

Dim pGeometry As ArcGIS.Core.Geometry.Geometry
Dim pGeometry1 As ArcGIS.Core.Geometry.Geometry
Dim Lpoint As MapPoint
Dim PRotate As Double    '旋转角
Dim px As Double
Dim py As Double

Lpoint = MapPointBuilderEx.CreateMapPoint(px, py)   'origin  缩放点
'将pGeometry以旋转点Lpoint为中心,得到pGeometry1
pGeometry1 = GeometryEngine.Instance.Scale(pGeometry, Lpoint, Scale_x, Scale_y)
Geometry rotatedPolyline = GeometryEngine.Instance.Rotate(textLine, origin, System.Math.PI *PRotate/180)

四、复制平移

Dim Layer As FeatureLayer = Map.FindLayers("TK_LINE").First()
Dim dx As Double
Dim dy As Double
 '创建编辑器
Dim duplicateFeatures = New EditOperation
duplicateFeatures.Name = "Duplicate Features"
'创建【inspector】实例
Await QueuedTask.Run(Sub()
                     Dim insp2 = New Inspector
                    '加载
                     Dim Oid As Long = 2
                     insp2.Load(Layer, Oid)
                     
                     pfeatureClass = Layer.GetFeatureClass
                     '获取复制对象
                     Dim geom As ArcGIS.Core.Geometry.Geometry = insp2("SHAPE")
                    '复制要素及全属性复制                     
                     Dim rtoken = duplicateFeatures.Create(insp2.MapMember, insp2.ToDictionary(Function(a) a.FieldName, Function(a) a.CurrentValue))
                     If duplicateFeatures.IsEmpty = False Then
                           If duplicateFeatures.Execute = True Then
                              '移动位置
                               Dim modifyOp = duplicateFeatures.CreateChainedOperation
                               modifyOp.Modify(Layer, rtoken.ObjectID, GeometryEngine.Instance.Move(geom, dx, dy))
                               If modifyOp.IsEmpty = False Then
                                    modifyOp.Execute()
                               End If
                           End If
                     End If
                    End Sub)

五、平行复制

       Dim roadsLayer = MapView.Active.Map.FindLayers("Roads").FirstOrDefault()
       ' 建立平行复制生成器,并设置参数
       Dim parOffsetBuilder = New ParallelOffset.Builder()
       With parOffsetBuilder
           .Selection = MapView.Active.Map.GetSelection()      '所选要素
           '.Template = roadsLayer.GetTemplate("Freeway")      '模板(可以不选)
           .Distance = 200                                     '偏移距离
           .Side = ParallelOffset.SideType.Both                '偏移方式(左,右,两侧)
           .Corner = ParallelOffset.CornerType.Mitered         '拐角处理方式(圆角,斜接角,斜面角)
           .Iterations = 1                                     '重复偏移的次数
           .AlignConnected = False                             '是否对齐连接线的方向
           .CopyToSeparateFeatures = False                      '是否复制到独立要素
           .RemoveSelfIntersectingLoops = True                  '是否移除自相交环
       End With

       '创建编辑器并执行
       Dim parallelOp = New EditOperation()
       parallelOp.Create(parOffsetBuilder)
       If parallelOp.IsEmpty = False Then
           Dim Result = parallelOp.Execute()
           If Result = False Then
               MsgBox("操作失败。")
               Exit Sub
           End If
       End If

六、炸开多部件

Dim FeatureLayer = MapView.Active.Map.FindLayers("TK_Polygon").FirstOrDefault()
Layer = FeatureLayer
pfeatureClass = Layer.GetFeatureClass
Dim POid As List(Of Long)
POid = New List(Of Long)
POid.Add(0)
explodeFeatures.Explode(FeatureLayer, POid, True)
If explodeFeatures.IsEmpty = False Then
    Dim result = explodeFeatures.Execute()
    If result = False Then
        MsgBox("操作失败。")
        Exit Sub
    End If
End If

七、缓冲

Geometry1 = GeometryEngine.Instance.Buffer(Geometry, 5.0)

你可能感兴趣的:(arcgis)