Vol 2: HOW TO UPLOAD YOUR MAPS TO ARCGIS ONLINE WITHIN THE APPLICATION MANAGER PROCESS USING PYTHON

As we saw in our previous blog-post HOW TO INCLUDE PYTHON IN YOUR CUBE APPLICATION MANAGER WORKFLOWPython software can be integrated into Cube's workflow in order to exploit its powerful programming language and comprise geoprocessing functionalities by including the ArcPy library. The program can also be linked dynamically (inputs/outputs, parameters, etc.) to the other program in your application. Allowing you to publish directly to ArcGIS online, your output (or input) MXD, thereby storing your results visualizations or mappings.

 

HERE’S HOW:

First, create a valid MXD with ArcMAP, using the Cube dataset or shape files you wish to visualize along with the mapping layout parameters.

To make this “dynamic” in the process:

  • Keep the same .mdb/.gdb name for all scenarios, e.g. Scenario.mdb / or Shape Files
  • Create the .mxd templates through ArcMAP and store these in an input folder within the catalog folder
  • Copy the .mxd “templates” over, in the different Scenario specific folders. This can be easily done with a Pilot script as in the example below (e.g. for Loaded_Network.mxd)

python1

 

 

 

 

A Python User Program needs to be included in the Application Manager work-flow, as explained here.

The input “sys.argv” for this Python script can be included through Catalog Keys, as below:

python2

 

 

 

 

 

 

 

The script included in the publish2AGOL.py file has been obtained from the script at the link https://blogs.esri.com/esri/arcgis/2013/04/23/updating-arcgis-com-hosted-feature-services-with-python/. The process within this script is the following (as reported at the above link):

  • Turn a map document into a Service Definition Draft (HostedMS.sddraft) using the mapping.CreateMapSDDraft function.
  • Modify the XML inside the .sddraft with the appropriate settings using the dom.minidom module.
  • Analyze the modified draft (HostedMSNew.sddraft) for errors using mapping.AnalyzeForSD.
  • Stage the sddraft into a Service Definition file (.sd) using StageService_server.
  • Upload the service to ArcGIS Online (ArcGIS.com) using UploadServiceDefinition_server.

Any error or message is written to the output Report.prn text file.

The {AGOL_Username} and the {AGOL_Password} Catalog Keys are used in conjunction with the arcpy.SignInToPortal_server function. Nevertheless, for ArcGIS 10.2 (and later) users, it could be necessary to comment out this part of the script as below:

python3

 

 

 

And sign in / connect from ArcGpython4IS for Desktop “File > Sign In” prior to run the Python program.

 

This could also be updated by looking at the post here https://blogs.esri.com/esri/arcgis/2014/01/24/updating-your-hosted-feature-service-for-10-2/.

 

The Map Result

map