AnsweredAssumed Answered

usage of ConvertWebMapToMapDocument

Question asked by n.ueberschaeresri-rw-esridist Employee on Mar 14, 2017
Latest reply on Mar 16, 2017 by n.ueberschaeresri-rw-esridist

I am trying to somehow backup WebMaps from AGOL and am thinking the ConvertWebMapToMapDocument function could be helpful with this. I thought of saving (1) the json file itself and (2) save it as mxd. While I think saving the json file itself shouldn't be that dificult, I'm struggeling finding a way to make ConvertWebMapToMapDocument work.

Unfortunately, when looking through different examples in the documentation and through the web, I always find a WebMap_as_JSON variable (or similar named) that gets its value from a tool as it seems (getAttributeAsText(0)). I assume that it expects the json code of the WebMap which could be this one http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson

I managed to read the content by adding

jsonResponse = urllib.urlopen(webmap)
WebMap_as_JSON = json.loads(jsonResponse.read())

When I print now WebMap_as_JSON I get the same content as at the URL above though in a different order. 

 

But when I try to convert now my WebMap_as_JSON to a mapdocument with 

result = arcpy.mapping.ConvertWebMapToMapDocument(WebMap_as_JSON)

I receive a Runtime Error:

RuntimeError: Expected to find comma, colon or start of array; state : startOfObject; buffer : {u'authoringAppVersion': u'5.1', u'authoringApp':

So I assume it's still not the right content as the input. 

 

I would highly appreciate if someone could give me a hint how to get the right input for ConvertWebMapToMapDocument. Thanks a lot!

 

For you to try, this is what I have so far: 

 

import arcrest
import arcpy, urllib, urllib2, json

webmap="http://www.arcgis.com/sharing/rest/content/items/95562b6a24994641bbbaa3d1f2b7cf4f/data?f=pjson"
jsonResponse = urllib.urlopen(webmap)
WebMap_as_JSON = json.loads(jsonResponse.read())
print(WebMap_as_JSON)
result = arcpy.mapping.ConvertWebMapToMapDocument(WebMap_as_JSON)

mxd = result.mapDocument
mxd.saveACopy(r"<here is my path to the output mxd file>")

print("Map document saved")

Outcomes