0

I've been doing some experimentation with SelectByLayerAttribute, and I've noticed that it does not select anything when provided with the path of a feature layer (e.g. 'C:\Users\Sean\OneDrive\Documents\ArcGIS\Projects\ProjectName\test.gdb\Electric_substations')

It only works with layers that are sourced from the Contents pane (ArcGIS Pro Script tool)

using input from contents pane

in_substation = arcpy.GetParameterAsText(5)

arcpy.SelectLayerByAttribute_management(in_substation , "NEW_SELECTION", where_cond)

The only solution that I can think of now is to add it to the Contents pane using m.addDataFromPath('C:\Users\Sean\OneDrive\Documents\ArcGIS\Projects\ProjectName\test.gdb\Electric_substations') then using that as the input somehow.

If I had a layer located at the path 'C:\Users\Sean\OneDrive\Documents\ArcGIS\Projects\ProjectName\test.gdb\Electric_substations', could I convert it to a format where SelectByLayerAttribute would accept it without adding it to the contents pane using addDataFromPath?

asked Jun 7, 2021 at 14:00
2
  • 1
    Layer functions operate on Layer objects. A source path is not a valid Layer because it doesn't have a selection set property (which moots the purpose of SelectLayerByAttribute) Commented Jun 7, 2021 at 15:02
  • Try Select tool, it works on feature classes. Commented Jun 10, 2021 at 1:57

1 Answer 1

3

The tool, Select Layer by Attribute only works on layers. A layer, is different than the featureclass or item on disk. The layer is either virtual, or resides in the app (ArcMap/ArcGIS Pro, etc). Think of the layer like a view of the data. You need to put the selection (what the tool is doing), on the layer.

I'm not entirely sure of your workflow - it sounds like you're working with a tool, inside the app, but you are not using layers. (Maybe there is a good reason for this, but typically in the app, you'd just use a layer, something added to your map). Anyways, you can still use a item on disk (featureclass). Instead of using Select Layer by Attribute, make use of Make Feature Layer. It will "turn a featureclass into a layer". It has the added benefit of a where parameter, so the tool does two things at once.

answered Jun 7, 2021 at 16:31

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.