ArcGIS Desktop

  • Documentation
  • Support

  • My Profile
  • Help
  • Sign Out
ArcGIS Desktop

ArcGIS Online

The mapping platform for your organization

ArcGIS Desktop

A complete professional GIS

ArcGIS Enterprise

GIS in your enterprise

ArcGIS for Developers

Tools to build location-aware apps

ArcGIS Solutions

Free template maps and apps for your industry

ArcGIS Marketplace

Get apps and data for your organization

  • Documentation
  • Support
Esri
  • Sign In
user
  • My Profile
  • Sign Out

ArcMap

  • Home
  • Get Started
  • Map
  • Analyze
  • Manage Data
  • Tools
  • Extensions

Export Map Server Cache

  • Summary
  • Usage
  • Syntax
  • Code sample
  • Environments
  • Licensing information

Summary

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

Usage

    Note:

    Parameters have changed for this tool at version 10.1. Models and scripts written prior to 10.1 that use this tool will need to be modified to work in 10.1.

    When moving to 10.1 Service Pack 1, you must open and validate any models that use this tool because it has a new parameter. This process is described in Automating cache creation and updates with geoprocessing.

  • Before running this tool, create the folder on disk that will hold the exported tiles.

  • The Overwrite Tiles parameter was added to this tool at 10.1 Service Pack 1 and allows the exported tiles to completely overwrite the tiles in the destination cache, rather than blending the images. Exported tiles can still be constrained to an area of interest.

Syntax

ExportMapServerCache_server (input_service, target_cache_path, export_cache_type, copy_data_from_server, storage_format_type, scales, {num_of_caching_service_instances}, {area_of_interest}, {export_extent}, {overwrite})
ParameterExplanationData Type
input_service

The map or image service whose cache tiles will be exported.

This is a string containing both the server and service information. To see how to construct this string, open ArcCatalog, select your service in the Catalog tree, and note the text in the Location toolbar. Change the backslashes to forward slashes, for example, GIS Servers/arcgis on MYSERVER (admin)/USA.MapServer.

Image Service; MapServer
target_cache_path

The folder into which the cache will be exported. This folder does not have to be a registered server cache directory. The ArcGIS Server account must have write access to the target cache folder. If the server account cannot be granted write access to the destination folder but the ArcGIS Desktop, ArcGIS Pro or client has write access to it, then choose the Copy data from server parameter.

Folder
export_cache_type

Choose to export cache as a cache dataset or a tile package. Tile packages are suitable for ArcGIS Runtime and ArcGIS Mobile deployments.

  • CACHE_DATASET —Map or image service cache that is generated using ArcGIS Server. Usable in ArcMap and by ArcGIS Server map or image services. This is the default.
  • TILE_PACKAGE —A single compressed file where the cache dataset is added as a layer and consolidated so that it can be shared easily. Usable in ArcGIS Desktop, as well as in ArcGIS Runtime and mobile applications.
String
copy_data_from_server

Set this option to COPY_DATA if the ArcGIS Server account cannot be granted write access to the target folder and the ArcGIS Desktop or ArcGIS Pro client has write access to it. The software exports the tiles in the server output directory before moving them to the target folder.

  • COPY_DATA —Tiles are placed in the server output directory, then moved to the target folder. The ArcGIS Desktop or ArcGIS Pro client must have write access to the target folder.
  • DO_NOT_COPY —Tiles are exported directly into the target folder. The ArcGIS Server account must have write access to the target folder. This is the default.
Boolean
storage_format_type

The storage format of the exported cache.

  • COMPACT —Tiles are grouped in bundle files to save space on disk and allow for faster copying of caches. This is the default, if Export cache type (export_cache_type in Python) is Tile package.
  • EXPLODED —Each tile is stored as an individual file (in the way caches were always stored prior to ArcGIS Server).
String
scales
[scales,...]

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

By default, the scales listed in the tool dialog are between the minimum and maximum cached scales for the service. To update the scale range go to the Service Editor > Caching tab and use the sliders to update the minimum and maximum cached scales.

Double
num_of_caching_service_instances
(Optional)

The total number of instances of the System/CachingTools service that you want to dedicate toward running this tool. You can increase the maximum number of instances per machine of the System/CachingTools service using the Service Editor window available through an administrative connection to ArcGIS Server. Ensure your server machines can support the chosen number of instances.

Long
area_of_interest
(Optional)

An area of interest (polygon) that spatially constrains where tiles are exported from the cache. This parameter is useful if you want to export irregularly shaped areas, as the tool clips the cache dataset at pixel resolution.

