Wednesday 23 August 2017

arcgis desktop - Create Layer from Selected Features tool: How is the list of features stored?


In ArcGIS Desktop, there is a tool called Create Layer from Selected Features. Using this tool, I can convert a selection to a layer in ArcMap.


It's my guess that there is a "list of features" that is embedded in the layer somewhere that isolates which features to show in the map.


I would have thought that the "list of features" would have been stored in a where clause in a definition query as a list of objectids. For example: where objectid in(123,456,789,...). However, this is not the case.


If the layer doesn't have a WHERE clause or definition query, then how is the list of features stored?



Answer



Create Layer From Selected Features DOES NOT create a DYNAMIC layer. The resulting layer is not dynamic at all. It is based on an FIDset.


If you change the source data, the FIDs will change and your selection layer will break.



There is no where clause in a selection layer. It is based on FIDset (the FIDs that were selected when you used 'Create layer from selected features').


Please note that if you add or remove records from the source data, the FIDs will change, and your selection layer will show incorrect records.


You are confusing the selection layer with a query layer, which stores a where clause and is dynamic.


EDIT: The list of features for a selection layer is stored in memory. It is bad practice to use selection layers other than for temporary work as there is no way to recover the original selection once the selection layer breaks.


To find the list of features in a selection layer, you can use many different methods including SearchCursor to build a list of IDs.


Something like this:


OIDlist = []
with arcpy.da.SearchCursor(layer, 'OBJECTID') as scur:
for row in scur:
OIDlist.append(row[0])


From comment by crmackey:


There is also a built-in way with describe to get the FIDSet. This is a string, but is easy to convert to a list:


OIDlist = map(int, arcpy.Describe(layer).FIDSet.split(';'))

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...