




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
通过坐标数值生成点线面的shp图层Arcgis10.0之后版本虽然交9.3增加了很多功能,但是却不知何故少了一些常用的功能。本问主要就比拟常用通过坐标数值生成点线面的shp图层做简单介绍。一、前期准备1.将附件CreateFeaturesFromTextFile文件复制到任何一个固定的位置。2.翻开Arcgis,新建toolbox3.按图新建脚本工具C:\ProgramFiles\ArcGIS\Desktop10.1\ArcToolbox\Stylesheets\geoprocessing_help.xsl4.点击下一步,ScriptFile选择刚刚那个脚本文件“CreateFeaturesFromTextFile〞5.设置参数其中,“坐标值规定“中的Default的值为12345678.12345“输出shp文件〞中的Direction改为output“坐标系统“的type改为optional6.点击finished二、制作带有坐标的文本文件。1.这个文件第一行以d,x,m开头,分别表示点线面。2.接下几行是坐标值,以“编号〔编号从0开始〕X坐标Y坐标〞例如:040545654.256532145697.3253.另起行以end结束。保存成txt格式的文件。三、生产shp图层1.翻开刚刚那个制作好的脚本工具CreateFeaturesFromTextFile2.按照提示操作,坐标系统可以不填3.点击Ok。完成考前须知:编写的txt文件的坐标必须按照顺序编写,否那么图形会出现紊乱〔点文件除外〕。将一下文本粘贴到txt中,并保存成.py的文件。'''----------------------------------------------------------------------------------ToolName:CreateFeaturesFromTextFileSourceName:CreateFeaturesFromTextFile.pyVersion:ArcGIS9.1Author:EnvironmentalSystemsResearchInstituteInc.RequiredArgumuments:AnInputTextFilecontainingfeaturecoordinatesAnInputCharacterdesignatingthedecimalseparatorusedinthetextfile.AnoutputfeatureclassOptionalArguments:Aspatialreferencecanbespecified.Thiswillbethespatialreferenceoftheoutputfc.Description:Readsatextfilewithfeaturecoordinatesandcreatesafeatureclassfromthecoordinates.----------------------------------------------------------------------------------'''importstring,os,sys,locale,arcgisscriptinggp=arcgisscripting.create()gp.overwriteoutput=1msgErrorTooFewParams="Notenoughparametersprovided."msgUnknownDataType="isnotavaliddatatype.Datatypemustbepoint,multipoint,polylineorpolygon."msgErrorCreatingPoint="Errorcreatingpoint%sonfeature%s"#setsallthepointpropertiesdefcreatePoint(point,geometry):try:point.id=geometry[0]point.x=geometry[1]point.y=geometry[2]#WhenemptyvaluesarewrittenoutfrompyWriteGeomToTextFile,theycomeas1.#QNAN#Additionally,theuserneednotsupplythesevalues,soiftheyaren'tinthelistdon'taddthemiflen(geometry)>3:ifgeometry[3].lower().find("nan")==-1:point.z=geometry[3]iflen(geometry)>4:ifgeometry[4].lower().find("nan")==-1:point.m=geometry[4]returnpointexcept:raiseException,msgErrorCreatingPointtry:#gettheprovidedparametersinputTxtFile=open(gp.getparameterastext(0))fileSepChar=gp.getparameterastext(1)outputFC=gp.getparameterastext(2)#spatialreferenceisoptionaloutputSR=gp.getparameterastext(3)#makesurethetexttypespecifiedinthetextfileisvalid.inDataT=inputTxtFile.readline().strip().lower()d={'d':'point','ml':'multipoint','x':'polyline','m':'polygon'}inDataType=d[inDataT]dataTypes=["point","multipoint","polyline","polygon"]ifinDataType.lower()notindataTypes:msgUnknownDataType="%s%s"%(inDataType,msgUnknownDataType)raiseException,msgUnknownDataType#createthenewfeatureclassgp.toolbox="management"gp.CreateFeatureclass((outputFC)[0],(outputFC)[1],inDataType,"#","ENABLED","ENABLED",outputSR)#createanewfieldtoassuretheidofeachfeatureispreserved.idfield="File_ID"gp.addfield(outputFC,idfield,"LONG")#getsomeinformationaboutthenewfeatureclassforlateruse.outDesc=gp.describe(outputFC)shapefield=outDesc.ShapeFieldName#createthecursorandobjectsnecessaryforthegeometrycreationrows=gp.insertcursor(outputFC)pnt=gp.createobject("point")pntarray=gp.createobject("Array")partarray=gp.createobject("Array")locale.setlocale(locale.LC_ALL,'')sepchar=locale.localeconv()['decimal_point']#loopthroughthetextfile.featid=0lineno=1forlineininputTxtFile.readlines():lineno+=1#createanarrayfromeachlineintheinputtextfilevalues=line.replace("\n","").replace("\r","").replace(fileSepChar,sepchar).split("")#forapointfeatureclasssimplypopulateapointobjectandinsertit.ifinDataType=="point"andvalues[0].lower()!="end":row=rows.newrow()pnt=createPoint(pnt,values)row.SetValue(shapefield,pnt)row.SetValue(idfield,int(values[0]))rows.insertrow(row)#foramultipointthetextfileisorganizedabitdifferently.Groupsofpointsmustbeinsertedatthesametime.elifinDataType=="multipoint":iflen(values)>2:pnt=createPoint(pnt,values)pntarray.add(pnt)elif(len(values)==2andlineno!=2)orvalues[0].lower()=="end":row=rows.newrow()row.SetValue(shapefield,pntarray)#storethefeatureidjustincasethereisanerror.helpstrackdowntheoffendinglineintheinputtextfile.ifvalues[0].lower()!="end":row.SetValue(idfield,featid)featid=int(values[0])else:row.SetValue(idfield,featid)rows.insertrow(row)pntarray.removeall()elif(len(values)==2andlineno==2):featid=int(values[0])#forpolygonsandlines.polygonshaveabitoflogicforinteriorrings(donuts).#linesusethesamelogicaspolygons(exceptfortheinteriorrings)elifinDataType=="polygon"orinDataType=="polyline":#takescareof#addsthepointarraytothepartarrayandthenpartarraytothefeatureif(len(values)==2andfloat(values[1])==0andlineno!=2)orvalues[0].lower()=="end":partarray.add(pntarray)row=rows.newrow()row.SetValue(shapefield,partarray)#storethefeatureidjustincasethereisanerror.helpstrackdowntheoffendinglineintheinputtextfile.ifvalues[0].lower()!="end":row.SetValue(idfield,featid)featid=int(values[0])else:row.SetValue(idfield,featid)rows.insertrow(row)partarray.removeall()pntarray.removeall()#addspartsand/orinteriorringstothepartarrayelif(len(values)==2andfloat(values[1])>0)orvalues[0].lower()=="interiorring":partarray.add(pntarray)pntarray.removeall()#addpointstothepointarrayeliflen(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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- HY/T 0388-2023海洋灾害基本术语
- GM/T 0010-2023SM2密码算法加密签名消息语法规范
- GB/T 43267-2023道路车辆预期功能安全
- DZ/T 0135-1994地质仪器产品标准编写规定
- CJ/T 50-2008瓶装液化石油气调压器
- CJ/T 349-2010数字社区管理与服务网格划分与编码规则
- CJ/T 166-2006建设事业集成电路(IC)卡应用技术
- CJ/T 115-2017动物园安全标志
- 项目管理中的创新思维试题及答案
- 高效复习2025年系统分析师考试试题及答案
- 心脏彩超解读完整版课件
- 前道设备简介及设计方法
- 门窗安装质量验收标准
- 医学高级职称评审答辩报告PPT模板
- 图解通信施工安全隐患
- 文言文常考实词
- 宝安区义务教育入学申请·集体宿舍证明
- 《园艺植物育种学》试题库参考答案
- 急诊科护理查房中毒-PPT课件
- 宁波市建设工程资料统一用表(2022版)1 通用分册
- 11-059 职业技能鉴定指导书 继电保护(第二版)(11-059职业技能鉴定指导书职业标准试题库)
评论
0/150
提交评论