If you do not specify an area of interest, the full extent of the map is exported.

Feature Set
export_extent
(Optional)

A rectangular extent defining the tiles to be exported. By default the extent is set to the full extent of the map service into which you are importing. Note the optional parameter on this tool Area of Interest that allows you to alternatively import using a polygon. It is recommended not to provide values for both the parameters for a job. If values are provided for both parameters, the Area of Interest takes precedence over Import Extent

Extent
overwrite
(Optional)
  • OVERWRITE —The export replaces all pixels in the area of interest, effectively overwriting tiles in the destination cache with tiles from the originating cache.
  • MERGE —When the tiles are imported, transparent pixels in the originating cache are ignored by default. This results in a merged or blended image in the destination cache. This is the default.
Boolean

Derived Output

NameExplanationData Type
output_cache_path

Code sample

ExportMapServerCache example 1 (stand-alone script)

Export cache tiles for a feature class while changing the storage format from EXPLODED to COMPACT.

# Name: ExportMapServerCache.py for ArcGIS Server 
# Description: The following stand-alone script demonstrates how to export 
# cache as CACHE_DATASET in COMPACT storage format and MERGE tiles using
# an AREA_OF_INTEREST to TARGET_CACHE_PATH which is accessible to server
# instances 

# Requirements: os, sys, time and traceback modules
# 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
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server 			= "arcgis on MyServer_6080 (publisher)"
serviceName 		= "Rainfall.MapServer"
inputService 		= connectionFile + "\\" + server + "\\" + serviceName
targetCachePath 	= "C:/data/temp"
exportCacheType 	= "CACHE_DATASET"
copyDataFromServer 	= "DO_NOT_COPY"
storageFormat 		= "COMPACT"
scales 			= [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
areaOfInterest 		= "C:/data/101/Portland/Metro.shp"
exportExtents 		= ""
overwriteTiles 		= "MERGE"

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]"

# Enter rectangular custom extent values for the "exportExtents" variable to
# constrain the exporting cache along the rectangular extents

try:
    starttime = time.clock()
    result = arcpy.ExportMapServerCache_server(inputService, targetCachePath,
                                               exportCacheType,
                                               copyDataFromServer,
                                               storageFormat, scales, 
                                               numOfCachingServiceInstances, 
                                               areaOfInterest, exportExtents, 
					       overwriteTiles)
    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 " + serviceName +\
    " to " + targetCachePath + "\n using " + areaOfInterest + "\n 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 \n" "Line %i" % tb.tb_lineno)
    report.write(e.message)

print "Exported Map server Cache  using area of Interest"

report.close()
ExportMapServerCache example 2 (stand-alone script)

Export cache as a TILE_PACKAGE when the destination folder is inaccessible to ArcGIS Server instances.

# Name: ExportMapServerCache.py
# Description: The following stand-alone script demonstrates how to export cache
# as TILE_PACKAGE for default number of scales of a service, to a 
# TARGET_CACHE_PATH which is inaccessible to server instances using
# COPY_DATA_FROM_SERVER

# Requirements: os, sys, time and traceback modules

# 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
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server = "arcgis on MyServer_6080 (publisher)"
serviceName = "Rainfall.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
targetCachePath = "C:/temp/usa"
exportCacheType = "TILE_PACKAGE"
copyDataFromServer = "COPY_DATA"
storageFormat = "COMPACT"
scaleValues = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
exportExtents = ""
areaOfInterest = ""
overwriteTiles = "MERGE"

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(inputService, targetCachePath,
                                               exportCacheType,
                                               copyDataFromServer,
                                               storageFormat, scales,
                                               numOfCachingServiceInstances,
                                               areaOfInterest,
                                               exportExtents, overwriteTiles)
    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 " + serviceName +\
    + " to " + targetCachePath + " 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.

Licensing information

  • ArcGIS Desktop Basic: Yes
  • ArcGIS Desktop Standard: Yes
  • ArcGIS Desktop Advanced: Yes

Related topics

  • An overview of the Caching toolset

ArcGIS Desktop

  • Home
  • Documentation
  • Support

ArcGIS Platform

  • ArcGIS Online
  • ArcGIS Desktop
  • ArcGIS Enterprise
  • ArcGIS for Developers
  • ArcGIS Solutions
  • ArcGIS Marketplace

About Esri

  • About Us
  • Careers
  • Esri Blog
  • User Conference
  • Developer Summit
Esri
Tell us what you think.
Copyright © 2019 Esri. | Privacy | Legal