This question is back to basics; I looked around for an answer or a clue and I can't find what I'm looking for. I'm stuck.
I've got 3 variables with assigned string values (shapefile paths) and I am running them through a loop to check that their projected coordinate systems (PCS) are the same as my DEM's PCS. I want the code to check if they're the same, and if not, I want to project the file and reassign the projected file path to the original variable.
This is my code:
print("Verifying that coordinate systems are the same...") InSHP = [outline, DA, soil] DEMSR = arcpy.Describe(DEM).spatialReference.PCSCode for i, l in enumerate(InSHP): print InSHP[i] sr = arcpy.Describe(l).spatialReference.PCScode if sr != DEMSR: l = arcpy.Project_management(l, l[:-4] + "PRJ.shp", DEMSR) InSHP[i] = l print InSHP[i] print outline
print InSHP[i] produces the modified file path but print outline does not.
So, l = the projected shapefile but the l doesn't automatically connect the original variable name (outline) to the new path. I was initially expecting the program to automatically deduce that l = new path = outline, which was kind of stupid of me to think in retrospect. Now I explicitly know that l only refers to the entry in the list and is in no way connected to the original variable aside from having the same starting values. Is there a way to automate this sort of assignment or am I doomed to adding the following at the end of my code?
outline = InSHP DA = InSHP soil = InSHP
I guess it's not a big deal because there's only 3 of them but what if I need to check more inputs?
As a side question, this loop tells me that my soils file does not have a PCS, but when I look at the file properties in GIS or Catalog, it does have a PCS. Any idea why that's happening?
EDIT: Ugh. Adding those next 3 lines at the end didn't actually accomplish what I wanted it to accomplish. I'm so used to working with cursors and GIS tables that my plain list skills are lacking. :S
EDIT 2: Okay I got my list to update using the enumerate function and I updated my code accordingly. My original question(s) still stand, though. Is there a way to assign the new values to the original variables names without having to explicitly type the variable names again? I'm starting to think there isn't but I already posted this and I'm going to keep it here in case any other novice has this same problem.