Sort Domain Alphabetically in ArcGIS Online

4855
31
06-22-2021 08:11 AM
JasonBritton1
Occasional Contributor

Hello all. I've got a Coded Value list of street names in and AGOL feature service. The list has grown to over 1200 and as a matter of convenience, I'm tired of having to scroll to drop the new value in its appropriate location. Anyone have a fix to sort the list of of values with a couple of clicks? 

31 Replies
GIS_Fox
Occasional Contributor III

That's bizarre. It may be an area minimum requirement or agency level of government or company access perhaps. DM me if you hear back, when I upload next I will take this into consideration if it's an issue for whatever reason. 

Back on topic though, do any of these help? If one topic or the other helps more we can dive into that in more focus for example. 

Jansen Lyons - Records and GIS Section - Public Works - City of Rio Rancho, NM
0 Kudos
JasonBritton1
Occasional Contributor

Nothing suggested seems really viable so far. I posted on reddit as well and someone created a sample codeblock to use. I suck at python so I'll have to stumble around and see if I can get it to work. 

JoeBorgione
MVP Emeritus

post it and lets have a look....

That should just about do it....
JasonBritton1
Occasional Contributor

from arcgis.gis import GIS gis = GIS("home") # Open the layer from arcgis.features import FeatureLayer MY_LAYER_URL = "https://services6.arcgis.com/your/full/path/here/FeatureServer/0" layer = FeatureLayer(MY_LAYER_URL, gis=gis) # Get the field definition. MY_FIELD_NAME = "yourFieldName" targetFieldDef = None for fieldDef in layer.properties["fields"]: if fieldDef["name"] == MY_FIELD_NAME: targetFieldDef = fieldDef break # Get the Coded Value List, sort it and push it back on the field def. codedValues = targetFieldDef["domain"]["codedValues"] sortedCodedValues = sorted(codedValues, key=lambda cvPair: cvPair["name"]) targetFieldDef["domain"]["codedValues"] = sortedCodedValues # Get the layer's manager interface and modify its definition. layerMgr = layer.manager updatedDef = {"fields": [targetFieldDef]} layerMgr.update_definition(updatedDef)

GIS_Fox
Occasional Contributor III

Is there a planned streets layer you could draw out of in combination to existing instead of updating the layer 2 days a week? It seems too complicated for what it should be, I am not nearly code-savvy enough to implement this but I follow the syntax well enough. Civil authorities will change or add names as they need to with request/petition/growth, and this is not to say growth can outstrip this, but I am curious if there are more pragmatic planning and delivery methods of this data than having 2 days a week dedicated to this work. Seems grueling but unfortunately realistic in today's market and such. On note of the code is there an editing group involved with this or is it just you?

Jansen Lyons - Records and GIS Section - Public Works - City of Rio Rancho, NM
0 Kudos
JasonBritton1
Occasional Contributor

There is a group of about 20 editors for this particular layer. There definitely has to be a better way, but I don't know what it is. The positive part is that I don't dedicate a full two days a week to it, but rather work on it maybe for an hour or two on the days I add roads. This is actually related to a point file used for water meter sets and drop ins where the field crews are required to input the billing address associated with the meter. Workflow is that I create the new centerline and then I have to add the new road name to the meter layer. 

JoeBorgione
MVP Emeritus

I can't really make heads or tails out of that code either even after putting in my python ide.

That should just about do it....
JasonBritton1
Occasional Contributor

Me either. 

GIS_Fox
Occasional Contributor III

Well, the day is young and I would say keep on it as others reply to this or your Reddit post. Keep us posted, glad it's just a few hours at a time than 48-ish straight over work periods. Thanks for posting & thanks to @JoeBorgione . This has been most interesting.

Cheers @JasonBritton1 

Jansen Lyons - Records and GIS Section - Public Works - City of Rio Rancho, NM
cartezj1
New Contributor III

I know it's been a while since you've posted but this is for reference for folks. I can't speak to how to easily make the values alphabetical in the feature layer. I'm not super skilled at coding so the one provided doesn't make sense for me in the AGOL environment. 

Since it's primarily for the field folks, I'm making the assumption that data is being collected using Collector, Survey123 or Field Maps. Perhaps Survey123 would be worth considering the most. 

My first suggestion doesn't lend itself well to workflow, but if wanting the initial change up to alphabetical order: export data back to geodatabase. Create the domain with the values in alphabetical order using Excel then table to domain, and reupload as new hosted feature layer. This is not great if you have this layer on a bunch of maps. But the values will be in ABC order.

The second is creating a survey using the existing feature service. You'll need to use Survey123 Connect which allows for creating a survey in Excel. Updates to choices is pretty easy when the feature service is published again. The survey can be created to depict the choices as a drop down in that's still searchable in the field but will be in the order that has been set in S123 Connect. With a list that's super long you'll want to use linked content-csv instead. You might use pulldata or external choice lists. Check out this link by ESRI that leads to explaining more. 

The quest continues otherwise to figure out how to get these rearranged behind the scenes on the actual feature layer for when working at the computer in AGOL or Pro.