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.
1 Answer 1
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>
-
This is amazing! For some reason it was not clear publishing needed specific properties as well. Thanks a lot!Joost Neujens– Joost Neujens2020年02月06日 08:03:15 +00:00Commented Feb 6, 2020 at 8:03
-
If it answer's your question, please mark it as such.KHibma– KHibma2020年02月06日 13:34:29 +00:00Commented 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– KHibma2020年02月06日 13:35:49 +00:00Commented 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?Joost Neujens– Joost Neujens2020年02月06日 14:57:18 +00:00Commented Feb 6, 2020 at 14:57
Explore related questions
See similar questions with these tags.
File Geodatabase
(although how you're usingfileGeodatabase
is correct per the official doc