Export Map Server Cache (Server)

Summary

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

Usage

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

  • The ArcGIS Server account must have write access to the target cache folder. If the ArcGIS Server account cannot be granted write access to the target cache folder, but the ArcGIS Pro client has write access to it, choose the Copy data from server (copy_data_from_server) parameter.

  • The Overwrite Tiles parameter 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.

Parameters

LabelExplanationData Type
Input Service

The map image layer with the cache tiles to be exported. You can choose it by browsing to the desired service in a portal or you can drag a web tile layer from the Portal tab in the Project pane to supply this parameter.

Image Service; Map Server
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 or ArcGIS Pro client has write access to it, choose the Copy data from server parameter.

Folder
Export cache type

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

  • Cache dataset —A map or image service cache that is generated using ArcGIS Server. It can be used in ArcGIS Desktop 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. In can be used in ArcGIS Desktop, ArcGIS Runtime, and mobile apps.
String
Copy data from server

Check this parameter only 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.

  • Checked—Tiles are placed in the server output directory and are then moved to the target folder. The ArcGIS Desktop client must have write access to the target folder.
  • Unchecked—Tiles are exported directly into the target folder. The ArcGIS Server account must have write access to the target folder.
Boolean
Storage Format Type

The storage format of the exported cache.

  • Compact — Tiles are grouped in bundle and bundlex files to save space on disk and allow for faster copying of caches. If the Export cache type parameter is set to Tile package, this is the default.
  • Compact V2 — Tiles are grouped in bundle files only. This format provides better performance on network shares and cloudstore directories. If the Export cache type parameter is set to Tile package then the extension of the tile package is (.tpkx),which is supported by newer versions of the ArcGIS Platform such as ArcGIS Online, ArcGIS Enterprise 10.9 and ArcGIS Runtime 100.5.
  • Exploded —Each tile is stored as an individual file (the way caches were stored prior to ArcGIS Server).
String
Scales

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

Double
Number of caching service instances
(Optional)

Specifies the number of instances that will be used to update or generate the tiles. The value for this parameter is set to unlimited (-1) and cannot be modified.

Long
Area Of Interest
(Optional)

An area of interest 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 that the optional parameter on this tool, Area Of Interest, allows you to alternatively import using a polygon. It is recommended that you not provide values for both parameters for a job. If values are provided for both parameters, the Area Of Interest parameter takes precedence over Import Extent.

  • Default—The extent will be based on the maximum extent of all participating inputs. This is the default.
  • Current Display Extent—The extent is equal to the data frame or visible display. The option is not available when there is no active map.
  • As Specified Below—The extent will be based on the minimum and maximum extent values specified.
  • Browse—The extent will be based on an existing dataset.
Extent
Overwrite Tiles
(Optional)

Specifies whether the images in the receiving cache will be merged with the tiles from the originating cache or overwritten by them.

  • Checked—The export replaces all pixels in the area of interest, effectively overwriting tiles in the destination cache with tiles from the originating cache.
  • Unchecked—When the tiles are exported, 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

LabelExplanationData Type
Output Cache Path

The folder into which the cache has been exported.

String

arcpy.server.ExportMapServerCache(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})
NameExplanationData Type
input_service

The map image layer with the cache tiles to be exported.

Image Service; Map Server
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 or ArcGIS Pro client has write access to it, choose the Copy data from server parameter.

Folder
export_cache_type

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

  • CACHE_DATASETA map or image service cache that is generated using ArcGIS Server. It can be used in ArcGIS Desktop and by ArcGIS Server map or image services. This is the default.
  • TILE_PACKAGEA single compressed file where the cache dataset is added as a layer and consolidated so that it can be shared. In can be used in ArcGIS Desktop, ArcGIS Runtime, and mobile apps.
String
copy_data_from_server

Set this parameter 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_DATATiles are placed in the server output directory and are then moved to the target folder. The ArcGIS Desktop or ArcGIS Pro client must have write access to the target folder.
  • DO_NOT_COPYTiles 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 and bundlex files to save space on disk and allow for faster copying of caches. If the export_cache_type parameter is set to Tile package, this is the default.
  • COMPACT_V2 Tiles are grouped in bundle files only. This format provides better performance on network shares and cloudstore directories. If the export_cache_type parameter is set to Tile package then the extension of the tile package is (.tpkx),which is supported by newer versions of the ArcGIS Platform such as ArcGIS Online, ArcGIS Enterprise 10.9 and ArcGIS Runtime 100.5.
  • EXPLODEDEach tile is stored as an individual file (the way caches were stored prior to ArcGIS Server).
String
scales
[scales,...]

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

Double
num_of_caching_service_instances
(Optional)

Specifies the number of instances that will be used to update or generate the tiles. The value for this parameter is set to unlimited (-1) and cannot be modified.

Long
area_of_interest
(Optional)

An area of interest 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 that the optional parameter on this tool, Area Of Interest, allows you to alternatively import using a polygon. It is recommended that you not provide values for both parameters for a job. If values are provided for both parameters, the Area Of Interest parameter takes precedence over Import Extent.

  • MAXOF—The maximum extent of all inputs will be used.
  • MINOF—The minimum area common to all inputs will be used.
  • DISPLAY—The extent is equal to the visible display.
  • Layer name—The extent of the specified layer will be used.
  • Extent object—The extent of the specified object will be used.
  • Space delimited string of coordinates—The extent of the specified string will be used. Coordinates are expressed in the order of x-min, y-min, x-max, y-max.
Extent
overwrite
(Optional)

Specifies whether the images in the receiving cache will be merged with the tiles from the originating cache or overwritten by them.

  • OVERWRITEThe export replaces all pixels in the area of interest, effectively overwriting tiles in the destination cache with tiles from the originating cache.
  • MERGEWhen 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

The folder into which the cache has been exported.

String

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 as 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(str(e))

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 as 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(str(e))

print("Exported Map server Cache ")

report.close()

Environments

This tool does not use any geoprocessing environments.

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics