1

I'm working on an ArcGIS JS API web application that requires a heavily customized PDF report.

When a user submits their desired extent to our reporting function, we need to convert their webmap to MXD (likely using arcpy.mapping.ConvertWebMapToMapDocument), modify some symbology, and export to PNG. We also need to build a separate legend (farther down in the report) that contains the proper polygon boxes and text descriptions:

enter image description here

My current plan is to export these all separately, then use python to inject them into a LaTeX document, then run pdflatex to generate PDF.

Is it possible to export the legend objects (polygon boxes and associated text) in this way? I can manually convert the legend to graphics in ArcMap, then paste them into Paint (or something) but I'm struggling to find a way to do this in python.

Any other workflows that make more sense?

3

There is not a way in arcpy.mapping to directly do the graphics conversion that you want.

One way to maybe pull this off, though, is to create a second map document from the web map and then modify that map document so that its layout consists only of the legend with the format and dimensions you want. One easy way to achieve this is to set the elementWidth or elementHeight of the other elements to a very small number and then move them to a negative position. (I think you can set them to 0.0 even and not worry about moving them, but if that creates a problem, just make them like 0.1 width and then move them to elementPositionX -1.0).
Once you do this, export the entire map document (which will only be your legend) to PNG.

The one problem you have to tackle here is that you cannot change the size of a map layout in arcpy. To tackle this, create a second template_mxd that is the exact dimensions you want for your legend. Since a "MAP_ONLY" template does not have surround elements, you cannot just modify the dimensions when you call arcpy.mapping.ConvertWebMapToMapDocument.

Then, when you call ConvertWebMapToMapDocument the second time, reference the template_mxd that has the legend dimensions. (In fact, you could modify this template so that all of the non-legend elements are already shrunk and off-canvas, but you will probably have to resize the legend still to fit your document.)

  • Got it-- thanks. I was hoping to be able to extract the actual image (i.e. the pink rectangle, then the rectangle with hashed one way, then the rectangle hashed another) and have those as image files, which doesn't seem possible. I'll see if I can format the legend in the second map document to look like my image above . . . otherwise maybe ArcObjects could help? – Charlie Hofmann Nov 12 '15 at 21:03
  • Oh, I think you can make calls to the rest API for the individual pieces of the legend too. That will take me a while to figure out, but I have some time today to look into that. – blord-castillo Nov 13 '15 at 14:07
  • Nice! Yeah, I was wondering about that too. Keep me posted! Thanks! – Charlie Hofmann Nov 13 '15 at 14:21
  • I think we're going to take a different approach-- it turns out we need to set symbology on the fly (based on a user-submitted extent). We're going to apply a set ArcGIS style to each type of feature on the map, then use a pre-generated png that corresponds to each style in the report. The REST API approach would certainly work, but the report symbology is never actually served from the REST endpoint. – Charlie Hofmann Nov 13 '15 at 15:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.