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.
-
Hello @Melissa, do you have a desktop application (ArcMap or ArcGIS Pro)?Yogesh Chavan– Yogesh Chavan2021年09月01日 15:32:32 +00:00Commented Sep 1, 2021 at 15:32
-
Hi @YogeshChavan, I have ArcMap 10.7Melissa– Melissa2021年09月01日 17:28:42 +00:00Commented Sep 1, 2021 at 17:28
-
Related/possible duplicate: gis.stackexchange.com/questions/91834/…Marvin– Marvin2025年01月16日 01:16:05 +00:00Commented Jan 16 at 1:16
1 Answer 1
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.
- Go to ArcGIS Online and navigate to the Notebooks tab
- Create a new "Standard" notebook
- 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