获取ARCGIS中polygon的中心点坐标

更新时间:2023-07-29 15:50:54 阅读: 评论:0

获取ARCGIS中polygon的中心点坐标(基于ArcGIS Desktop 9.3)
2009-05-17 11:08
大家好 我是GIS理想 这次我们研究下怎样获取ARCGIS中polygon的中心点坐标
其实这个问题很早就遇到了 也没来得及总结 群里也有友友们在询问 这里集中解决一下啦
不妥之处 还请大家批评指正~~~
下面是arcgis help里的讲解(这段是别人整的 貌似有点问题 我先贴下 后面我提供了解决办法):
Adding the x,y coordinates of the centroid of a polygon layer to a new field
1. Optionally, start an edit ssion in ArcMap. Calculating a field is faster outside of an edit ssion, but
you won't be able to undo the calculation.
2. Open the attribute table of the layer of the layer you want to edit.
3. Right-click the field heading for the X field (if there is no X field you can add a new field by clicking
the options button and lecting the new field
option).
4. Click Calculate Values.
5. Check Advanced.
6. Type the following VBA statement in the first text box.
Dim dblX As DoubleDim pArea As IAreaSet pArea = [Shape]dblX = pArea.Centroid.X
7. Type the variable dblX in the text box directly under the X field name.
8. Click OK.
You can repeat the same process for updating a field with the Y coordinates for the centroid point of each
polygon in the layer.
?
The property X returns a field type of double. For best results, your X field should also be a double field
type.
下面我简要的翻译下 不敢保证百分百正确哈 呵呵 其实这些小问题 大家也都能看得懂。。。。。。
在计算面的中心点坐标的时候 用的是字段计算器(当然了还有其他方法)
第一步 添加X Y字段 注意在对面图层添加字段的时候 图层不能是可编辑状态 也就是说Editor下面不要选择开始编辑状态即可
第二步 选择编辑 右键图层打开属性表
第三步 右键X字段表头 选择字段计算器
第四步 选中Advanced
第五步 编写VBA代码 :
Dim dblX As Double
Dim pArea As IArea
t pArea = [Shape]
dblX = pArea.Centroid.y
然后在下面一栏里直接填上“dblX” 点击OK 即可
为了取得更好的效果 建议在字段的声明类型与vba类型一致
下面我介绍另外一个方法 不用写VBA代码了 因为属性表里操作已经为大家准备好了
就是修改上面第三步的操作 不要选择字段计算器 选择计算几何要素(calculate Geometry)
然后在Property下拉列表框里选择相应的属性即可
显然这里默认的计算有面积 周长 中心坐标XY
其他操作就与上面的一样了 很明显这样的话不用书写VBA代码了 稍微简单一点 不过本人还是推荐大家用VBA 毕竟这样有助与
对AE的理解 对搞开发有帮助的 ~~~吼吼
对了 大家可以直接在HELP里查找 这里面对VBA代码说的也很详细的 我这里也贴出来一点供大家参考 不翻译了哈
很简单的
How to u Visual Basic code to calculate fields bad on area, length, perimeter, etc.
You can u Visual Basic code in the Advanced box in the Field Calculator dialog to calculate fields using
geometric measurements. Although the easiest way
to perform the calculations is to u the Calculate Geometry dialog described above, there may be situations
where you want to u Visual Basic code to
perform the calculations in the Field Calculator instead. The examples show how to do this.
1. The code examples return a value of type 'double', so u them to calculate either an existing field of
type 'double' or a new field of type 'double'
you've added to the table.
2. Check Advanced. You'll e two empty text entry boxes.
3. Enter one of the four line code examples into the topmost box, the one labeled 'Pre-Logic VBA Script
Code'. Tip: you can lect the code in this help
topic, right-click and choo Copy, and then paste it into the box.
To calculate area:
Dim Output as double
Dim pArea as Iarea
Set pArea = [shape]
Output = pArea.area
To calculate length or perimeter (depending on whether the features are lines or polygons):
Dim Output as double
Dim pCurve as ICurve
Set pCurve = [shape]
Output = pCurve.Length
To add the x coordinate of points:
Dim Output As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
Output = pPoint.X
To add the x coordinate of polygon centroids:
Dim Output As Double
Dim pArea As IArea
Set pArea = [Shape]
Output = pArea.Centroid.X
4. Type the variable Output into the cond text box. Do not enclo it in quotes or brackets.
5. Click OK
The units of the calculated values will be the units that your features are stored in, not the map units or
display units of the data frame you are currently
working with. So if your data is stored in feet, the calculated values will be in feet. If you want the
calculated data to be in different units than the
data's units, you could either add a conversion into the calculation expression, or (more simply) project your
data into a coordinate system that us the
units you want the values to be in, and then perform the calculatio
最后我贴出来一些DESKTOP里常用的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]
周记300字初中
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

本文发布于:2023-07-29 15:50:54,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/1122814.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:选择   字段   大家   代码   坐标   计算
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图