Arcgis100之后版本坐标值转换成shp图层教程_第1页
Arcgis100之后版本坐标值转换成shp图层教程_第2页
Arcgis100之后版本坐标值转换成shp图层教程_第3页
Arcgis100之后版本坐标值转换成shp图层教程_第4页
Arcgis100之后版本坐标值转换成shp图层教程_第5页
已阅读5页,还剩9页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、通过坐标数值生成点线面的shp图层Arcgis10.0之后版本虽然交9.3增加了很多功能,但是却不知何故少了一些常用的功能。本问主要就比较常用通过坐标数值生成点线面的shp图层做简单介绍。一、前期准备1.将附件CreateFeaturesFromTextFile文件复制到任何一个固定的位置。2.打开Arcgis,新建toolbox3.按图新建脚本工具 C:Program FilesArcGISDesktop10.1ArcToolboxStylesheetsgeoprocessing_help.xsl4.点击下一步,Script File选择刚才那个脚本文件“CreateFeaturesFrom

2、TextFile”5.设置参数其中,“坐标值规定“中的Default的值为12345678.12345“输出shp文件”中的Direction改为output“坐标系统“的type改为optional6.点击finished二、制作带有坐标的文本文件。1.这个文件第一行以d,x,m开头,分别表示点线面。2.接下几行是坐标值,以“编号(编号从0开始) X坐标 Y坐标”例如:0 40545654.256 532145697.3253.另起行以end结束。保存成txt格式的文件。三、生产shp图层1.打开刚才那个制作好的脚本工具CreateFeaturesFromTextFile2. 按照提示操作,

3、坐标系统可以不填3.点击Ok。完成注意事项:编写的txt文件的坐标必须按照顺序编写,否则图形会出现紊乱(点文件除外)。将一下文本粘贴到txt中,并保存成.py的文件。'''- Tool Name: CreateFeaturesFromTextFile Source Name: CreateFeaturesFromTextFile.py Version: ArcGIS 9.1 Author: Environmental Systems Research Institute Inc. Required Argumuments: An Input Text File cont

4、aining feature coordinates An Input Character designating the decimal separator used in the text file. An output feature class Optional Arguments: A spatial reference can be specified. This will be the spatial reference of the output fc. Description: Reads a text file with feature coordinates and cr

5、eates a feature class from the coordinates.-'''import string, os, sys, locale, arcgisscriptinggp = arcgisscripting.create()gp.overwriteoutput = 1msgErrorTooFewParams = "Not enough parameters provided."msgUnknownDataType = " is not a valid datatype. Datatype must be point,

6、multipoint, polyline or polygon."msgErrorCreatingPoint = "Error creating point %s on feature %s"# sets all the point propertiesdef createPoint(point, geometry): try: point.id = geometry0 point.x = geometry1 point.y = geometry2 # When empty values are written out from pyWriteGeomToText

7、File, they come as 1.#QNAN # Additionally, the user need not supply these values, so if they aren't in the list don't add them if len(geometry) > 3: if geometry3.lower().find("nan") = -1: point.z = geometry3 if len(geometry) > 4: if geometry4.lower().find("nan") = -

8、1: point.m = geometry4 return point except: raise Exception, msgErrorCreatingPointtry: # get the provided parameters inputTxtFile = open(gp.getparameterastext(0) fileSepChar = gp.getparameterastext(1) outputFC = gp.getparameterastext(2) # spatial reference is optional outputSR = gp.getparameterastex

9、t(3) # make sure the text type specified in the text file is valid. inDataT = inputTxtFile.readline().strip().lower() d = 'd':'point','ml':'multipoint','x':'polyline','m':'polygon' inDataType = dinDataT dataTypes = "point", &q

10、uot;multipoint", "polyline", "polygon" if inDataType.lower() not in dataTypes: msgUnknownDataType = "%s%s" % (inDataType, msgUnknownDataType) raise Exception, msgUnknownDataType # create the new featureclass gp.toolbox = "management" gp.CreateFeatureclass

11、(outputFC)0, (outputFC)1, inDataType, "#", "ENABLED", "ENABLED", outputSR) # create a new field to assure the id of each feature is preserved. idfield = "File_ID" gp.addfield(outputFC, idfield, "LONG") # get some information about the new featureclas

12、s for later use. outDesc = gp.describe(outputFC) shapefield = outDesc.ShapeFieldName # create the cursor and objects necessary for the geometry creation rows = gp.insertcursor(outputFC) pnt = gp.createobject("point") pntarray = gp.createobject("Array") partarray = gp.createobject

13、("Array") locale.setlocale(locale.LC_ALL, '') sepchar = locale.localeconv()'decimal_point' # loop through the text file. featid = 0 lineno = 1 for line in inputTxtFile.readlines(): lineno += 1 # create an array from each line in the input text file values = line.replace(&qu

14、ot;n", "").replace("r", "").replace(fileSepChar, sepchar).split(" ") # for a point feature class simply populate a point object and insert it. if inDataType = "point" and values0.lower() != "end": row = rows.newrow() pnt = createPoint(

15、pnt, values) row.SetValue(shapefield, pnt) row.SetValue(idfield, int(values0) rows.insertrow(row) # for a multipoint the text file is organized a bit differently. Groups of points must be inserted at the same time. elif inDataType = "multipoint": if len(values) > 2: pnt = createPoint(pn

16、t, values) pntarray.add(pnt) elif (len(values) = 2 and lineno != 2) or values0.lower() = "end": row = rows.newrow() row.SetValue(shapefield, pntarray) # store the feature id just in case there is an error. helps track down the offending line in the input text file. if values0.lower() != &q

17、uot;end": row.SetValue(idfield, featid) featid = int(values0) else: row.SetValue(idfield, featid) rows.insertrow(row) pntarray.removeall() elif (len(values) = 2 and lineno = 2): featid = int(values0) # for polygons and lines. polygons have a bit of logic for interior rings (donuts). # lines use

18、 the same logic as polygons (except for the interior rings) elif inDataType = "polygon" or inDataType = "polyline": #takes care of #adds the point array to the part array and then part array to the feature if (len(values) = 2 and float(values1) = 0 and lineno != 2) or values0.low

19、er() = "end": partarray.add(pntarray) row = rows.newrow() row.SetValue(shapefield, partarray) # store the feature id just in case there is an error. helps track down the offending line in the input text file. if values0.lower() != "end": row.SetValue(idfield, featid) featid = int

20、(values0) else: row.SetValue(idfield, featid) rows.insertrow(row) partarray.removeall() pntarray.removeall() #adds parts and/or interior rings to the part array elif (len(values) = 2 and float(values1) > 0) or values0.lower() = "interiorring": partarray.add(pntarray) pntarray.removeall() #add points to the point array elif len(values) > 2: pnt = createPoint(pnt, values) pntarray.add(pnt) elif (len(values) = 2

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论