I am trying to test if each feature of a feature class list intersect each feature of a shapefile (clip layer). I'm working with arcpy in ArcGIS 10.0
The arcgis desktop help says that if the feature comes from a geodatabase, all the features will be copied but if it's a layer, only selected will be copied (http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000).
In my code, I'm working with a feature class list from a geodatabase.In order to copy only selected, I first convert each feature class to a feature layer :
for fc in fcList:
for row in rows:
where_clause = "secteur = '{0}'".format(secteur)
arcpy.MakeFeatureLayer_management(pochoir, "ptmp", where_clause)#pochoir is #the clip feature. For each row I make a tmp corresponding to the geometry that I'll use #after.
arcpy.MakeFeatureLayer_management(fc, "toselect")
arcpy.SelectLayerByLocation_management("toselect", "INTERSECT", "ptmp")
arcpy.CopyFeatures_management("toselect", "selected") ## Here is the problem : #"selected" should be empty when not intersecting with "ptmp" but the whole "toselect" (so #the whole fc) is copied even if not intersecting.
nbrow = arcpy.GetCount_management("selected")
outName = "{0}_{1}_{2}".format(fc, secteur, count)
if nbrow > 0: ## So all the layers goes in the if even if they do not intersect.
do something
else:
do something else