Arcgis100之后版本坐标值转换成shp图层教程Word文档下载推荐.docx
《Arcgis100之后版本坐标值转换成shp图层教程Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Arcgis100之后版本坐标值转换成shp图层教程Word文档下载推荐.docx(11页珍藏版)》请在冰点文库上搜索。
例如:
040545654.256532145697.325
3.另起行以end结束。
保存成txt格式的文件。
三、生产shp图层
1.打开刚才那个制作好的脚本工具CreateFeaturesFromTextFile
2.按照提示操作,坐标系统可以不填
3.点击Ok。
完成
注意事项:
编写的txt文件的坐标必须按照顺序编写,否则图形会出现紊乱(点文件除外)。
将一下文本粘贴到txt中,并保存成.py的文件。
'
----------------------------------------------------------------------------------
ToolName:
CreateFeaturesFromTextFile
SourceName:
CreateFeaturesFromTextFile.py
Version:
ArcGIS9.1
Author:
EnvironmentalSystemsResearchInstituteInc.
RequiredArgumuments:
AnInputTextFilecontainingfeaturecoordinates
AnInputCharacterdesignatingthedecimalseparatorusedinthetextfile.
Anoutputfeatureclass
OptionalArguments:
Aspatialreferencecanbespecified.Thiswillbethe
spatialreferenceoftheoutputfc.
Description:
Readsatextfilewithfeaturecoordinatesandcreatesafeatureclass
fromthecoordinates.
----------------------------------------------------------------------------------'
importstring,os,sys,locale,arcgisscripting
gp=arcgisscripting.create()
gp.overwriteoutput=1
msgErrorTooFewParams="
Notenoughparametersprovided."
msgUnknownDataType="
isnotavaliddatatype.Datatypemustbepoint,multipoint,polylineorpolygon."
msgErrorCreatingPoint="
Errorcreatingpoint%sonfeature%s"
#setsallthepointproperties
defcreatePoint(point,geometry):
try:
point.id=geometry[0]
point.x=geometry[1]
point.y=geometry[2]
#WhenemptyvaluesarewrittenoutfrompyWriteGeomToTextFile,theycomeas1.#QNAN
#Additionally,theuserneednotsupplythesevalues,soiftheyaren'
tinthelistdon'
taddthem
iflen(geometry)>
3:
ifgeometry[3].lower().find("
nan"
)==-1:
point.z=geometry[3]
4:
ifgeometry[4].lower().find("
point.m=geometry[4]
returnpoint
except:
raiseException,msgErrorCreatingPoint
try:
#gettheprovidedparameters
inputTxtFile=open(gp.getparameterastext(0))
fileSepChar=gp.getparameterastext
(1)
outputFC=gp.getparameterastext
(2)
#spatialreferenceisoptional
outputSR=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
#createthenewfeatureclass
gp.toolbox="
management"
gp.CreateFeatureclass(os.path.split(outputFC)[0],os.path.split(outputFC)[1],inDataType,"
#"
ENABLED"
outputSR)
#createanewfieldtoassuretheidofeachfeatureispreserved.
idfield="
File_ID"
gp.addfield(outputFC,idfield,"
LONG"
)
#getsomeinformationaboutthenewfeatureclassforlateruse.
outDesc=gp.describe(outputFC)
shapefield=outDesc.ShapeFieldName
#createthecursorandobjectsnecessaryforthegeometrycreation
rows=gp.insertcursor(outputFC)
pnt=gp.createobject("
pntarray=gp.createobject("
Array"
partarray=gp.createobject("
locale.setlocale(locale.LC_ALL,'
sepchar=locale.localeconv()['
decimal_point'
#loopthroughthetextfile.
featid=0
lineno=1
forlineininputTxtFile.readlines():
lineno+=1
#createanarrayfromeachlineintheinputtextfile
values=line.replace("
\n"
"
).replace("
\r"
).replace(fileSepChar,sepchar).split("
"
#forapointfeatureclasssimplypopulateapointobjectandinsertit.
ifinDataType=="
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=="
iflen(values)>
2:
pntarray.add(pnt)
elif(len(values)==2andlineno!
=2)orvalues[0].lower()=="
row.SetValue(shapefield,pntarray)
#storethefeatureidjustincasethereisanerror.helpstrackdowntheoffendinglineintheinputtextfile.
ifvalues[0].lower()!
row.SetValue(idfield,featid)
featid=int(values[0])
else:
pntarray.removeall()
elif(len(values)==2andlineno==2):
#forpolygonsandlines.polygonshaveabitoflogicforinteriorrings(donuts).
#linesusethesamelogicaspolygons(exceptfortheinteriorrings)
orinDataType=="
#takescareof
#addsthepointarraytothepartarrayandthenpartarraytothefeature
if(len(values)==2andfloat(values[1])==0andlineno!
partarray.add(pntarray)
row.SetValue(shapefield,partarray)
partarray.removeall()
#addspartsand/orinteriorringstothepartarray
elif(len(values)==2andfloat(values[1])>
0)orvalues[0].lower()=="
interiorring"
#addpointstothepointarray
eliflen(values)>
inputTxtFile.close()
delrows
delrow
exceptException,ErrorDesc:
#handletheerrorshere.ifthepointcreationfails,wanttokeeptrackofwhichpointfailed(easiertofixthe
#textfileifwedo)
ifErrorDesc[0]==msgErrorCreatingPoint:
ifinDataType.lower()=="
msgErrorCreatingPoint=msgErrorCreatingPoint%(values[0],values[0])
msgErrorCreatingPoint=msgErrorCreatingPoint%(values[0],featid)
gp.AddError(msgErrorCreatingPoint)
elifErrorDesc[0]!
gp.AddError(str(ErrorDesc))
gp.AddError(gp.getmessages
(2))
#makesuretocloseupthefileinputnomatterwhat.
ifinputTxtFile: