2

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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Feb 5, 2020 at 15:21
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 Commented 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. Commented 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! Commented Feb 5, 2020 at 16:01
  • Using 'File Geodatabase' as file_type resulted in the error below: Commented Feb 5, 2020 at 16:03
  • Please always provide code and error messages as formatted text rather than pictures. Commented 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>
answered Feb 5, 2020 at 17:10
4
  • This is amazing! For some reason it was not clear publishing needed specific properties as well. Thanks a lot! Commented Feb 6, 2020 at 8:03
  • If it answer's your question, please mark it as such. Commented 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. Commented 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? Commented Feb 6, 2020 at 14:57

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.