我是靠谱客的博主 魁梧乌冬面,这篇文章主要介绍ArcGIS中使用python实现:将面要素类的所有节点信息存储在属性表的字段中,现在分享给大家,希望可以做个参考。

总结两种方法实现:将面要素类的所有节点信息,按节点顺序存储在属性表的字段中

一种是使用字段计算器的python代码块,在网上找到了实现代码,但在运行中报如下错误,最后确定原因在于所添加的字段长度不够导致的:


首先需要通过add field添加一个string类型的字段,注意:字段长度必须足够大(如果面的节点很多),修改如下截图中Length值。


然后右键字段打开字段计算器,勾选显示代码块,如下截图所示:


代码块内容如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def MySub(feat): partnum = 0 #multipart feature partcount = feat.partCount pntcount = 0 str='' # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) while partnum < partcount: part = feat.getPart(partnum) pnt = part.next() # Enter while loop for each vertex # str=str+"[" while pnt: pntcount += 1 px='%f' %pnt.X py='%f' %pnt.Y str=str+px+","+py +";" #print px, py pnt = part.next() # If pnt is null, either the part is finished or there is an # interior ring if not pnt: str=str[:-1] str=str+"]" pnt = part.next() partnum += 1 return str

第二种方法是使用py脚本文件处理,代码块调试起来很费劲,所以在排查错误的时候使用py更方便,代码如下:

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# -*- coding: utf-8 -*- import arcpy def MySub(feat): partnum = 0 #multipart feature partcount = feat.partCount pntcount = 0 str='' # Enter while loop for each part in the feature (if a singlepart feature # this will occur only once) while partnum < partcount: part = feat.getPart(partnum) pnt = part.next() # Enter while loop for each vertex str=str+"[" while pnt: pntcount += 1 px='%f' %pnt.X py='%f' %pnt.Y str=str+px+","+py +";" #print px, py pnt = part.next() # If pnt is null, either the part is finished or there is an # interior ring if not pnt: str=str[:-1] str=str+"]" pnt = part.next() partnum += 1 return str arcpy.env.workspace = "E:/ArcTutor/Editing/Zion.gdb" # Create the update cursor cursor = arcpy.UpdateCursor("Park_boundary") for row in cursor: mystr= MySub(row.shape) row.setValue("aaa", mystr) cursor.updateRow(row) # Delete cursor and row objects del cursor, row



最后

以上就是魁梧乌冬面最近收集整理的关于ArcGIS中使用python实现:将面要素类的所有节点信息存储在属性表的字段中的全部内容,更多相关ArcGIS中使用python实现:将面要素类内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(72)

评论列表共有 0 条评论

立即
投稿
返回
顶部