arcgis10的pythonarcpy使用指南

上传人:第*** 文档编号:38771994 上传时间:2018-05-07 格式:PDF 页数:10 大小:519KB
返回 下载 相关 举报
arcgis10的pythonarcpy使用指南_第1页
第1页 / 共10页
arcgis10的pythonarcpy使用指南_第2页
第2页 / 共10页
arcgis10的pythonarcpy使用指南_第3页
第3页 / 共10页
arcgis10的pythonarcpy使用指南_第4页
第4页 / 共10页
arcgis10的pythonarcpy使用指南_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《arcgis10的pythonarcpy使用指南》由会员分享,可在线阅读,更多相关《arcgis10的pythonarcpy使用指南(10页珍藏版)》请在金锄头文库上搜索。

1、属性 说明 ID 点的形状 ID X 点的水平坐标 Y 点的垂直坐标 Z 点的高程值 M 点的测量值 点属性 如果一个面包含多个洞,它将由多个环组成。针对 面返回的点对象数组将包含外部环及所 有内部环的点。外部环总是先返回,接着是内部环,其中以空点对象作为环之间的分隔符。 当脚本在地理数据库或 shapefile 中读取面的坐标时,它应包含用于处理内部环的逻辑(如 果脚本需要此信息) ;否则,将只读取外部环。 多部分 (multipart) 要素是由多个物理部分组成的, 但是只引用数据库中的一组属性。 例如, 在州行政区图层中,可将夏威夷州看作是一个多部分要素。虽然它是由许多岛屿组成的,但 在

2、数据库中仍将其记录为一个要素。 环是一个用于定义二维区域的闭合路径。 有效的环是由有效路径组成的, 因而环的起点和终 点具有相同的 x,y 坐标。顺时针环是外部环,逆时针环定义内部环。 以下示例将打印所有要素的坐标: 读取点几何读取点几何 点要素类上的搜索光标 import arcpy infc = arcpy.GetParameterAsText(0) # Identify the geometry field # desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor #

3、 rows = arcpy.SearchCursor(infc) # Enter for loop for each feature/row # for row in rows: # Create the geometry object feat # feat = row.getValue(shapefieldname) pnt = feat.getPart() # Print x,y coordinates of current point # print pnt.X, pnt.Y 对于上述要素类,脚本将返回以下信息: 2.0 4.0 8.0 10.0 7.0 5.0 读取多点几何读取多点几

4、何 多点要素类上的搜索光标 import arcpy infc = arcpy.GetParameterAsText(0) # Identify the geometry field # desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = arcpy.SearchCursor(infc) # Enter for loop for each feature/row # for row in rows: # Create the geometry objec

5、t # feat = row.getValue(shapefieldname) # Print the current multipoints ID # print “Feature %i:“ % row.getValue(desc.OIDFieldName) # For each point in the multipoint feature, # print the x,y coordinates for pnt in feat: print pnt.X, pnt.Y 对于上述要素类,脚本将返回以下信息: Feature 0: 3.0 8.0 4.0 4.0 6.0 6.0 Feature

6、 1: 5.0 9.0 8.0 10.0 Feature 2: 9.0 5.0 读取多义线或多边形几何读取多义线或多边形几何 面或线要素类上的搜索游标 import arcpy infc = arcpy.GetParameterAsText(0) # Identify the geometry field # desc = arcpy.Describe(infc) shapefieldname = desc.ShapeFieldName # Create search cursor # rows = arcpy.SearchCursor(infc) # Enter for loop for e

7、ach feature/row # for row in rows: # Create the geometry object # feat = row.getValue(shapefieldname) # Print the current multipoints ID # print “Feature %i:“ % row.getValue(desc.OIDFieldName) partnum = 0 # Step through each part of the feature # for part in feat: # Print the part number # print “Pa

8、rt %i:“ % partnum # Step through each vertex in the feature # for pnt in feat.getPart(partnum): if pnt: # Print x,y coordinates of current point # print pnt.X, pnt.Y else: # If pnt is None, this represents an interior ring # print “Interior Ring:“ partnum += 1 对于上述要素类,脚本将返回以下信息。要素 0 是单部分面,要素 1 是两部分面

9、,而要素 2 是带有内部环的单部分面。 Feature 0: Part 0: 3.0 8.0 1.0 8.0 2.0 10.0 3.0 8.0 Feature 1: Part 0: 5.0 3.0 3.0 3.0 3.0 5.0 5.0 3.0 Part 1: 7.0 5.0 5.0 5.0 5.0 7.0 7.0 5.0 Feature 2: Part 0: 9.0 11.0 9.0 8.0 6.0 8.0 6.0 11.0 9.0 11.0 Interior Ring: 7.0 10.0 7.0 9.0 8.0 9.0 8.0 10.0 7.0 10.0 写入几何写入几何 使用插入和更新游

10、标, 脚本可以在要素类中创建新要素或更新现有要素。 脚本可以通过创建 点对象、 填充要素属性和将要素放入数组中来定义要素。 该数组随后即可用于设置要素的几 何。 单个几何部分可以由点数组定义, 因此可以从多个点数组创建多部分 (multipart) 要素。 下面就是一个文件示例, 该示例将由随后的脚本进行处理。 它包含一个点 ID 及 x 坐标和 y 坐标。 1;-61845879.0968;45047635.4861 1;-3976119.96791;46073695.0451 1;1154177.8272;-25134838.3511 1;-62051091.0086;-26160897.

11、9101 2;17365918.8598;44431999.7507 2;39939229.1582;45252847.3979 2;41170500.6291;27194199.1591 2;17981554.5952;27809834.8945 3;15519011.6535;11598093.8619 3;52046731.9547;13034577.2446 3;52867579.6019;-16105514.2317 3;17160706.948;-16515938.0553 以下示例显示如何读取包含一系列线性坐标的文本文件(如上所示) ,并使用它们创建新要 素类。 # Create

12、 a new line feature class using a text file of coordinates. # Each coordinate entry is semicolon delimited in the format of ID;X;Y # Import ArcPy and other required modules # import arcpy from arcpy import env import fileinput import string import os env.overwriteOutput = True # Get the coordinate A

13、SCII file # infile = arcpy.GetParameterAsText(0) # Get the output feature class # fcname = arcpy.GetParameterAsText(1) # Get the template feature class # template = arcpy.GetParameterAsText(2) try: # Create the output feature class # arcpy.CreateFeatureclass_management(os.path.dirname(fcname), os.pa

14、th.basename(fcname), “Polyline“, template) # Open an insert cursor for the new feature class # cur = arcpy.InsertCursor(fcname) # Create an array and point object needed to create features # lineArray = arcpy.Array() pnt = arcpy.Point() # Initialize a variable for keeping track of a features ID. # I

15、D = -1 for line in fileinput.input(infile): # Open the input file # set the points ID, X and Y properties # pnt.ID, pnt.X, pnt.Y = string.split(line,“;“) print pnt.ID, pnt.X, pnt.Y if ID = -1: ID = pnt.ID # Add the point to the features array of points # If the ID has changed, create a new feature #

16、 if ID != pnt.ID: # Create a new row or feature, in the feature class # feat = cur.newRow() # Set the geometry of the new feature to the array of points # feat.shape = lineArray # Insert the feature # cur.insertRow(feat) lineArray.removeAll() lineArray.add(pnt) ID = pnt.ID # Add the last feature # feat = cur.newRow() feat.shape = lineArray cur.insertRow(feat)

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 中学教育 > 其它中学文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号