So how to batch define the projection for a folder full of shapefiles is the problem at hand. For those who can't wait I posted the code here first and the explanation comes after.
# Name: DefineProjection.py # Description: Records the coordinate system information for the specified input dataset or feature class # Author: ESRI # import system modules import arcpy from arcpy import env import os # set workspace environment where the shapefiles are located env.workspace = "C:\\BaseFolderName\\FolderOfShapefiles"
# creates a list of feature classes or shapefiles in the current workspace
fcs = arcpy.ListFeatureClasses('*') # set local variables try: for file in fcs: inData = file coordinateSystem = "PROJCS[\"MGI_Austria_GK_East\",GEOGCS[\"GCS_MGI\",DATUM[\"D_MGI\",SPHEROID[\"Bessel_1841\",6377397.155,299.1528128]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",0.0],PARAMETER[\"False_Northing\",-5000000.0],PARAMETER[\"Central_Meridian\",16.33333333333333],PARAMETER[\"Scale_Factor\",1.0],PARAMETER[\"Latitude_Of_Origin\",0.0],UNIT[\"Meter\",1.0],AUTHORITY[\"EPSG\",31256]]" arcpy.DefineProjection_management(inData, coordinateSystem) except arcpy.ExecuteError: print arcpy.GetMessages(2) arcpy.AddError(arcpy.GetMessages(2)) except Exception as e: print e.args arcpy.AddError(e.args)
First you need to of course change the input folder to your folder where you have the shapefiles you wish to define the projection for.
Second you need to specify the coordinate system you want to set for all your shapefiles. Here you need to escape out the " otherwise the code will crash out. To get this definition just go to your hard drive where ArcGIS is installed and find the folder of the projections and open your projection in a text editor such as notepad++ on Windows or vi on a Linux machine and select all in the text file and copy paste into your python script.
Thats that now just go ahead and run the script.