这一段是批量定义要素类(FeatureClasses)投影的ArcPy代码:
把要处理的要素类塞进一个文件夹(工作空间,workspace),然后将代码开头的路径换成这个“文件夹”的路径,处理完后再做其他处理(比如批量塞回原来文件夹,vba,python啥的代码、小工具处理即可)。
或者,把要处理的要素类都加载到ArcMap工作空间,然后把下面代码set environment workspace(设置工作空间)的这一行代码干掉,代码执行的默认工作空间就是当前ArcMap的工作空间了。
define coordinate system那里把坐标系信息改为自己需要定义的坐标系信息。不知道哪儿获取?先定义好一个Shpfile的投影信息,然后把它的.prj文件用记事本打开。
import arcpy # set environment workspace arcpy.env.workspace=r"C:\Users\Administrator\Desktop\ArcCode\新建文件夹" # get files clses = arcpy.ListFeatureClasses() # define coordinate system Coordinate_System = "PROJCS[‘CGCS2000_3_Degree_GK_CM_114E‘,GEOGCS[‘GCS_China_Geodetic_Coordinate_System_2000‘,DATUM[‘D_China_2000‘,SPHEROID[‘CGCS2000‘,6378137.0,298.257222101]],PRIMEM[‘Greenwich‘,0.0],UNIT[‘Degree‘,0.0174532925199433]],PROJECTION[‘Gauss_Kruger‘],PARAMETER[‘False_Easting‘,500000.0],PARAMETER[‘False_Northing‘,0.0],PARAMETER[‘Central_Meridian‘,114.0],PARAMETER[‘Scale_Factor‘,1.0],PARAMETER[‘Latitude_Of_Origin‘,0.0],UNIT[‘Meter‘,1.0]]" # code source: https://www.cnblogs.com/yzhyingcool/ QQ:975601416 for cls in clses: print str(cls) arcpy.DefineProjection_management(cls, Coordinate_System) print("OK")
这是一段批量定义影像投影的Arcpy代码:
影像图片格式:代码中定义为tif格式,其他格式自行更改。
基本设置如上,不复述。
import arcpy # set environment workspace arcpy.env.workspace=r"C:\Users\Administrator\Desktop\新建文件夹" # get files rasters = arcpy.ListRasters("*", "tif") # define coordinate system Coordinate_System = "PROJCS[‘CGCS2000_3_Degree_GK_CM_114E‘,GEOGCS[‘GCS_China_Geodetic_Coordinate_System_2000‘,DATUM[‘D_China_2000‘,SPHEROID[‘CGCS2000‘,6378137.0,298.257222101]],PRIMEM[‘Greenwich‘,0.0],UNIT[‘Degree‘,0.0174532925199433]],PROJECTION[‘Gauss_Kruger‘],PARAMETER[‘False_Easting‘,500000.0],PARAMETER[‘False_Northing‘,0.0],PARAMETER[‘Central_Meridian‘,114.0],PARAMETER[‘Scale_Factor‘,1.0],PARAMETER[‘Latitude_Of_Origin‘,0.0],UNIT[‘Meter‘,1.0]]" #code source: https://www.cnblogs.com/yzhyingcool/ QQ:975601416 for ras in rasters: print str(ras) arcpy.DefineProjection_management(ras, Coordinate_System) print("OK")
原文地址:https://www.cnblogs.com/yzhyingcool/p/10274153.html
时间: 2024-10-09 14:14:34