Error when trying to upload Raster Image with Python

1011
4
03-08-2021 09:26 AM
FlorSch
New Contributor II

Hello Community,

i've got a Problem with Uploading Rasterimages to the ESRI Portal with Python.

For Feature Layer everything is working well with e.g.

.
.
layerproperties['type'] = 'Shapefile'
item = self.gis.content.add(item_properties=layerproperties, data=layerpath)
item.publish()


But if i try to upload a .tif in a .zip and change the 'type' to 'Image Collection' i get a Problem after the Upload when i try to publish:

ValueError: A file_type must be provide, data format not recognized

I tried to publish the Image Collection manually in the portal:

Publish Image Collection error: Exception: null

After that i watched into the Reference and chnanged item.publish() to:

 

item.publish(publish_parameters=None, address_fields=None, output_type=None, overwrite=False, file_type='Image Collection' , build_initial_cache=False, item_id=None)

 

ErrorMessage:

File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\arcgis\gis\__init__.py", line 10353, in publish
elif not buildInitialCache and ret[0]['type'].lower() == 'image service':
KeyError: 'type'

So i added a output_type to the publish function:

item.publish(publish_parameters=None, address_fields=None, output_type='Imagery Layer', overwrite=False, file_type='Image Collection' , build_initial_cache=False, item_id=None)

I got the same error.

So i watched again in the reference:

Publishes a hosted service based on an existing source item (this item). Publishers can create feature, tiled map, vector tile and scene services.
Feature services can be created using input files of type csv, shapefile, serviceDefinition, featureCollection, and fileGeodatabase. CSV files that contain location fields (i.e. address fields or XY fields) are spatially enabled during the process of publishing. Shapefiles and file geodatabases should be packaged as *.zip files.
Tiled map services can be created from service definition (*.sd) files, tile packages, and existing feature services.
Vector tile services can be created from vector tile package (*.vtpk) files.
Scene services can be created from scene layer package (*.spk, *.slpk) files.
Service definitions are authored in ArcGIS Pro or ArcGIS Desktop and contain both the cartographic definition for a map as well as its packaged data together with the definition of the geo-service to be created.

Seems for me, i cant upload and publish any images...
Am i right? Or does anyone know how to solve the problem?

 

Best regards and thanks a lot for your help

0 Kudos
4 Replies
JayantaPoddar
MVP Esteemed Contributor

Do you have access to ArcGIS Pro? Could you try Build a tile package in ArcGIS Pro and upload to your organization ?



Think Location
0 Kudos
FlorSch
New Contributor II

I do have but i try to automate this step...
I CAN upload tifs to the Portal with clicking in the Portal itself...

But i think i will try to automate the building of such a tile package and then upload it with my Code...

 

Thanks for your Reply 🙂

0 Kudos
JayantaPoddar
MVP Esteemed Contributor

Yes. I am sure you have already figured it out, but I am still sharing the link to the python script for Create Map Tile Package (Data Management) for anyone looking for it.



Think Location
0 Kudos
fpr
by
New Contributor

Hi Flor,

Maybe you can use following sample below to add an image, logo in AGOL content by setting type = pdf as a tricky.

 

from arcgis.gis import GIS
import arcgis
import os

gis = GIS("https://arcgis.com", "myLogin")
manager = arcgis.gis.ContentManager(gis)

#Trick:
#use type=pdf to add your image named miramas.JPG

inRaster = r"C:\Pictures\miramas.JPG"
image_properties = {'type':'PDF', 'description':'image raster','title':os.path.basename(inRaster), 'tags':'jpg', 'access':'Public'}
manager.add(image_properties, data = inRaster)
print('added!!')

 

Hope this help you,

Regards,

Fred

0 Kudos