This is my first arcpy script attempting to use lists.
Input: 4 dif Excel files, each with a dif spatial reference
Output: 4 dif feature classes (in same geodatabase), each with original spatial reference converted to NAD 1983.
Issue: I can make 4 dif (but similar) scripts and have Python work for each input BUT is there a way to have Python go through my input list? The problem is that for the second step,
arcpy.MakeXYEventLayer_management, I don't know how to rotate through the spatial references depending on which Excel file I am using. Trying to use user suggested idea of sub-lists.
Updated Pasted script from Notepad:
# Import arcpy module import arcpy from arcpy import env # Set workspace env.workspace = r"E:\GIS\1.gdb\\" # Set the spatial reference sr1 = arcpy.SpatialReference("WGS 1984") sr2 = arcpy.SpatialReference("NAD 1927") sr3 = arcpy.SpatialReference("NAD 1983") # Set variables textPath1 = r"E:\GIS\Excel_files_by_datum\\" textPath2 = r"E:\GIS\2015Q1\\" textPath3 = r"E:\GIS\1.gdb\\" input = [["WGS84.xlsx", sr1],["NAD27.xlsx",sr2],["NAD83.xlsx",sr3],["Long_0_or_blank.xlsx",sr3]] out_Layer = "XY_Temp" Layername = input[0:5] #Run processes for ss in input: try: print "Converting Excel file to table" # Convert Excel to table Table1 = arcpy.ExcelToTable_conversion(textPath1+ ss,textPath3 + Layername) print "Making XY event layer" # This is to take the xy values of the table and transform to points # Description: Creates an XY layer and exports it to a layer file XY_event = arcpy.MakeXYEventLayer_management(Table1,"LONGITUDE","LATITUDE",out_Layer, ss) print "Copying features" # Description: Creates geodatabase feature class from the xy layer FeatureCopy = arcpy.CopyFeatures_management(XY_event, Layername + "_temp") print "Making feature layer" # Description: Transforms xy event layer into feature layer so I can select from it FeatureLayer = arcpy.MakeFeatureLayer_management(FeatureCopy, Layername + "_temp2") print "Converting from original datum to NAD83" # Converts file from input datum to NAD83 Transformed = arcpy.Project_management(FeatureLayer,textPath3 + Layername + "_to_NAD83",ss) print "Adding xy coordinates to feature layer table" # Adds new NAD83 xy coordinates to feature layer table arcpy.AddXY_management(Transformed) print "Deleting temp file" # Deletes temp FeatureCopy file arcpy.Delete_management(FeatureCopy) print "Deleting original table" # Deletes table from before the NAD 83 xy coordinates were added arcpy.Delete_management(Table1) print "Project complete" except: print arcpy.GetMessages()