Monday, April 15, 2013

Dynamic Layers and Workspaces

An interesting and exciting aspect that I really like at 10.1 is the use of dynamic map services to display data from a work space on disk.

The exciting aspect is this:

  • Dynamic Rendering
  • Add 1:n layers to a map service
Where is gets interesting is this, in ArcPy, you cannot update symbology for feature classes.  So essentially if you wanted to add a feature class to a map document, you have to accept the default symbology, or apply the symbology from an already existing set of layer files (.lyr).  Not real dynamic, and at least I feel, a horrible choice.  

Leveraging the web map REST specifications, as a developer you could create a map object (mapping.MapDocument object) and export the display to PNG, PDF, JPG, etc...  The downside is that at 10.1, it appears you cannot save the MapDocument object to disk and view the dynamic layer in the TOC.  This will throw an error when you open the map document file.

So what is this good for you are probably thinking?  It's true you cannot view dynamic layers in 10.1, but the ability to use dynamic layers gives data driven pages the much needed shot in the arm to add layer on the fly from a web application.  The new printing services for ArcGIS for Server leverages this concept except the out of box tool only produces one export at a time, where as a data driven page tool would produce multiple exports from a single input.

To get this concept to work, you would have to do the following:

import arcpy

from arcpy import mapping
json = arcpy.GetParameterAsText(0)
results = mapping.ConvertWebMapToMapDocument(json)
mxd = results.mapDocument
mapping.ExportToPDF(mxd, r"c:\temp\export.pdf")

Here we created a new map object from a JSON string input and dumped it out to a PDF.  (JSON not included here)

ConvertWebMapToMapDocument() has some other very interesting functions/properties.  It can incorporate existing map document templates, and even extract Point, Lines and Polygon graphics to feature classes when passed as JSON to the function.

You can find more about ConvertWebMapToMapDocument here:  In addition to the function you can also find examples of web map JSON so you can quickly start playing around with the functions.

Please support this idea of having GUI designer in python built in with python add-ins.
It can be found here. (direct link: