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
- In Catalog (not in a map) right click on the raster and choose "share as web layer"
- In the sharing panel choose the option "Copy all Data"
- Click Publish
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))