ARCGIS PRO SDK VB2022 读取要素坐标

ReadOnlyPartCollection 类: 和 Polygon 使用的 ReadOnlySegmentCollection 部件的只读集合。
ReadOnlyPointCollection 类:返回所有顶点坐标
ReadOnlySegmentCollection:此类型的所有成员的列表
Copy2DCoordinatesToList 方法 :以 2D 坐标的只读列表形式获取所有部件中所有坐标的副本,返回对象IReadOnlyList<Coordinate2D> 
CopyPointsToList :将此列表中的 MapPoint 复制到给定的 MapPoint 列表中。
GetEnumerator方法: 返回循环访问集合的枚举器(返回对象ReadOnlyPointCollection)
Segment 类:表示起点和终点以及它们如何连接的抽象类
例如:读取 polygon1坐标
          读取所有坐标读入IReadOnlyList
​Dim coordinates As IReadOnlyList(Of Coordinate2D) = polygon1.Copy2DCoordinatesToList()
          读取所有坐标读入ReadOnlyPointCollection
Dim ppts As ReadOnlyPointCollection = polygon1.Points
         读取所有坐标读入IEnumerator
Dim enumPts As IEnumerator(Of MapPoint) = polygon1.Points.GetEnumerator()
        读取第一个部件坐标读入subsetCoordinates2D
Dim coordinate2Ds As IList(Of Coordinate2D) = New List(Of Coordinate2D)(10)
Dim subsetCoordinates2D As ICollection(Of Coordinate2D) = coordinate2Ds
ppts.Copy2DCoordinatesToList(1, 1, subsetCoordinates2D)

一、读取点要素坐标

Dim point As ArcGIS.Core.Geometry.MapPoint
Dim Pfeature As Feature
For it = 0 To Map.Layers.Count - 1
    If Map.Layers(it).Name = "JZD" Then
        Layer = CType(Map.Layers(it), FeatureLayer)
        ttp = 1
        EXIT FOR
    End If
Next
If ttp = 0 Then
    MsgBox("界址点层不存在。")
    Exit Sub
End If
Await QueuedTask.Run(Sub()
                         pfeatureClass = Layer.GetFeatureClass
                         Dim rowS As RowCursor = pfeatureClass.Search()
                         While rowS.MoveNext
                             Pfeature = CType(rowS.Current, Feature)
                             point = Pfeature.GetShape
                             Console.WriteLine(point.X & "," & point.Y)
                             Debug.Print(point.X & "," & point.Y)
                         End While
                     End Sub)

二、读取线要素坐标(完整代码)

     Dim segments As IEnumerator(Of MapPoint)
     Dim ttp As Integer
     Dim Polyline As ArcGIS.Core.Geometry.Polyline
     Dim point As ArcGIS.Core.Geometry.MapPoint
     Dim Pfeature As Feature
     MapView = MapView.Active
     '获取地图视图的关联地图
     Map = MapView.Map
     ttp = 0
     '获取的图层
     For it = 0 To Map.Layers.Count - 1
         If Map.Layers(it).Name = "权属界线" Then
             Layer = CType(Map.Layers(it), FeatureLayer)
             ttp = 1
         End If
     Next
     If ttp = 0 Then
         MsgBox("权属界线层不存在。")
         Exit Sub
     End If
     '枚举器arcgis
     Await QueuedTask.Run(Sub()
                              pfeatureClass = Layer.GetFeatureClass
                              Dim rowS As RowCursor = pfeatureClass.Search()

                              While rowS.MoveNext
                                  Pfeature = CType(rowS.Current, Feature)
                                  Polyline = Pfeature.GetShape
                                  segments = Polyline.Points.GetEnumerator
                                  Dim coordinates As IReadOnlyList(Of Coordinate2D) = Polyline.Copy2DCoordinatesToList()
                                  Dim ppts As ReadOnlyPointCollection = Polyline.Points
                                  Dim xhcsz As Integer = 0
                                  For Each parts In Polyline.Parts
                                      For J As Integer = 0 To parts.Count
                                          Console.WriteLine(ppts(J + xhcsz).X & "," & ppts(J + xhcsz).Y)
                                          Debug.Print((J + 1 + xhcsz).ToString & "," & ppts(J + xhcsz).X & "," & ppts(J + xhcsz).Y)
                                      Next
                                      xhcsz += parts.Count + 1
                                  Next
                              End While
                          End Sub)

