插个广告,制作ArcGIS的Tool工具学习下面的教程就对了:
零基础学习Python制作ArcGIS自定义工具观看链接
《零基础学习Python制作ArcGIS自定义工具》课程简介
这一段是批量定义要素类(FeatureClasses)投影的ArcPy代码:
把要处理的要素类塞进一个文件夹(工作空间,workspace),然后将代码开头的路径换成这个“文件夹”的路径,处理完后再做其他处理(比如批量塞回原来文件夹,vba,python啥的代码、小工具处理即可)。
define coordinate system那里把坐标系信息改为自己需要定义的坐标系信息。不知道哪儿获取?先定义好一个Shpfile的投影信息,然后把它的.prj文件用记事本打开。
import arcpy # set environment workspace arcpy.env.workspace=r"C:UsersAdministratorDesktopArcCode新建文件夹" # 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:UsersAdministratorDesktop新建文件夹" # 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")