I'm very new to python, but I'm having trouble finding the answer on my own.

I need to loop through a given file geodatabase, select any features that intersect a project polygon and then search the selection for specific information.

Broadly, how does one create feature layers for all the feature classes in a feature dataset and then pass those layers onto select by location?

My code so far ...

import arcpy
import csv
arcpy.env.overwriteOutput = True

arcpy.env.workspace = "C:\\Users\\Katherine.idea-PC\\Desktop\\FinalProject\\Water.gdb\\WaterDistribution"
featureClassList = arcpy.ListFeatureClasses()
projectArea = "C:\\Users\\Katherine.idea-PC\\Desktop\\FinalProject\\ProjectArea.shp"
outputCSV = "C:\\Users\Katherine.idea-PC\\Desktop\\Final Project\\Output.csv"

for featureClass in featureClassList:
     arcpy.MakeFeatureLayer_management(fc, fc+"_lyr")
     arcpy.SelectLayerByLocation_management (fc + "_lyr", "WITHIN", projectArea)
  • 1
    Welcome to GIS SE! Being "very new to Python", I recommend that you do the Make Feature Layer and Select Layer By Location steps manually on one feature class first, then use Copy As Python Snippet in the Geoprocessing | Results window to copy/paste the first few lines of code that you can post here via an edit to your Question. From there it should be easy to advise on how to add the iteration advice you seek.
    – PolyGeo
    Jan 5, 2014 at 22:31

1 Answer 1


I think it is only this line that stops it from working. Instead of:

for featureClass in featureClassList:


for fc in featureClassList:

Otherwise, I would expect you will get an error from the MakeFeatureLayer line about fc being a non-existent variable.

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.