0

I am trying create a loop that will intersect each individual township with a statewide section layer. I am having trouble with the syntax of the intersect tool I think, but maybe it is something else.

# Import system modules
import sys, string, os, arcgisscripting
import arcpy, os, sys, string
from arcpy import env
from arcpy.sa import *
gp = arcgisscripting.create()

arcpy.OverWriteOutput = 1
arcpy.env.overwriteOutput = True


input_folder = "C:\\state\\towns.gdb"
arcpy.env.workspace = input_folder
out_wksp = "C:\\state\\township_sections.gdb\\"

env.workspace = input_folder

fcl = arcpy.ListFeatureClasses()
print fcl

infeatures = ["C:\\state\\towns.gdb\\sections", fcl]
print infeatures


#ExtractByMask_sa (in_raster, in_mask_data, out_raster) 
for fc in input_folder:
    print fc
    arcpy.Intersect_analysis(infeatures, out_wksp + fcl, "ALL", "", "INPUT")
    #arcpy.Intersect_analysis(["C:\\state\\towns.gdb\\sections" fcl], out_wksp + fcl, "ALL", "", "INPUT")
#    fc = fclist.Next()
    print 'clipped', fcl

print 'done'

closed as too broad by PolyGeo, Jason Scheirer, user2856, Mapperz Aug 4 '14 at 2:22

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Welcome to GIS.SE. out_wksp + fcl doesn't look right. fcl is all the feature layers, surely it should be out_wksp + fc. Your iteration does't look right either. Are you trying to do each feature class in a database and/or some shapefiles too? – Michael Stimson Aug 3 '14 at 22:35
3

It is apparent that you are using a 9/9.3 example that clipped rasters. Here's a markup to show you the difference:

# Import system modules
# import sys, string, os, arcgisscripting #9/9.3 geoprocessor, use arcpy instead
import arcpy, os, sys, string
from arcpy import env
#from arcpy.sa import * # don't need this, you're not doing any Spatial Analyst functions
#gp = arcgisscripting.create()#9/9.3 geoprocessor, use arcpy instead

# arcpy.OverWriteOutput = 1 this is (sort of) the Old way
arcpy.env.overwriteOutput = True # this is right

input_folder = "C:\\state\\towns.gdb"
arcpy.env.workspace = input_folder # this is right
out_wksp = "C:\\state\\township_sections.gdb\\"

#env.workspace = input_folder # not right, already done

fcl = arcpy.ListFeatureClasses()
print fcl

infeatures = ["C:\\state\\towns.gdb\\sections", fcl] # not sure what this is about??
print infeatures

for fc in fcl:
    print fc
    infeatures = input_folder + '\\' + fc
    arcpy.Intersect_analysis(infeatures, out_wksp + fc, "ALL", "", "INPUT")
    print 'clipped ' + fc

print 'done'

When iterating feature classes you get a list using arcpy.ListFeatureClasses() and then iterate using for fc in the_list: where essentially fc is a string with the name of each feature class. For safety use the full path name, just in case you've changed your workspace along the way: infeatures = input_folder + '\\' + fc.

You've imported env from arcpy so you don't need to arcpy.env.overwriteOutput it could be env.overwriteOutput it doesn't make any difference at runtime but there's no point from arcpy import env if you intend to fully qualify it later... that's just me being picky though.

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