I am trying to write my first python code to use in ArcGIS 10.1.

I have feature classes in a file geodatabase .gdb, and AOI.shp (area of interest). I list my geodatabase feature classes, and want to intersect my list with AOI.shp. I want to save my final intersected files.

Here is my code:

# import system modules
import arcpy, os
from arcpy import env

# Allow to overwrite existing files
arcpy.env.overwriteOutput = True

# Set environment settings
env.workspace = r"C:\Users\...\extent_AOI\disturbaces_for_aoi.gdb"

# identify AOI
aoi = r"C:\Users\...\aoi.gdb\aoi"

# Set output database
out_wksp = r"C:\Users\...\disturbances_by_aoi.gdb"

# list features in the working folder database
fcl = arcpy.ListFeatureClasses()

# print files to check them
print fcl

for fc in fcl:
    arcpy.Intersect_analysis([fc, aoi], out_wksp + fc, "ALL", "", "INPUT")
    print "intersection ok"

My code seems to run through PythonWin.

However, I can't find my output data in my output folder out_wksp ?

How can I save my output data correctly?

  • 2
    out_wksp + fc will not place the fc in your workspace, replace line of code - arcpy.Intersect_analysis([fc, aoi], out_wksp + "\\" + fc, "ALL", "", "INPUT") – Clubdebambos Feb 7 '17 at 20:18

Your output filepath is not including slashes before the feature class name. So if your feature class is called tempFC the output filepath is being generated as
C:\Users\...\disturbances_by_aoi.gdbtempFC rather than

Use os.path.join() to create a valid filepath:

for fc in fcl:
    outputFC = os.path.join(out_wksp, fc)
    arcpy.Intersect_analysis([fc, aoi], outputFC , "ALL", "", "INPUT")

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.