Select to view content in your preferred language

Dataframe.scale problem when map created through ConvertWebMapToMapDocument

1760
1
Jump to solution
06-18-2013 09:21 AM
KenDoman
Frequent Contributor
I'm using a modified version of the Advanced High Quality Printing script to create a custom print job for a client. They want to create PDF maps at 1:1200 or 1:4800 scale, and they have mxds formatted for that. However, the client-side flex application uses tiled map services that display at scales of 1:500, 1:1000, 1:2000, 1:4000, and so on. So, when I passed my WebMapAsJson into the script, the map scale was not what the client wanted (1" to 333.3' instead of 1" to 400').

So, I tried to pass a scale value to the dataframe, to override the webmap scale. That's when I received an error in the script that said "DataFrameObject: Error in setting scale value". According to the documentation, the dataframe's scale property is supposed to be read/write, but it wasn't the case here. I've looked through the mxd, and the dataframe's extent was set to automatic.

I also tried to set the mxd's extent to a fixed scale (1:4800), and commented out the dataframe.scale setting. However, the ConvertWebMapToMapDocument overrode the fixed scale with the map scale from the web service.

I can't change the tiling scales from the client web map service. Can anybody recommend a good workaround?
Tags (2)
1 Solution

Accepted Solutions
KenDoman
Frequent Contributor
After mucking around, I found a way to replace the scale value passed from the web application before it is used to update the .mxd file. Here's the relevant snippets of the script, based on the High Quality Map Printing Tutorial using arcpy.mapping

# Imports import arcpy import sys import os import uuid import ast # used to work with user defined extent import json # used to work with the web map json string  # Snip...  # Input WebMap json Web_Map_as_JSON = arcpy.GetParameterAsText(0)  #Snip (insert other parameters)  #Extra parameter - Extent Extent = ast.literal_eval(arcpy.GetParameterAsText(5)) _Extent = arcpy.Extent(Extent.get("xmin"), Extent.get("ymin"), Extent.get("xmax"), Extent.get("ymax"))  #Extra parameter - Scale Scale = float(arcpy.GetParameterAsText(6))  # modify Web_Map_as_JSON so that the web map scale matches the scale provided. Web_Map_Dict = json.loads(Web_Map_as_JSON) Web_Map_Dict["mapOptions"]["scale"] = Scale Web_Map_as_JSON = json.dumps(Web_Map_Dict)  # Snip (getting file location of templateMxd)  # Convert the WebMap to a map document result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd) mxd = result.mapDocument  # Snip (do other things to the map as needed)  # Reference the data frame that contains the webmap # Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap" df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]  # Update the extent of the map to match the extent passed through the service. df.panToExtent(_Extent)  # Snip (Do whatever else you need to the map, before serving it out.)

View solution in original post

1 Reply
KenDoman
Frequent Contributor
After mucking around, I found a way to replace the scale value passed from the web application before it is used to update the .mxd file. Here's the relevant snippets of the script, based on the High Quality Map Printing Tutorial using arcpy.mapping

# Imports import arcpy import sys import os import uuid import ast # used to work with user defined extent import json # used to work with the web map json string  # Snip...  # Input WebMap json Web_Map_as_JSON = arcpy.GetParameterAsText(0)  #Snip (insert other parameters)  #Extra parameter - Extent Extent = ast.literal_eval(arcpy.GetParameterAsText(5)) _Extent = arcpy.Extent(Extent.get("xmin"), Extent.get("ymin"), Extent.get("xmax"), Extent.get("ymax"))  #Extra parameter - Scale Scale = float(arcpy.GetParameterAsText(6))  # modify Web_Map_as_JSON so that the web map scale matches the scale provided. Web_Map_Dict = json.loads(Web_Map_as_JSON) Web_Map_Dict["mapOptions"]["scale"] = Scale Web_Map_as_JSON = json.dumps(Web_Map_Dict)  # Snip (getting file location of templateMxd)  # Convert the WebMap to a map document result = arcpy.mapping.ConvertWebMapToMapDocument(Web_Map_as_JSON, templateMxd) mxd = result.mapDocument  # Snip (do other things to the map as needed)  # Reference the data frame that contains the webmap # Note: ConvertWebMapToMapDocument renames the active dataframe in the template_mxd to "Webmap" df = arcpy.mapping.ListDataFrames(mxd, 'Webmap')[0]  # Update the extent of the map to match the extent passed through the service. df.panToExtent(_Extent)  # Snip (Do whatever else you need to the map, before serving it out.)