ARCGIS属性表中字段的Calculate的妙用
[转]
在ARCGIS属性表中,一般不会包含实体几何信息,可以采取VBA进行计算。 下面是几个简单的代码(转载自集思学院) 特点: 1推荐给不会使用AO的朋友 2可以保存为CAL文件以备下次方便使用 使用方法 1打开属性表,选择计算的字段,右点选择Calculate Values; 2.选择“是”,进入Field Calculator; 2选择Advance选项; 3 在Pre-Logic VBA Script Code编辑框中输入VBA代码; 4在下面编辑框中输入赋值部分. 1--点坐标X VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPoint As IPoint Set pPoint = pGeo 赋值部分: pPoint.X 2--点坐标Y VBA部分: 同上 赋值部分: pPoint.Y 坐标值为文件存储的固有值,和是否使用On the Fly坐标表示无关。返回当前显示的坐标值参看8,9 3--多边形周长 VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPolygon As IPolygon Set pPolygon = pGeo 赋值部分: pPolygon.Length 4--多边形面积 VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPolygon As IPolygon Set pPolygon = pGeo Dim pArea As IArea Set pArea = pPolygon 赋值部分: pArea.Area 5--多边形重心X VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPolygon As IPolygon Set pPolygon = pGeo Dim pArea As IArea Set pArea = pPolygon Dim pPoint As IPoint Set pPoint = pArea.Centroid 赋值部分: pPoint.X 6--多边形重心Y VBA部分: 同上 赋值部分: pPoint.Y 7--Polyline长度 VBA部分: Dim pGeo As IGeometry Set pGeo = [Shape] Dim pPolyline As IPolyline Set pPolyline = pGeo Dim pCurve As IPolycurve Set pCurve = pPolyline 赋值部分: pCurve.Length 8--表示点坐标X VBA部分: Dim pDoc As IMxDocument Set pDoc = ThisDocument Dim pSpRef As ISpatialReference Set pSpRef = pDoc.FocusMap.SpatialReference Dim pClone As IClone Set pClone = [Shape] Dim pGeo As IGeometry Set pGeo = pClone.Clone Dim pPoint as IPoint Set pPoint = pGeo pGeo.Project pSpRef 赋值部分: pPoint.X 9--表示点坐标Y VBA部分: 同上 赋值部分: pPoint.Y