Select to view content in your preferred language

Count results of SelectLayerByLocation tool

1162
5
11-30-2010 11:53 AM
KarenRobine
Frequent Contributor
I've run a geoprocessing SelectLayerBylocation on 2 layers. One has a few features. The other has millions (the layer to be selected). This runs quickly. But then I'm trying to figure out how many resultant records there are.  That seems to hang. I've tried
rtnNum = gp.GetCount_management(freewayLayer)
which is maybe still buggy in 9.3?? (but does it work in 10?)

I've tried a basic search cursor. In 99.99% of my cases, The selection layer will have 0 results. So I think its trying to deal with ALL of the records if the selection layer has 0 features selected.
I've tried gp.tableselect(freewayLayer, tempFile) but this is also rediculously slow. I was thinking this would ONLY work on the selected features but now I'm not so sure.

Ideas? I ONLY need to know how many intersected features there are?
0 Kudos
5 Replies
KarenRobine
Frequent Contributor
I just found this:
http://forums.arcgis.com/threads/16409-Check-if-FeaturLayer-has-Selection-FAIL?p=51277&viewfull=1#po...

But its soooooo slow. It takes several minutes to execute the following:
intNum = int(gp.GetCount_management(freewayLayer).getoutput(0))
0 Kudos
KarenRobine
Frequent Contributor
So the answer is:
fidSet = gp.describe(freewayLayer).fidset
which is sooooo much faster then any other method. (less then a second compared to several minutes using other methods)..
Nice!
0 Kudos
ArcGISUser
Frequent Contributor
Here's some existing code you can try:

result = arcpy.GetCount_management(ParcelInfo)
arcpy.AddMessage("   " + result.getOutput(0) + " Anno selected." )
getSTAnnoSel = result.getOutput(0)
if getSTAnnoSel >= 1:
       arcpy.AddMessage("     Anno has been calculated to street anno symbology")
       #Have it do something
elif getSTAnnoSel == 0:   
       arcpy.AddMessage("      Anno is NOT calculated.")
       #Have it do something else
0 Kudos
ChrisSnyder
Honored Contributor
You might want to explicitly be using integer values with this line:

getSTAnnoSel >= "1"

since you are attempting to quantitatively compare two string values (which "sort of" works BTW, but in an alphabetical sort of way). For example:

>>> "3" >= "2"
True
>>> "2" >= "3"
False
>>> "3" > "20"
True
>>> #oh crap!!!


http://forums.arcgis.com/threads/16409-Check-if-FeaturLayer-has-Selection-FAIL?p=51277&viewfull=1#po...
0 Kudos
ArcGISUser
Frequent Contributor
Oops my bad dawg.
0 Kudos