TransWikia.com

Creating definition query from selected features using ArcGIS Pro

Geographic Information Systems Asked on June 19, 2021

I have a layer with 2000 or so points, and I selected 50 of them (with no attributes in common, they were randomly chosen). Now I want to make a definition query, so should I will only visualize these 50 points from now.

What is the most practical way to turn the selected features into a definition query filter?

3 Answers

You would not make a definition query, especially if there is no logic to select them. What you can do is right click on the layer in the contents panel go to selection in the context menu and select "Make Layer from selected features". This will create another layer based upon your selection. This layer is a sort of definition query but based upon selections, so it's pointing to the source dataset and not creating a brand new dataset.

Answered by Hornbydd on June 19, 2021

There are several ways to do it, but the most practical way, since it's arbitrary is to create a new field (name it what ever you want, i.e. "mydefquery"), and field calculate that field to what ever makes sense (i.e. "Random 50 points").

You can then make a definition query where mydefquery='Random 50 points'.

This is better than doing a Selection to Layer approach or a DQ where Object ID IN (210, 5002, 3321, ....) because it will persist if you migrate the data to another geodatabase or add that FC to another map.

Answered by alexGIS on June 19, 2021

You can also just do it with a few lines of code. This has the advantage over the make layer from selected feature, in that you can see the query definition.

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

Answered by Mark Bryant on June 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP