Export Map Server Cache (Server)

Summary

Exports tiles from a map cache to a folder on disk. The tiles can either be imported into other caches or they can be accessed from ArcGIS Desktop as a raster dataset, independent from their parent service.

Usage

Syntax

ExportMapServerCache_Server (server_name, object_name, data_frame, target_cache, {export_extent}, {levels}, thread_count, storage_format_type, {export_feature_class})
ParameterExplanationData Type
server_name

The ArcGIS Server machine hosting the service whose cache tiles will be exported.

String
object_name

The map service whose tiles will be exported.

String
data_frame

The source data frame for the map service.

String
target_cache

The folder into which the cache will be exported. This folder does not have to be a registered server cache directory.

Folder
export_extent
(Optional)

A rectangular extent defining the tiles to be exported. By default the extent is set to the full extent of the service's source map. Note the optional parameter on this tool that allows you to alternatively constrain tile export to a feature class boundary.

Extent
levels
[levels,...]
(Optional)

A list of scale levels at which tiles will be exported.

Double
thread_count

Number of map service instances to use while exporting the cache. By default the maximum allowable number of instances will be used (default for an ArcGIS Server service is 2). If you have more server power, you can raise the maximum allowable number of instances in the Service Properties, then raise this parameter when you run the tool.

Long
storage_format_type

The storage format of the exported cache.

  • COMPACTTiles are grouped in bundle files to save space on disk and allow for faster copying of caches.
  • EXPLODEDEach tile is stored as an individual file (in the way caches were always stored prior to ArcGIS Server 10).
String
export_feature_class
(Optional)

A polygon feature class that defines where tiles are exported from the cache. This is useful if you want to export irregularly shaped areas.

Feature Class

Code Sample

This example uses ExportMapServerCache to export an entire map cache for four scales.

# Name: ExportMapServerCache.py
# Description: The following stand-alone script demonstrates how to export cache
#               for default number of scales of a service to a destination folder
# Requirements: os, sys, time and traceback modules
# Author: ESRI

# Any line that begins with a pound sign is a comment and will not be executed
# Empty quotes take the default value.
# To accept arguments from the command line replace values of variables to
#                                                           "sys.argv[]"

# Import system modules
import arcpy
from arcpy import env
import os, sys, time, datetime, traceback, string

# Set environment settings
env.workspace = "C:/data"

# List of input variables for map service properties
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
exportExtents = ""
scaleValues = [500000,250000,125000,64000]
destinationCacheDir = "C:/data/temp"
threadCount = "2"
storageFormat = "Exploded"

currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = 'C:/data/report_%s.txt' % arg1

# print results of the script to a report
report = open(file,'w')

# use "scaleValues[0]","scaleValues[-1]","scaleValues[0:3]"

try:
    starttime = time.clock()
    result = arcpy.ExportMapServerCache_server(server, service, dataFrame,
                                      destinationCacheDir, threadCount ,
                                      storageFormat, exportExtents,
                                      scaleValues)
    finishtime = time.clock()
    elapsedtime = finishtime - starttime

    #print messages to a file
    while result.status < 4:
        time.sleep(0.2)
    resultValue = result.getMessages()
    report.write ("completed " + str(resultValue))

    print " Exported cache successfully for mapservice " + service + " to "
    + destinationCacheDir + " in " + str(elapsedtime) + " sec \n on" + arg2

except Exception, e:
    # If an error occurred, print line number and error message
    tb = sys.exc_info()[2]
    report.write("Failed at step 1 \n" "Line %i" % tb.tb_lineno)
    report.write(e.message)
    
print "Exported Map server Cache "

report.close()

This example uses ExportMapServerCache to export a map cache based on the boundaries of a feature class.

# Name: ExportMapServerCache.py
# Description: The following stand-alone script demonstrates how to export cache
#               for default number of scales of a service to a destination folder
# Requirements: os, sys, time and traceback modules
# Author: ESRI

# Any line that begins with a pound sign is a comment and will not be executed
# Empty quotes take the default value.
# To accept arguments from the command line replace values of variables to
#                                                           "sys.argv[]"

# Import system modules
import arcpy
from arcpy import env
import os, sys, time, datetime, traceback, string

# Set environment settings
env.workspace = "C:/data"

# List of input variables for map service properties
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
exportExtents = ""
scaleValues = [500000,250000,125000,64000]
destinationCacheDir = "C:/data/temp"
threadCount = "2"
storageFormat = "Exploded"

currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = 'C:/data/report_%s.txt' % arg1

# print results of the script to a report
report = open(file,'w')

# use "scaleValues[0]","scaleValues[-1]","scaleValues[0:3]"

try:
    starttime = time.clock()
    result = arcpy.ExportMapServerCache_server(server, service, dataFrame,
                                      destinationCacheDir, threadCount ,
                                      storageFormat, exportExtents,
                                      scaleValues)
    finishtime = time.clock()
    elapsedtime = finishtime - starttime

    #print messages to a file
    while result.status < 4:
        time.sleep(0.2)
    resultValue = result.getMessages()
    report.write ("completed " + str(resultValue))

    print " Exported cache successfully for mapservice " + service + " to "
    + destinationCacheDir + " in " + str(elapsedtime) + " sec \n on" + arg2

except Exception, e:
    # If an error occurred, print line number and error message
    tb = sys.exc_info()[2]
    report.write("Failed at step 1 \n" "Line %i" % tb.tb_lineno)
    report.write(e.message)
    
print "Exported Map server Cache "

report.close()

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

5/9/2011