Equivalent to Find Tool in ArcPy?

217
6
09-16-2021 08:04 AM
AxelThomas
New Contributor III

Hi,

is there an equivalent to the "Find tool" in ArcMap using arcpy? The find tool is way faster when searching over multiple layers than any code I can come up with... Any ideas?

 

 

Tags (2)
0 Kudos
6 Replies
BlakeTerhune
MVP Regular Contributor

If you don't know the exact name or position, I can't think of another way than simply looping over everything that's there and checking for likeness. There may be some inefficiency in your code that could be improved. Feel free to post a snippet of what you're doing.

0 Kudos
AxelThomas
New Contributor III

I thought so [sigh...]

I am using a two-step approach:
first selecting feature classes based on name and then looping through the list with a search cursor:

fcList = arcpy.ListFeatureClasses(sSearchStr,"POLYGON")

for fcls in fcList:

    cnt = len([r[0] for r in arcpy.da.SearchCursor(fcls, fieldname, where_clause = query)])

    if cnt > 0:

        [....]

Would be great if  you have an idea how to speed up this process!

 

 

 

0 Kudos
BlakeTerhune
MVP Regular Contributor

Are you sure the slowness is coming from ListFeatureClasses()? If so, maybe try arcpy.da.Walk()

If not, it might be the counting of records that's slow. @JoshuaBixby posted a blog article a while back concerning the performance of counting records. Unfortunately, the formatting was lost in transition to the new Geonet forum but he summarizes in the comments that:

If you can reach back to the layer, feature layer, feature class, table view, or table; then the Get Count tool is by far the quickest method.

However, it does look like you're applying a where_clause so you'd probably have to make a selection first for get count, which would likely negate the performance gain. Maybe try ArcSDESQLExecute() with a  where clause and count?

0 Kudos
DanPatterson
MVP Esteemed Contributor

There is no equivalent in arcpy.


... sort of retired...
0 Kudos
DuncanHornby
MVP Frequent Contributor

Ensure the field you are querying over has an attribute index built for it.

0 Kudos
AxelThomas
New Contributor III

Thanks to all of you, there are a number of interesting points to check now. Thankfully first I will be off to the mountains for a week or so and will tackle that problem when I'm back

0 Kudos