Arc'GIS Python 度分秒转度
import arcpy as ARCPY import os import types import string spiltstr="," def convertPoints(): ARCPY.OverWriteOutput = True # Input point FC # Output FC # Feature Field # Sort Field # Close Line or Leave Open inPts = ARCPY.GetParameterAsText(0) xField=ARCPY.GetParameterAsText(1) yField=ARCPY.GetParameterAsText(2) outFeatures = ARCPY.GetParameterAsText(3) #输出文本 convertPointsToLine(inPts, outFeatures, xField,yField) #获得顺序 def getid(IDField,fieldList): i=0 #ARCPY.AddMessage("IDField="+IDField) for field in fieldList: #ARCPY.AddMessage("field="+field+":"+str(i)) if (field==IDField) or (field=='"'+IDField+'"') or (field=="'"+IDField+"'"): return i i=i+1 return -1 def dmstod(dms): #ARCPY.AddMessage("================================="+dms+"==============================") p = dms.find('.') if p<0: return str(dms) #ARCPY.AddMessage("p="+str(p)) d=string.atof(dms[0:p]) #ARCPY.AddMessage("d="+str(d)) if len(dms)>p+3: f=string.atof(dms[p+1:p+3]) #ARCPY.AddMessage("f="+str(f)) if len(dms)>p+5: s1=string.atof(dms[p+3:p+5]) #ARCPY.AddMessage("s1="+str(s1)) if dms[p+5:len(dms)]=="": s2=string.atof(dms[p+5:len(dms)]) else: s2=0 #ARCPY.AddMessage("s2="+str(s2)) else: s1=string.atof(dms[p+3:len(dms)]) s2=0 s=s1+s2/100 #ARCPY.AddMessage("s="+str(s)) #ARCPY.AddMessage("================================="+str(d)+":"+str(f)+":"+str(s)) else: f=string.atof(dms[p+1:len(dms)]) s=0 return str(d+f/60+s/3600); def convertPointsToLine(inPts, outFeatures, xField,yField): outfp = open(outFeatures, 'w') fp = open(inPts, 'r') s = fp.readline() s=s[0:len(s)-1] #删除回车 outfp.write(s+"\n") fieldList = s.split(spiltstr) fieldNameList = s.split(spiltstr) #ARCPY.AddMessage("=====闫磊 gisoracle编写:"+s) xID=getid(xField,fieldList) yID=getid(yField,fieldList) ARCPY.AddMessage("X="+str(xID)+",Y="+str(yID)) try: s = fp.readline() s=s[0:len(s)-1] #删除回车 while s: #ARCPY.AddMessage("=====闫磊 gisoracle编写"+s) fieldList = s.split(spiltstr) i=0 outs=""; for field in fieldList: if (i==xID) or (i==yID): outs=outs+dmstod(field) else: outs=outs+field outs=outs+"," i=i+1 outs=outs[0:len(outs)-1] outfp.write(outs+"\n") s = fp.readline() finally: fp.close() outfp.close() if __name__ == '__main__': convertPoints()