1

I am reading in the documentation it should be possible to publish a local file geodatabase as a hosted feature layer to ArcGIS Online. I have been trying different things, but that job keeps failing.

I am using the code below:

# Publish zipped fgdb to AGOL

fgdb = r"C:\Users\path\to\zipped\geodatabase.gdb.zip"
serviceProp = {}
serviceProp['type'] = 'Feature Service'
serviceProp['url'] = "https://organisation.url.com"

fgdb1 = gis.content.add(item_properties=serviceProp, data = fgdb, folder = "New folder")
fgdb2 = fgdb1.publish(publish_parameters = {'itemID': fgdb1.id}, file_type = 'fileGeodatabase', build_initial_cache=True, overwrite=True)

Has anyone been successful doing something similar? The best I can get is a an empty hosted feature layer. The feature service seems to be created but no feature layers are inside, while the local file geodatabase contains 20 layers.


error message related to comment above: using 'File Geodatabase' as a file type.

error message related to comment above: using 'File Geodatabase' as a file type.

5
  • From an old forum post I found, try setting the file_type to File Geodatabase (although how you're using fileGeodatabase is correct per the official doc
    – KHibma
    Feb 5, 2020 at 15:43
  • To troubleshoot further, upload the zipped fGDB directly to arcgis.com using the add item and see if that works. If that doesn't work, its not a code problem, but something inside the fGDB.
    – KHibma
    Feb 5, 2020 at 15:46
  • That is already tested and that works. I can upload the fGDB to AGOL with ArcGIS Pro without problems. Thanks for the quick response! Feb 5, 2020 at 16:01
  • Using 'File Geodatabase' as file_type resulted in the error below: Feb 5, 2020 at 16:03
  • Please always provide code and error messages as formatted text rather than pictures.
    – PolyGeo
    Feb 5, 2020 at 22:07

1 Answer 1

5

Your code is close, but there are a few things you're doing wrong with the properties you're passing into each call. Try the below code (specifically updating what you're passing for the properties and not passing in the itemId to the publish... the item itself knows which item it is, thus you don't need to give it this).

import arcgis
from arcgis.gis import GIS

g = arcgis.gis.GIS("https://www.arcgis.com", "USER", "PASSWORD")

fgdb = r"C:\temp\foo.zip"
serviceProp = {}
serviceProp['type'] = 'File Geodatabase'
serviceProp['itemType'] = "file"
serviceProp['tags'] = "sometag"

pubProps = {}
pubProps["hasStaticData"] = 'true'
pubProps["name"] ="foo"
pubProps["maxRecordCount"] = 2000
pubProps["layerInfo"] = {"capabilities":"Query"}


fgdb1 = g.content.add(item_properties=serviceProp, data = fgdb)
print(fgdb1)
>><Item title:"foo" type:File Geodatabase owner:USER>

fgdb2 = fgdb1.publish(publish_parameters = pubProps, file_type = 'filegeodatabase', overwrite=True)
print(fgdb2)
>><Item title:"foo" type:Feature Layer Collection owner:USER>
4
  • This is amazing! For some reason it was not clear publishing needed specific properties as well. Thanks a lot! Feb 6, 2020 at 8:03
  • If it answer's your question, please mark it as such.
    – KHibma
    Feb 6, 2020 at 13:34
  • I think the biggest problem in your code was trying to supply a URL and the TYPE. The system guessed you were uploading a CSV based on the properties you were sending it. Setting it to File Geodatabase and file are key.
    – KHibma
    Feb 6, 2020 at 13:35
  • Well actually, not entirely. As a capability, I specify more than just 'Query'. I also add 'Edit, Sync, etc.'. But it seems these are not all taken into account. That's normal? Feb 6, 2020 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.