博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ArcMap中用VBA读度矢量图层信息
阅读量:7049 次
发布时间:2019-06-28

本文共 3585 字,大约阅读时间需要 11 分钟。

 ArcMap下用VBA操作图层基本的过程了。

1 Private Sub UIButtonControl1_Click()   2 Dim pApp As IApplication  3 Set pApp = Application  4 Dim pDoc As IMxDocument  5 Set pDoc = pApp.Document  6 Dim pMap As IMap  7 Set pMap = pDoc.FocusMap  8 Dim pLayer As ILayer  9 Set pLayer = pDoc.SelectedLayer 10  11 If (pLayer Is Nothing) Then MsgBox "请选择要计算的图层!": Exit Sub 12 Dim pFeatLayer As IFeatureLayer 13 Set pFeatLayer = pLayer 14  15 Dim pFeatClass As IFeatureClass 16 Set pFeatClass = pFeatLayer.FeatureClass 17  18 Dim outStr As String 19  20 Select Case pFeatClass.ShapeType '1为point,3为polyline,4为polygon 21     Case 1 22         MsgBox ("当前图层为点图层") 23         Call compoint(pFeatClass, outStr) 24     Case 3 25         MsgBox ("当前图层为面图层") 26         Call compolyline(pFeatClass, outStr) 27     Case 4 28         MsgBox ("当前图层为面图层") 29         Call compolygon(pFeatClass, outStr) 30     Case Else 31 End Select 32  33 Dim msgStr() As String 34 Dim maxi As Integer 35 ReDim Preserve msgStr(0) 36 maxi = -1 37 For i = 0 To CInt((Len(outStr) / 640)) 38     maxi = maxi + 1 39     ReDim Preserve msgStr(maxi) 40     msgStr(maxi) = Mid(outStr, 640 * i + 1, 640) 41 Next 42 For i = 0 To UBound(msgStr) - 1 43     MsgBox (msgStr(i)) 44 Next 45  46  47  48 End Sub//获取点图层坐标信息  49 Private Function compoint(pFeatClass As IFeatureClass, ByRef outStr As String) 50 Dim pPnt As IPoint 51  52 Dim pFeatCursor As IFeatureCursor 53 Set pFeatCursor = pFeatClass.Search(Nothing, False) 54  55 Dim pFeature As IFeature 56 Set pFeature = pFeatCursor.NextFeature 57 Dim sName As String 58 Do Until pFeature Is Nothing 59     Set pPnt = pFeature.Shape 60     sName = pFeature.Value(pFeature.Fields.FindField("CITY_NAME")) 61     Set pFeature = pFeatCursor.NextFeature 62     outStr = outStr + sName + ": " + Str(pPnt.X) + "," + Str(pPnt.Y) 63     If pPnt.Z <> Null Then outStr = outStr + Str(pPnt.Z) 64     outStr = outStr + vbNewLine 65 Loop 66  67 End Function 68 //获取线图层长度信息等属性信息  69 Private Function compolyline(pFeatClass As IFeatureClass, ByRef outStr As String) 70 Dim pPolyline As IPolyline 71 Dim pFeatCursor As IFeatureCursor 72 Set pFeatCursor = pFeatClass.Search(Nothing, False) 73 Dim pFeature As IFeature 74 Set pFeature = pFeatCursor.NextFeature 75 Dim itab As Integer 76 Dim sName As String 77  78 Do Until pFeature Is Nothing 79     itab = 1 + itab 80     Set pPolyline = pFeature.Shape 81     sName = pFeature.Value(pFeature.Fields.FindField("NAME")) 82     Set pFeature = pFeatCursor.NextFeature 83     outStr = outStr + "元素" + CStr(itab) + ": " + sName + ",长度为:" + Str(pPolyline.Length) + ";" + vbNewLine 84 Loop 85  86 End Function 87// 获取多边形图层信息等属性信息  88 Private Function compolygon(pFeatClass As IFeatureClass, ByRef outStr As String) 89 Dim pArea As IArea 90 Dim pPolygon As IPolygon 91 Dim pFeatCursor As IFeatureCursor 92 Set pFeatCursor = pFeatClass.Search(Nothing, False) 93 Dim pPnt As IPoint 94 Dim pFeature As IFeature 95 Set pFeature = pFeatCursor.NextFeature 96 Dim sName As String 97 Do Until pFeature Is Nothing 98     Set pPolygon = pFeature.Shape 99     Set pArea = pPolygon100     Set pPnt = pArea.Centroid101     sName = pFeature.Value(pFeature.Fields.FindField("STATE_NAME"))102     Set pFeature = pFeatCursor.NextFeature103     outStr = outStr + sName + ": " + _104         "周长是:" + Str(pPolygon.Length) + _105         ",面积是:" + Str(pArea.Area) + _106         ",重心是:(" + Str(pPnt.X) + "," + Str(pPnt.Y) + ")"107     If pPnt.Z <> Null Then outStr = outStr + Str(pPnt.Z)108     outStr = outStr + vbNewLine109 Loop110 111 End Function

 

转载于:https://www.cnblogs.com/lulee007/p/3222218.html

你可能感兴趣的文章
ASP.NET中Session的个人浅谈
查看>>
ORACLE里锁有以下几种模式,v$locked_object,locked_mode
查看>>
【树莓派】Linux 测网速及树莓派源
查看>>
Java用户线程和守护线程
查看>>
[TypeScript] Use the never type to avoid code with dead ends using TypeScript
查看>>
Javascript 与 SPA单页Web富应用
查看>>
SpringMVC之访问静态文件
查看>>
【java设计模式】之 模板方法(Template Method)模式
查看>>
小米手机会不会更好
查看>>
atitit.Sealink2000国际海运信息管理系统
查看>>
android面试总结01 activity生命周期
查看>>
Java 实现策略(Strategy)模式
查看>>
Ubuntu离线安装Sogou拼音(附老版本安装&输入法自启动)
查看>>
springmvc结合base64存取图片到mysql
查看>>
深度学习主机环境配置: Ubuntu16.04+GeForce GTX 1080+TensorFlow
查看>>
linux 抓包 tcpdump 简单应用
查看>>
mongodb官网文档阅读笔记:与写性能相关的几个因素
查看>>
PHP处理时间格式
查看>>
BestCoder Round #11 (Div. 2)
查看>>
JAVA入门[20]-Spring Data JPA简单示例
查看>>