三、读取面要素坐标(核心代码)

方法一、通过枚举

   Dim polygon1 As polygon = pfeature.GetShape
  Dim Parts 
  Dim polygon_vs as Integer=polygon1.PointCount
 MsgBox("本多边形由" & Parts & "部件组成。" & vbCrLf & "总点数" & polygon_vs)
 '多边形的最外层(外部,顺时针)环。如果输入为null或空,则返回null
 If polygon1 Is Nothing = True Or polygon1.IsEmpty = True Then
     MsgBox("输入为空。")
     Exit Sub
 End If

 '枚举器arcgis
 Dim coordinates As IReadOnlyList(Of Coordinate2D) = polygon1.Copy2DCoordinatesToList()
 Dim ppts As ReadOnlyPointCollection = polygon1.Points
 Dim xhcsz As Integer = 0
 For Each parts In polygon1.Parts  '第一次:面的外环
     For J As Integer = 0 To parts.Count
         Console.WriteLine(ppts(J + xhcsz).X & "," & ppts(J + xhcsz).Y)
         Debug.Print((J + 1 + xhcsz).ToString & "," & ppts(J + xhcsz).X & "," & ppts(J + xhcsz).Y)
     Next
     xhcsz += parts.Count + 1
 Next

方法二、通过要素的JSON文本来截取的做法

partnum = 1
Pfeature = CType(rowS.Current, Feature)
polygon1 = Pfeature.GetShape
js = polygon1.ToJson().ToString()
Console.WriteLine(js)
Dim cod As String = js.Substring((js.IndexOf("[[[") + 3), js.IndexOf("]]]") - js.IndexOf("[[[") - 3)
'坐标点列表
Dim list_xy As List(Of String) = cod.Split("]]").ToList()
For  i As Integer = 0 TO list_xy.Count-1
    '坐标行
    Dim xy_detils As List(Of string)  = list_xy(i).Replace(",[[", "").Split("],[").ToList()
    '加一行title
    Dim  count As Integer  = xy_detils.Count    '点的个数
    Dim title As String = count.ToString & "," & ft_name & "," & "面" & "," & ft_type & "," & "@" & vbCrLf
    txt_all += title
    index = 0
    For j As Integer = 0 To (xy_detils.Count - 1)
        '点序号
        index = j + 1
        If j = xy_detils.Count - 1 Then
            index = 1
        End If
        ' XY坐标点
        pxy = xy_detils(j).Split(",")
        'px = Math.Round(pxy(0), 3).ToString()
        'py = Math.Round(pxy(0), 3).ToString()
        px = Format(Val(pxy(0)), "0.000").ToString()
        py = Format(Val(pxy(1)), "0.000").ToString()
        ' 加入文本
        txt_all += "J" & index & "," & partnum & "," & py & "," & px & vbCrLf
    Next
    partnum += 1
Next

方法三、读取指定部件坐标: 读入subsetCoordinates2D

Dim ppts As ReadOnlyPointCollection = polygon1.Points
Dim coordinate2Ds As IList(Of Coordinate2D) = New List(Of Coordinate2D)(10)
Dim subsetCoordinates2D As ICollection(Of Coordinate2D) = coordinate2Ds
ppts.Copy2DCoordinatesToList(1, 1, subsetCoordinates2D)
For i = 0 To dbx_zds - 1
    pv_x(i) = subsetCoordinates2D(i).X
    pv_y(i) = subsetCoordinates2D(i).Y
Next

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值