Why would my script run slower than the Select By Attributes window?

446
2
09-27-2011 08:26 AM
TimLangner
Occasional Contributor III
Hi there

I've created the below script which allows me to select features and have imported it into an ArcToolBox, with it set to run in the foreground. My reason for doing this is that I wish to be able to edit the script easily when changing layer or table names.

The problem I am finding with the interactive select by attribute window, is that I have to navigate through a rather long drop down list of layers and when ever I switch layers it helpful clears my SQL statement. Therefore I end up having to retype it even though the statements are often very similar.

However when I run the below code to select just 65 records out of over 61000, it is taking anything from 9 to 23 seconds, where as the interactive method takes under 2 seconds. Can anyone tell me what is cause this lag? Am I doing something wrong and if not, is there another way I can achieve this?
import arcpy
arcpy.SelectLayerByAttribute_management ("Full areas polygon layer outline only v5", "NEW_SELECTION", " \"AREA_NAME\" = 'AREA 4' ")
I may eventually use the arcpy.GetParameterAsText to allow me to change the inputy variable for the area_name and create scripts for other layers. However it's not saving me time if it takes 10-20 seconds each time.

Kind regards

Tim
Tags (2)
0 Kudos
2 Replies
MathewCoyle
Frequent Contributor
A while ago I recall hearing the built in select by attributes dialogue having already started querying the data when it is opened (list of fields, names, joins etc) which already takes care of some of the overhead that the arcpy.SelectLayerByAttribute_management() still has to go through.

Making different selections based on changing criteria that you input will not gain you any performance using python scripts than using the built in tools, or else Esri would have coded the built in dialogue to be the same as the arcpy tool. The performance gain is in automation. Not having to query the same (or similar) data over and over and over and over again.

Another method you may want to try is creating a feature layer query.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006p000000

Using a where clause with this tool may give you the performance speed you are looking for, depending on why you need to make a selection at all.
0 Kudos
TimLangner
Occasional Contributor III
A while ago I recall hearing the built in select by attributes dialogue having already started querying the data when it is opened (list of fields, names, joins etc) which already takes care of some of the overhead that the arcpy.SelectLayerByAttribute_management() still has to go through.

Making different selections based on changing criteria that you input will not gain you any performance using python scripts than using the built in tools, or else Esri would have coded the built in dialogue to be the same as the arcpy tool. The performance gain is in automation. Not having to query the same (or similar) data over and over and over and over again.

Another method you may want to try is creating a feature layer query.

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000006p000000

Using a where clause with this tool may give you the performance speed you are looking for, depending on why you need to make a selection at all.


Thanks for your reply Matt.

What I'm doing is a series of quick visual and data checks.

1. I am checking that features are assigned to the correct road and using the correct UPRN (UK address id).
2. If the features are assigned to the wrong road then I need to switch to the LLPG layer in my query and search on the street name so that I can then update the details of the incorrect assigned features.

It's a fair quick task in terms of the query itself but requires me to switch between the two layers constantly. The queries are very similar because the tables use the same field names for the fields I am checking. However every time I switch layers in ArcGIS, in the select attributes window, it removes the what I have typed. In addition to that it is very easy to lose the Select attribute window, as it gets hidden behind the create feature window; table and identify windows which I have open. If I then go to the menu and hit Select by attributes, nothing appears and I then have it hunt around to find it hidden behind other windows. I could put it on the the map side but it obscures the map. I'd rather leave it open than close it.

By using the Python window I can use ALT+TAB to switch to it. I can amend my script,save and hit run. It's not possible to switch however to the select by attributes window in ArcGIS. I guess my issues are really myself trying to find ways around annoying GUI interface issues, as opposed to a genuine need to do this in python but I thought perhaps Python might be a good workaround, until ESRI, if they ever do so, improve the GUI interface.

What would be good is something along the lines of SQL Developer. In fact you can have multiple tabs open and from those run multiple queries and scripts which all output to the output window.

Kind regards

Tim
0 Kudos