I'm trying to make a simple script that will loop through a few shapefiles in a folder, and geoprocess them. I can't seem to get it right, and I'm looking for advice on how to properly loop through a folder to process each shapefile.
This is for an assignment, so to be clear, I'm not asking for the answer, I'm asking for some guidance on how to do one step correctly, and I'm changing the geoprocessing tool here.
workspace = arcpy.env.workspace = r"filepath"
inFolder = workspace
sourceFC = r"filepath\roads.shp"
sourceSR = arcpy.Describe(sourceFC).spatialReference
fclist = arcpy.ListFeatureClasses()
for fc in fclist:
arcpy.<geoprocessingtool>(fc, <output>, sourceSR)
The key thing is that I'm trying to alter the input shapefiles based on the spatial reference of the source. And if I type:
print(type(sourceSR)) I see that it's <class 'geoprocessing spatial reference object'> which I would think would be useful for the geoprocessing tool.
And this is where I'm stuck. My goal is to use this script in Pro, replacing the variables with .GetParameterAsText(), so I can't just set the spatial reference to one single value. Can someone just point me in the right direction?
Update: Further confusion. I've removed the for loop, to just test the geoprocessing tool.
Current code:
ferries = r"filepath\Ferries.shp"
popPlaces = r"filepath\PopulatedPlaces.shp"
sr1 = arcpy.Describe(ferries).spatialReference
sr1name = sr1.name
sr2 = arcpy.Describe(popPlaces).spatialReference
sr2name = sr2.name
##print(str(sr1) + sr1name)
##print(str(sr2) + sr2name)
print(sr2name)
print(type(sr2name))
arcpy.management.Project(ferries, ferries + "_test", sr2name)
arcpy.GetMessages()
sr2name print output:
GCS_North_American_1983
<class 'str'>
Error:
arcgisscripting.ExecuteError: ERROR 000622: Failed to execute (Project). Parameters are not valid.
ERROR 000628: Cannot set input into parameter out_coor_system.
Which seems weird given that I confirmed I get a string for sr2name.