I'm trying to write a script that clips all feature classes in fcList by the successive rows of a clip feature. I'm using arcpy with ArcGIS 10.0
The problem is that I need to verify whether the current fc of the fcList overlaps the current row of the clip rows. Here is the code (I commented the lines with my doubts, questions, remarks):
import arcpy, os
arcpy.env.workspace = r'Z:\Documents\SIG\tests\synthese_tocorrect.gdb'
fcList = arcpy.ListFeatureClasses() #the feature class to be clipped by each of the polygon of the clip layer
pochoir = r'Z:\Documents\SIG\tests\decoupe.shp' #the clip layer with multiple polygons
rows = arcpy.SearchCursor(pochoir)
count = 0
outFolder = r'Z:\Documents\SIG\tests\sorties'
for fc in fcList:
for row in rows:
p = row.Shape #I'm trying to get only the geometry of the current row but I thing it's not working
arcpy.MakeFeatureLayer_management(p,"ptmp") #...the output is empty while it should be the first polygon corresponding to the first row of the clip layer.
arcpy.SelectLayerByLocation_management("ptmp", "INTERSECT", fc)
arcpy.CopyFeatures_management("ptmp","ptmpselect")
nbrow = arcpy.GetCount_management("ptmpselect")
if nbrow > 0:
secteur = row.secteur #The integer ID of each polygon of the clip layer
out_poly = (outFolder, fc + "_" + str(secteur) + "_" + string(count))
arcpy.ClipAnalysis(fc, "ptmpselect", out_poly)
arcpy.DeleteManagement("ptmp")
arcpy.DeleteManagement("ptmpselect")
count = count + 1
else:
secteur = row.secteur # I know I repeat myself. Any idea to avoid it ?
out_poly = (outFolder, fc + "_" + str(secteur) + "_" + string(count))
del row, rows, pochoir, count, outFolder, fc, fcList
ptmpandptmpselectand iterate the counter only if there's an overlap? If not, pull them outside of the conditional. – Erica Nov 24 '14 at 12:36