Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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)
share|improve this question
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 at 22:31
add comment

1 Answer 1

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

for featureClass in featureClassList:

Try:

for fc in featureClassList:

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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