import arcpy
import os
from arcpy import env
import math
env.overwriteOutput = True
shp_sheet = arcpy.GetParameterAsText(0)
sr = arcpy.Describe(shp_sheet).spatialReference
arcpy.AddMessage("sr.type:"+sr.type)
arcpy.AddMessage("sr.datumName:"+sr.datumName)
arcpy.AddMessage("sr.name:"+sr.name)
arcpy.AddMessage("sr.PCSCode:"+str(sr.PCSCode))
arcpy.AddMessage("sr.PCSName:"+sr.PCSName)
arcpy.AddMessage("sr.projectionName:"+sr.projectionName)
arcpy.AddMessage("sr.projectionCode:"+str(sr.projectionCode))
arcpy.AddMessage("sr.GCSCode:"+str(sr.GCSCode))
arcpy.AddMessage("sr.GCSName:"+sr.GCSName)
arcpy.AddMessage("sr.spheroidName:"+sr.spheroidName)
arcpy.AddMessage("sr.type:"+sr.type)
投影信息如下:
sr.type:Projected
sr.datumName:
sr.name:Xian_1980_3_Degree_GK_Zone_35
sr.PCSCode:2359
sr.PCSName:Xian_1980_3_Degree_GK_Zone_35
sr.projectionName:Transverse_Mercator
sr.projectionCode:43006
sr.GCSCode:0
sr.GCSName:
sr.spheroidName:
sr.type:Projected
函数:
def batch_shape_proj(shape_path, save_path, reference_file):
try:
#if not os.path.exists(save_path):
#os.mkdir(save_path)
for file_list in os.listdir(shape_path):
if file_list.endswith('.shp'):
print(file_list)
shape = shape_path + '/' + file_list # 待投影文件
outPath = save_path + "/" + file_list.split('.')[-2] + "_proj.shp"
coordinate_system = arcpy.Describe("F:\\00义务劳动\\定义投影\\os\\hhh.shp").spatialReference
print(coordinate_system.PCSCode)
arcpy.Project_management(shape, outPath, )
except arcpy.ExecuteError:
print(arcpy.GetMessages())
def batch_raster_proj(raster_path, save_path, reference_file):
try:
if not os.path.exists(save_path):
os.mkdir(save_path)
for file_list in os.listdir(raster_path):
if file_list.endswith('.tif'):
raster = raster_path + '/' + file_list # 待投影文件
outPath = save_path + "/" + file_list.split('.')[-2] + "_proj.tif"
coordinate_system = arcpy.Describe(reference_file).spatialReference
arcpy.ProjectRaster_management(raster, outPath, coordinate_system, "BILINEAR", "", "", "#", "#")
except arcpy.ExecuteError:
print(arcpy.GetMessages())