I am getting stuck with a task that is slightly different from the posts I found so far on this same website.
Assumption: all layers have a defined coordinate system
Problem: I would like to automate a python script (using arcGIS 10.1 but 10.0 is fine as well) that projects a list of vector layers (some of which with different coordinate systems) to a common coordinate system, given by a target vector layer. The main issue I would need help with is how to automate something this:
1) check if the coordinate system of the current vector layer is the same as the target layer
2) if not, check if the datum is the same
3) if it's the same datum, then project the current layer to the target layer without any datum transformation
4) if, instead, they do not have the same datum, pick a pre-defined transformation and include that in the projection function
Any help would be much appreciated! thanks!
Here is my sample code:
import arcpy from arcpy import env arcpy.gp.overwriteOutput = True env.workspace = 'C:\\Temp' Target_lyr = 'water_Broward.shp' try: desc = arcpy.Describe(Target_lyr) TargetSR = desc.spatialReference for inputFC in arcpy.ListFeatureClasses('*'): if inputFC != Target_lyr: inputFC_SR = arcpy.Describe(inputFC).spatialReference if inputFC_SR.Name == TargetSR.Name: continue else: #check if current layer and target layer are the same type #thus if they are both 'projected' or 'geographic' if inputFC_SR.type == TargetSR.type: #HELP STARTING FROM HERE... #Check if both have same datum.. #if they ARE, then #outFC = inputFC + '_prj.shp' #arcpy.Project_management(inputFC, outFC, TargetCS) #if datum is NOT the same use #transformation = for example "WGS_1972_To_WGS_1984_1" #arcpy.Project_management(inputFC, outFC, TargetCS,transformation) #if current layer and target layer are NOT same kind else: #HELP #repeat as above same steps as above to check the datum except: print arcpy.GetMessages()