import arcpy
import os

fc = []

walk = arcpy.da.Walk('C:/Wiley/P1/gis/OSM.gdb')

outdir = "C:/Wiley/P1/gis/HK80.gdb/osm"

for root, dirs, datasets in walk:
    for ds in datasets:
        fc.append(os.path.join(root, ds))

if fc:
    output = os.path.join(outdir, os.path.basename(ds) + "_project")    
    hkfc = "C:\Wiley\P1\gis\HK80.gdb\Building_merge_dissolved"
    # Describe the feature class and get its spatial reference
    desc = arcpy.Describe(hkfc)
    spatialRef = desc.spatialReference

    out_coordinate_system = arcpy.SpatialReference('spatialRef.name')

    arcpy.Project_management(fc, output, out_coordinate_system) 

I am sure with a trained eye you guys know what to do. It came back to me with the following error:

Runtime error Traceback (most recent call last): File "", line 21, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects\mixins.py", line 962, in init self._arc_object.createFromFile(item) RuntimeError: ERROR 999999: Error executing function.

What went wrong?


I assume you want to loop through all the feature classes you're collecting, so it should be:

# we only need to do this once
hkfc = "C:\Wiley\P1\gis\HK80.gdb\Building_merge_dissolved"
desc = arcpy.Describe(hkfc)
spatialRef = desc.spatialReference

for input in fc:
    output = os.path.join(outdir, os.path.basename(input) + "_project")    
    arcpy.Project_management(input, output, spatialRef) 

The way you're using walk is a little awkward but should be functional.

  • Thx for your answer!! I will try it tmr! – Wiley Ng Sep 17 '17 at 17:39
  • Alright I understand now. Always use the variables inside the for function. – Wiley Ng Sep 18 '17 at 7:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.