1
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?

1 Answer 1

1

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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