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:
- Is there a better/more official way of doing this?
- This is a bit vague, but what could cause the upload to fail the first time it runs, but succeed every time after?
- Is there another way to do this using a different API?
- 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:
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="comment token">#obtain a reference to the project and map</SPAN>
project <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>ArcGISProject<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN>Path to the Project<SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">)</SPAN>
map <SPAN class="operator token">=</SPAN> project<SPAN class="punctuation token">.</SPAN>listMaps<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># create the raster layer</SPAN>
file_path <SPAN class="operator token">=</SPAN> <SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> some path <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN>
raster_layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>MakeRasterLayer_management<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> Valid parameters supplied here <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">)</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SaveToLayerFile_management<SPAN class="punctuation token">(</SPAN>raster_layer<SPAN class="punctuation token">,</SPAN> file_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># add the layer to the map</SPAN>
map<SPAN class="punctuation token">.</SPAN>addLayer<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>mp<SPAN class="punctuation token">.</SPAN>LayerFile<SPAN class="punctuation token">(</SPAN>file_path<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"TOP"</SPAN><SPAN class="punctuation token">)</SPAN>
project<SPAN class="punctuation token">.</SPAN>save<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># retrieve the layer from the map and make a</SPAN>
<SPAN class="comment token"># sharing draft from it</SPAN>
target_layer <SPAN class="operator token">=</SPAN> map<SPAN class="punctuation token">.</SPAN>listLayers<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> Layer name <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
sharing_draft <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>sharing<SPAN class="punctuation token">.</SPAN>CreateSharingDraft<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"STANDALONE_SERVER"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">"MAP_SERVICE"</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> Layer name <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">,</SPAN>
target_layer<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># update the properties of the sharing draft...</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>targetServer <SPAN class="operator token">=</SPAN> <SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> server connection <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN>
<SPAN class="punctuation token">.</SPAN>
<SPAN class="punctuation token">.</SPAN>
<SPAN class="punctuation token">.</SPAN>
<SPAN class="comment token"># save the sharing draft to a file</SPAN>
sddraft_path <SPAN class="operator token">=</SPAN> <SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> path to sharing draft <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN>
sharing_draft<SPAN class="punctuation token">.</SPAN>exportToSDDraft<SPAN class="punctuation token">(</SPAN>sddraft_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># The sharing draft is saved as an XML file with a different extension</SPAN>
<SPAN class="comment token"># and has options that can be modified to enable the features I want.</SPAN>
<SPAN class="comment token"># I modify the sharing draft to enable caching via "isCached" and setting</SPAN>
<SPAN class="comment token"># the min and max scale of the tile cache. Note: Setting these properties</SPAN>
<SPAN class="comment token"># does not cause the server to begin tiling the layer once it's uploaded,</SPAN>
<SPAN class="comment token"># but it does enable caching functionality in the hosted layer</SPAN>
modify_xml<SPAN class="punctuation token">(</SPAN>sddraft_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># stage the sharing draft, converting it to a service definition</SPAN>
sd_path <SPAN class="operator token">=</SPAN> <SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> path to the service definition <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN>
stage_result <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>StageService_server<SPAN class="punctuation token">(</SPAN>sddraft_path<SPAN class="punctuation token">,</SPAN> sd_path<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># upload the service definition to the standalone server</SPAN>
upload_result <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>UploadServiceDefinition_server<SPAN class="punctuation token">(</SPAN>stage_result<SPAN class="punctuation token">.</SPAN>getOutput<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> server connection <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># finally, cache the hosted layer</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>ManageMapServerCacheTiles_server<SPAN class="punctuation token">(</SPAN><SPAN class="operator token">/</SPAN><SPAN class="operator token">*</SPAN> valid parameters supplied here <SPAN class="operator token">*</SPAN><SPAN class="operator token">/</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Thank you for your time,
Brian