# -*- coding:UTF-8 -*-
import arcpy, os
import ConvertLag_Lat as CVLL
import sys
reload(sys)
sys.setdefaultencoding('utf8')
#輸入工作空間
in_features = arcpy.GetParameterAsText(0)
#輸出的空間坐標(biāo)系
outCSStr=arcpy.GetParameterAsText(1)
#輸出工作空間
output_folder = arcpy.GetParameterAsText(2)
outCS=arcpy.SpatialReference(4326)
arcpy.BatchProject_management(in_features, output_folder, outCS)
arcpy.env.workspace = output_folder
transType=0
if(outCSStr=='wgs84'):
arcpy.AddMessage("transform succeed")
elif(outCSStr=='gaode'):
arcpy.AddMessage("target coords gaode")
transType='3'
elif(outCSStr=='baidu'):
transType='6'
arcpy.AddMessage("target coords baidu")
arcpy.AddMessage("start transforming......")
featureclasses = arcpy.ListFeatureClasses()
for fc in featureclasses:
cur= arcpy.UpdateCursor(fc)
SR= arcpy.Describe(fc).spatialReference
des = arcpy.Describe(fc)
arcpy.RepairGeometry_management(fc)
fc_count=int(arcpy.GetCount_management(fc).getOutput(0))
arcpy.AddMessage(fc_count)
arcpy.SetProgressor("step", "transform " fc,0, fc_count, 1)
if des.shapeType.upper()=='POINT':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetPoint(geom,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
elif des.shapeType.upper()=='POLYLINE':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetLine(geom,SR,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
elif des.shapeType.upper()=='POLYGON':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetPolygon(geom,SR,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
arcpy.AddMessage(fc " transform finished")
2、百度高德與WGS84互轉(zhuǎn)
import arcpy, os
import ConvertLag_Lat as CVLL
import sys
reload(sys)
sys.setdefaultencoding('utf8')
#input path of folder where all shapefiles reside in
in_fold = arcpy.GetParameterAsText(0)
output_folder = arcpy.GetParameterAsText(1)
outCSStr= arcpy.GetParameterAsText(2)
outCS=arcpy.SpatialReference(4326)
arcpy.env.workspace = in_fold
#copy data
featureclasses = arcpy.ListFeatureClasses()
for fc in featureclasses:
arcpy.Copy_management(fc,output_folder "\\" fc)
arcpy.env.workspace=output_folder
transType='0'
if(outCSStr=='mars2baidu'):
transType='1'
elif(outCSStr=='baidu2mars'):
transType='2'
elif(outCSStr=='mars2baidu'):
transType='3'
elif(outCSStr=='mars2wgs84'):
transType='4'
elif(outCSStr=='baidu2wgs'):
transType='5'
elif(outCSStr=='wgs2baidu'):
transType='6'
arcpy.AddMessage("transfor type is " str(transType))
featureclasses = arcpy.ListFeatureClasses()
for fc in featureclasses:
cur= arcpy.UpdateCursor(fc)
SR= arcpy.SpatialReference(4326)
des = arcpy.Describe(fc)
arcpy.RepairGeometry_management(fc)
fc_count=int(arcpy.GetCount_management(fc).getOutput(0))
arcpy.SetProgressor("step", "transform " fc,0, fc_count, 1)
if des.shapeType.upper()=='POINT':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetPoint(geom,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
elif des.shapeType.upper()=='POLYLINE':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetLine(geom,SR,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
elif des.shapeType.upper()=='POLYGON':
for r in cur:
geom = r.getValue("SHAPE")
r.setValue("SHAPE",CVLL.offsetPolygon(geom,SR,transType))
cur.updateRow(r)
arcpy.SetProgressorPosition()
del r,cur
arcpy.AddMessage(fc " transform finished")