Proper way to generate tiled imagery layers on a standalone server?

303
0
08-06-2019 01:17 PM
BrianSmith11
New Contributor

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:

  1. Is there a better/more official way of doing this?
  2. This is a bit vague, but what could cause the upload to fail the first time it runs, but succeed every time after?
  3. Is there another way to do this using a different API?
  4. How do you cause the server to generate the hosted layer using the OGC standard?

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

0 Kudos
0 Replies