3

I have already created a hosted feature layer that contains four separate layers. To upload these, I created a compressed file of the shapefiles for the four layers, and uploaded that as my hosted feature layer.

I would like to add an additional layer to this hosted feature layer, but I can't figure out how. I know how to open the layer in the Map Viewer and add a layer that way, but that is only temporary.

I would like to add it permanently, without having to re-create everything else.

Matt
19.4k4 gold badges25 silver badges64 bronze badges
asked Sep 1, 2021 at 15:04
3
  • Hello @Melissa, do you have a desktop application (ArcMap or ArcGIS Pro)? Commented Sep 1, 2021 at 15:32
  • Hi @YogeshChavan, I have ArcMap 10.7 Commented Sep 1, 2021 at 17:28
  • Related/possible duplicate: gis.stackexchange.com/questions/91834/… Commented Jan 16 at 1:16

1 Answer 1

2

ArcGIS Online doesn't provide an easy interface to add a new table or layer to a feature service, but you can do this with a Python script using the ArcGIS API for Python.

  1. Go to ArcGIS Online and navigate to the Notebooks tab
  2. Create a new "Standard" notebook
  3. Insert the following code to initialize the GIS object
"""
https://community.esri.com/t5/arcgis-api-for-python-blog/add-table-from-hosted-service-to-another-and/bc-p/1204799
Run the Notebook through ArcGIS Online so that ArcGIS is already installed. Installing Anaconda locally is unnecessary because this script is run once. 
"""
from arcgis.gis import GIS
# Follow https://developers.arcgis.com/python/latest/guide/working-with-different-authentication-schemes/ to see how to get the client_id or log in correctly
# if you can't just use username and password (logging in through an organization's SAML)
# with normal login the link is "https://arcgis.com"
gis = GIS("https://XXXX.maps.arcgis.com",client_id="XXXXXXX")
from arcgis.features import FeatureLayerCollection
print("Initialized authenticated GIS object")
search_result = gis.content.search(query="title:YOUR_FEATURE_SERVICE_TITLE owner:USERNAME")
database_agol = search_result[0]
# layers can be replaced with tables and adjust the next line as well
flc = FeatureLayerCollection.fromitem(database_agol)
layer_0 = dict(flc.layers[0].properties)
layer_0
# Copies the layer to a new layer. You can then modify the data table in ArcGIS Online
flc.manager.add_to_definition({"layers": [layer_0]})

Script adapted from Esri forum answer

Additional Resources

answered Jan 16 at 2:24

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.