Select to view content in your preferred language

Service Definition or File Geodatabase for publishing a hosted feature layer to AGOL?

826
1
05-22-2024 10:49 AM
Labels (2)
MaryGraceMcClellan
Regular Contributor

I have a file geodatabase with 100 layers in it. I want each layer to be its own item in AGOL and I'm trying to write a script that will automatically publish them to AGOL. (The hope is I can re-use this later)

I've seen a couple of different methods for publishing layers to AGOL. The one I'm using now uses something like the following code: 

# feature class has been exported to its own GDB
# new gdb has been compressed to a .zip file

item = gis.content.add(path to zipped GDB)
published_item = item.publish(overwrite=True)

 

This is  resulting in a "Job failed" error and I don't understand why. I've seen that it's possible to use a service definition, but I only want the hosted feature and I don't care about having a map service. Is the service definition method the only way to actually accomplish what I want to do? 

 

0 Kudos
1 Reply
Clubdebambos
MVP Regular Contributor

Hi @MaryGraceMcClellan,

Here is how I would approach this if I had access to ArcGIS Pro and ArcPy and avoiding the use of the ArcGIS API for Python.

  • Create an APRX and save it.
  • Use ArcPy to access the APRX (arcpy.mp.ArcGISProject())
  • Use ArcPy to iterate through each feature class in the geodatabase (arcpy.ListFeatureClasses())
    • On each iteration, for each fc, add it to Map
    • Publish that layer to ArcGIS Online (see code here to help)
    • Remove layer from the map.

This will go through all feature classes in the gdb and publish each one individually to ArcGIS Online (or Portal) as Hosted Feature Services. You will need to define the name of the Feature Service on each iteration which can simply be the name of the feature class itself.

You can use the same workflow with some minor tweaks to overwrite the feature services too should the need/want arise

~ learn.finaldraftmapping.com
0 Kudos