I'm trying to automate a workflow that we perform in ArcGIS Pro. The workflow is taking some rasters that are stored in a FGDB and sharing them as an image service via Portal and a federated server.
Here is the documentation on the manual process that works
https://pro.arcgis.com/en/pro-app/latest/help/sharing/overview/web-image-layer.htm
The manual steps are
This results in an image service in Enterprise.
However, I cannot seem to script this workflow. I tried using
arcpy.CreateImageSDDraft
But it seems to create a Server-only version of the .sddraft. I can stage the file using arcpy.StageService but cannot upload the resulting .sd file to Portal. I even tried manually uploading the .sd file to Portal and Portal gave me a warning that it was an ArcGIS Server file.
import arcpy
from arcgis.gis import GIS
gis = GIS(url="https://url.to.portal/arcgis", username="userid", password="pass", set_active=True, expiration = 60, verify_cert=False)
service =r'Test_Image'
source = r'C:\Temp\Upload\20230721_AirPollutionPackage.gdb\SD_0721_1030_PM25_IDW'
sddraft = r'C:\Temp\Upload\SD_0721_1030_PM25_IDW.sddraft'
sdfinal = r'C:\Temp\Upload\SD_0721_1030_PM25_IDW.sd'
arcpy.CreateImageSDDraft( raster_or_mosaic_layer= source, out_sddraft=sddraft, service_name=service, server_type= 'ARCGIS_SERVER',
copy_data_to_server= True, folder_name= None, summary= "Test Image Upload",
tags= "las,image service")
try:
arcpy.StageService_server(in_service_definition_draft= sddraft, out_service_definition= sdfinal, staging_version=5)
arcpy.UploadServiceDefinition_server(in_sd_file=sdfinal, in_server="My Hosted Services")
warnings = arcpy.GetMessages(1)
print(warnings)
except Exception as ecp:
print(str(ecp))
I believe the problem you're facing is CreateImageSDDRaft is meant for publishing to ArcGIS Server. There's a required "connection_file_path" parameter I think you're missing which points to the path of an .ags connection file.
To my knowledge, it is possible to publish through Portal using a different workflow that relies on the ArcGIS API for Python: Create Imagery Layers | ArcGIS API for Python. However, I believe in order to make use of this approach you need to have a portal configured for Raster Analysis.
Thanks for the response @EarlMedina. Unfortunately, we do not have a Raster Analysis deployment. We only have an ArcGIS Server Advanced and a relational datastore.
So is there no way to replicate the Share Web Image Layer tool in Arcpy? It seems odd since it can be accomplished via Pro.
Since we are federated I don't believe I can create or use a publisher arcgis server connection, .ags file.
I think you can reasonably simulate the same result for your case. Instead of going through Portal you publish directly to Server and copy the data. It seems like you're publishing single raster datasets? That should be fine under your licensing. All you should have to do to is make some minor changes to your CreateImageSDDRaft function.