Esri / arcgis-python-api

Documentation and samples for ArcGIS API for Python
https://developers.arcgis.com/python/
Apache License 2.0
1.89k stars 1.1k forks source link

enable the publish() method to support publishing geotagged photos within a previous uploaded zip-folder #1228

Closed niol-zh closed 2 years ago

niol-zh commented 2 years ago

Is your feature request related to a problem? Please describe. Currently, the publish() method does not support creating a hosted feature layer Image-Collection item containing geotagged photos. See: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.Item.publish However, it is possible in an interactive way see: https://www.esri.com/arcgis-blog/products/arcgis-online/mapping/add-geotagged-photos-map/

It would be nice to do so.

import arcgis
gis = arcgis.gis.GIS('home')
item_prop = { "type": "ImageCollection", "title" : "MygeotaggedPhotos","tags": "holiday", "description" : "Photos from holiday"} 
myitem = gis.content.add(item_prop, data=r'path\to\my\zippedFolder\data.zip')
myitem.publish(file_type=imageCollection)

Describe the solution you'd like See python-code above

nanaeaubry commented 2 years ago

@niol-esrich As of now the REST API publish endpoint does not support publishing with type image collection. It is recommended to add the item and then use create_service to publish your image collection. After seeing the rest calls made when adding through online, as suggested in the blog, here is some pseudo code to help see the workflow:

from arcgis.features import FeatureLayerCollection
from arcgis import GIS
gis = GIS(profile="your_online_profile")

data_path = (<path to zip file>)

zip_properties={'title':'GeoImages',
                'description':'an image collection',
                'tags':'arcgis, python',
                'type': 'Image Collection'}

# add the image collection online
zip_item = gis.content.add(item_properties=zip_properties, data=data_path)

# call analyze to see the publish parameters that can be included
params = gis.content.analyze(item=zip_item)

# Create the service by specifying the create params parameter
feature_layer_item = gis.content.create_service(name="GeoImagesTest", create_params = {" your params here"})

# Get the FLC and add the layers to the definition
flc = FeatureLayerCollection.fromitem(feature_layer_item)
flc.manager.add_to_definition({"layers":[<layer info>]})

# Add the relationship to the zip file
flc.layers[0].append(zip_item.id, "imageCollection")
feature_layer_item.add_relationship(zip_item, "Service2Data")

I know this is not an ideal solution as of now and if we are able to add to the publish endpoint then we will do so. If a better solution arises I will add it here but this is following the calls made by adding it with ArcGIS Online with the parameters that were specified. Hope it can help!

Here are a few links as well to reference: