Upload a list for choice field in feature layer

315
2
11-22-2022 01:50 AM
Labels (1)
TobyChapman
New Contributor II

I am wanting to setup a layer for capturing tree plots.

I would like to create a choice list for the tree species.  I have the list of species in a csv file but I can't find way to upload it into the feature layer as a pick list.

Is there a way to this?

Any help would be appreciated.

0 Kudos
2 Replies
SaraJL
by
Occasional Contributor III

I have not seen a way to automatically do this in ArcGIS Online! The only way I have see to create a pick list of values in a feature layer in ArcGIS Online is to:

  • Create a Feature Layer from scratch in ArcGIS Online
  • Click on the Feature Layer > Select the Data tab (from the menu that says Overview, Data, Visualization, etc.)
  • Click on Fields on the top right
  • A large +Add button shows up on the top left > Add a field to the Feature Layer for the list (ex. Trees)
  • Click Add New Field
  • The new field should appear in the list > click on the field name (ex. Trees)
  • A Create List button shows on the top right
  • This will show the prompt window for adding values (in this case, tree species) to the list. There doesn't appear to be an automatic upload - so you might have to type the values in manually.

If you're using ArcGIS Field Maps, it will show up as a list picker on the GPS Unit/iPad - or if you are doing some other type of data collection. 

Not sure if there is an alternative way to do this! Like with a pre-created CSV file that you can upload to the site to create the Feature Layer - I've tried a few different methods, but nothing was successful. I think manually creating the list might be the only option.

Good luck with your project!

0 Kudos
RhettZufelt
MVP Frequent Contributor

You can use the python API for this.  Just need to convert the csv to json dictionary formated as below.

Here is what I use with subset of MUTCD codes for example:

from arcgis.gis import GIS

#JSON dictionary of the Domain Code/Values
# Replace FieldName with the name of the field you want the list on

update_dict = {"fields": [
    {
      "name": "FieldName",
      "domain": {"type":"codedValue","name":"FieldNameCodes",
      "codedValues":[
          {"name" : "Unknown", "code" : "Unknown"}, 
          {"name" : "Custom (Warning)", "code" : "Custom (Warning)"}, 
          {"name" : "W16-13P", "code" : "W16-13P"}, 
          {"name" : "W17-1", "code" : "W17-1"}]}}]}

# Connect to your AGOL account

my_agol = GIS(url='https://yourOrgHere.maps.arcgis.com/', username='AdminUser', password='AdminPass')

# Get the first layer - Layer 0 - of your Hosted Feature Layer with ID <HFL_ID>
# Change this to the layer number you want to modfy the Choice List for

lyr = my_agol.content.get('asdagaasf54ahghdf').layers[0]

update = lyr.manager.update_definition(update_dict)

This does not add to the list, but overwrites it.  So, I keep the json list in text editor so when I need to modify it, I just copy/paste into the script.

This is also the easiest way I have found to add somehting to the list and don't want it at the end.  After running this script, choice list is sorted in the order of the update_dict json.

R_

0 Kudos