Select to view content in your preferred language

Selection to Definition Query

11-15-2013 07:46 AM
Status: Under Consideration
Labels (1)
Occasional Contributor

Add a tool (w/ gui preferably) to get the attribute values for a set of selected features and use them in an interactive definition query dialog box which would allow the user to select which attributes to use for the querry and how to use them.  If this is set up in gui it could also be used to visually analyse for trends within the selected data.


I also added an idea for ArcGIS Pro for this capability. It has been reviewed but still not implemented. Jakub Sisak‌ are you looking to perhaps come up with a Pro Addin too? 

My idea is here: 


IMO Esri should offer to buy Jakub's tool and make it part of official toolkit.

by Anonymous User

A tool to create a definition query that includes all selected features. Maybe using a unique identifier field like "OBJECTID". This would be a nice addition instead of having to create a new layer from selected features to see just selected features on a map.


Hi @Anonymous User I merged the idea you just submitted with this existing idea - please add your vote to this one!  Thank you.


Instead of creating a new layer of the selected features it would be very helpful just to create a definition query out of the selected features (identifier = OBJECTID).

Please do this step. It's an old idea that helps avoiding data copies. Thanks a lot!



I created an Add-in that supports the following scenario:

1) User: selects a layer in Table of Contents and makes a selection
2) User: clicks on a button in the Ribbon bar (Table ->View)
3) Tool: creates a new Layer Definition based on current selection (from selected layer) based on ObjectID field under a specific name 'YYYY-MM-DD HH:MM:SS'. New Layer Definition is not active.

Would that do the job?

Looking for your feedback.



#### Edit:

If anyone is interested in, here is a link to the Add-in (ArcGIS Pro 2.8).





When creating maps, I often find a situation where I need to display a few polygons on a map. Instead of performing a definition query, or selecting the features and exporting, it would be nice to have an option from right clicking a layer to "Display only selected features", instead of having to make a new layer.

For example, a cartographer only needs to show a grouping of counties. They could draw a polygon to select counties and export to a new shp/feature layer. Or They could enter the county names in a def query, only to realize counties with like names from other states are still showing right across the state boarder. This gets trickier by having to add more expressions/expression sets to exclude the state, but maybe not one county in the grouping that may also share the other state...  If the cartographer could choose to "Display only selected features" in the map it would alleviate some additional workflows. They could export a map without creating new layers or making a complex def query. 

An additional but similar feature, it would also be nice to have the option to filer based on map extent like in Portal or AGOL.


For what it’s worth, it's possible to do it with PythonCreating definition query from selected features using ArcGIS Pro

The script creates a definition query from the selection. It uses the first layer in the Contents pane that is called MY_USER.ROADS.

def qdef_selected_features(lyr):
    desc = arcpy.Describe(lyr)
    # Get a semicolon-delimited string of selected feature IDs 
    fid_list = desc.FIDSet.split(";")
    # build the query definition
    query = '{} IN ({})'.format(desc.OIDFieldName, ",".join(fid_list))
    # apply the query definition back to the layer   
    lyr.definitionQuery = query

aprx ='current') 
m = aprx.activeMap 
lyr = m.listLayers('MY_USER.ROADS')[0] 

But I think we’re all saying we’d rather have an OOTB tool.




I often use attribute queries when exploring data to figure out what's what: what features of this dataset do I want, and which ones don't I want? This is a really useful method when looking at the map and if I have an idea about what the fields are. The very next thing I do is go create a definition query that's either the same, inverse of, or similar to my selection query. To save some steps along the way, a button in the select by attributes window for 'convert to definition query' would be really helpful. I picture a prompt that asks for a definition query name, and maybe display the expression editor again in case the one you want to save is slightly different than the one you're using for your attribute query. Hit OK and the definition query is applied!


Hi @KoryKramer  this actually does not seem to be the same idea. This idea, also good, seems to be talking about having the software convert selections into queries, not user-defined queries themselves within the select by attribute window. Thanks.