Hello Everyone,
I'm interested in taking raster data (raw files for terrain imagery), and publishing it to a standalone server through an automated python script, where the resulting layer is tiled according to my cache schematics. I have found a solution that works, but it does not seem well supported nor documented, and I'm questioning the reliability of my approach as the script seems to fail intermittently when run.
The questions I have are:
The resources I based my solution on:
I did find this class, which seems to be exactly what I want, but it does not support standalone servers: https://pro.arcgis.com/en/pro-app/arcpy/sharing/tilesharingdraft-class.htm
The approach I'm taking, which has been simplified for the point of demonstration, is as follows:
import arcpy
#obtain a reference to the project and map
project = arcpy.mp.ArcGISProject(/*Path to the Project*/)
map = project.listMaps()[0]
# create the raster layer
file_path = /* some path */
raster_layer = arcpy.MakeRasterLayer_management(/* Valid parameters supplied here */)
arcpy.SaveToLayerFile_management(raster_layer, file_path)
# add the layer to the map
map.addLayer(arcpy.mp.LayerFile(file_path), "TOP")
project.save()
# retrieve the layer from the map and make a
# sharing draft from it
target_layer = map.listLayers(/* Layer name */)[0]
sharing_draft = arcpy.sharing.CreateSharingDraft("STANDALONE_SERVER",
"MAP_SERVICE",
/* Layer name */,
target_layer)
# update the properties of the sharing draft...
sharing_draft.targetServer = /* server connection */
.
.
.
# save the sharing draft to a file
sddraft_path = /* path to sharing draft */
sharing_draft.exportToSDDraft(sddraft_path)
# The sharing draft is saved as an XML file with a different extension
# and has options that can be modified to enable the features I want.
# I modify the sharing draft to enable caching via "isCached" and setting
# the min and max scale of the tile cache. Note: Setting these properties
# does not cause the server to begin tiling the layer once it's uploaded,
# but it does enable caching functionality in the hosted layer
modify_xml(sddraft_path)
# stage the sharing draft, converting it to a service definition
sd_path = /* path to the service definition */
stage_result = arcpy.StageService_server(sddraft_path, sd_path)
# upload the service definition to the standalone server
upload_result = arcpy.UploadServiceDefinition_server(stage_result.getOutput(0),
/* server connection */)
# finally, cache the hosted layer
arcpy.ManageMapServerCacheTiles_server(/* valid parameters supplied here */)
Thank you for your time,
Brian