0

I am composing an Arcpy tool to help users cache their current mxd's webmaps (our own services). I want to know a way to call the ArcGIS Web Map's scales with ArcPy. Once I have the web maps scales, I can apply policies and pass the desired scales to arcpy.gp.ExportMapServerCache for extraction.

Notably, the geoprocessing tool "Export Map Server Cache" calls the maps scales into the tools dialogue, a user then ticks the scales they want the cache. I figure if the tool can do it then some code can do it too...

My end goal is a tool that gets a web maps scales, applies an appropriate extraction extent polygon for the scale range, and extracts appropriate scales into a cache.

##### For Many Web Cache
arcpy.CreateFolder_management(UserProjectPathCache,lyr.name)
arcpy.AddMessage("    New Cache Folder:  "+ UserProjectPathCache +"\\"+lyr.name)
ServiceCache = (UserProjectPathCache +"\\"+lyr.name)

##### Passing To Publisher Connection String:
ExportService = UserProjectPath +"\\Temp_Pub_Connection\\"+lyr.name+".MapServer"
arcpy.AddMessage("    Temp Publisher Con: "+ExportService)

#TAKEN FROM THE GLOBAL IMAGERY SERVICE
S1 = 591657527.591555
S2 = 295828763.795777 
S3 = 147914381.897889
S4 = 73957190.948944
S5 = 36978595.474472
S6 = 18489297.737236
S7 = 9244648.868618
S8 = 4622324.434309
S9 = 2311162.217155
S10 = 1155581.108577
S11 = 577790.554289
S12 = 288895.277144
S13 = 144447.638572
S14 = 72223.819286
S15 = 36111.909643
S16 = 18055.954822
S17 = 9027.977411
S18 = 4513.988705
S19 = 2256.994353
S20 = 1128.497176

DefaultScales = "{0};{1};{2};{3};{4};{5};{6};{7};{8};{9};{10};{11};{12};{13};{14};{15};{16};{17};{18};{19}".format(S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12,S13,S14,S15,S16,S17,S18,S19,S20)

target_cache_path = ServiceCache
export_cache_type = "TILE_PACKAGE"  #"CACHE_DATASET" # "TILE_PACKAGE"
copy_data_from_server = "COPY_DATA" # Because the server might not have write access
storage_format_type ="COMPACT" # Easier To Move
num_of_caching_service_instances = 1 # I pulled this number from the air
area_of_interest = CacheAOI
export_extent = ""
overwrite ="MERGE"

arcpy.AddMessage("    --------------")
arcpy.AddMessage("        I: CACHING WEB MAP TO: "+ServiceCache)

################## EXPORT MAP CACHE HERE
try:
        arcpy.AddMessage("        I: CACHING WEB MAP: PLEASE WAIT...")
        arcpy.gp.ExportMapServerCache(ExportService, target_cache_path, export_cache_type, copy_data_from_server, storage_format_type, DefaultScales, num_of_caching_service_instances, CacheAOI, export_extent, "MERGE")
        arcpy.AddMessage("        I: CACHING WEB MAP: Completed")
        del ExportService
except Exception as e:
        arcpy.AddError("       "+e.message)
3
  • you can get the scale information from status.gdb situated at your server C:\arcgisserver\directories\arcgiscache\<service-name> – Surya Nov 23 '14 at 23:47
  • My users will not have access to the Servers C.. But it's a good thought. – GISI Nov 27 '14 at 6:57
  • If you have scales with you like shown S1,S2... You can also check Export Tile Cache (Data Management) : resources.arcgis.com/en/help/main/10.2/index.html#//… This tool doesn't need to have an access in C drive of Server. – Surya Nov 27 '14 at 15:55
1

Bill from Esri Inc gave me a hand with this one. You can call the LOD via json:

    import urllib, json
    parameters = urllib.urlencode({'f':'json'})
    request = "http://services.arcgisonline.com/arcgis/rest/services/World_Street_Map/MapServer?" + parameters
    response = json.loads(urllib.urlopen(request).read())

    try:
        tileinfo = response['tileInfo']
        cachescales = []
        for lod in tileinfo['lods']:
            cachescales.append(lod['scale'])

        print cachescales
    except:
        print "tileInfo key does not exist in JSON response; probably not a cached map service."

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.