Import Map Server Cache (Server)

Summary

The source folder can be a child of a registered server cache directory, a folder into which a cache has been previously exported, or a tile package (.tpk).The target service must have the same tiling scheme and the storage format as the source cache.

Usage

  • Use this tool to import all or portions of a cache from one folder to another.

  • The Overwrite Tiles parameter allows the imported tiles to completely overwrite the existing tiles, rather than blending the images. Imported tiles can still be constrained to an area of interest.

Parameters

LabelExplanationData Type
Input Service
Image Service; Map Server
Source Cache Type

Imports a cache from a cache dataset or tile package to a cached map or image service running on the server.

  • 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.
  • TILE_PACKAGEA single compressed file where the cache dataset is added as a layer and consolidated so that it can be shared. It can be used in ArcGIS Desktop, ArcGIS Runtime, and mobile apps.
String
Source Cache Dataset
(Optional)

The path to the tiles that will be imported. This is represented by a raster dataset icon when you are browsing. You do not have to specify a registered server cache directory; most of the time you'll specify a location on disk where tiles have been previously exported. This location should be accessible to the ArcGIS Server account. If the ArcGIS Server account cannot be granted access to this location, check the Upload data to server parameter.

Raster Dataset
Source Tile Package
(Optional)

The path to the tile package that will be imported. This location should be accessible to the ArcGIS Server account. Importing a tile package file to a cached map or image service automatically enables the Upload data to server parameter.

File
Upload data to server
(Optional)

Check this parameter if the ArcGIS Server account does not have read access to the source cache. The tool will upload the source cache to the ArcGIS Server uploads directory before moving it to the ArcGIS Server cache directory.

  • Checked—Tiles are placed in the server uploads directory and are then moved to the server cache directory. This is active by default when the Source Cache Type parameter is set to TILE_PACKAGE.
  • Unchecked—Tiles are imported directly into the server cache directory. The ArcGIS Server account must have read access to the source cache.
Boolean
Scales
(Optional)

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

By default, the scales listed in the tool dialog box 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
Number of caching service instances
(Optional)
Long
Area Of Interest
(Optional)

An area of interest polygon that spatially constrains where tiles are imported into the cache. This parameter is useful if you want to import tiles for irregularly shaped areas, as the tool clips the cache dataset, which intersects the polygon at pixel resolution and imports it to the service cache directory.

If you do not provide a value for this parameter, the value of the Import Extent parameter will be used. The default is to use the full extent of the map.

Feature Set
Import Extent
(Optional)

A rectangular extent defining the tiles to be imported into the cache. 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 spatially constrain the imported tiles using an irregular shape. If values are provided for both parameters, the Area Of Interest parameter takes precedence over Import Extent.

  • Current Display Extent Map View—The extent will be based on the active map or scene. This option is only available when there is an active map.
  • Draw Extent Draw Extent—The extent will be based on a rectangle drawn on the map or scene. This option will create a feature class in the project geodatabase and add a layer to the map. The feature class will have the same coordinate system as the map.
    Note:

    This option is not available in the Environments dialog box. It is only available from a tool parameter with an extent data type or from the Environments tab on a tool dialog box.

    Note:

    When the Enable and disable editing from the Edit tab editing option is checked, you must enable editing on the Edit ribbon tab to draw the extent.

  • Extent of a Layer Layer—The extent will be based on an active map layer. Use the drop-down list to choose an available layer or use the Extent of data in all layers option to get the combined extent of all active map layers, excluding the basemap. This option is only available when there is an active map with layers.

    Each map layer has the following options:

    • All Features Select All—The extent of all features in the layer.
    • Selected Features Area from Selected Features—The extent of the selected features in the layer.
    • Visible Features Extent Indicator—The extent of the visible features in the layer.
      Note:

      The extents from the Selected Features Area from Selected Features and Visible Features Extent Indicator options are only available for feature layers.

  • Browse Browse—The extent will be based on an existing dataset.
  • Clipboard Paste—The extent can be copied to and pasted from the clipboard.
    • Copy Extent Copy—Copies the extent coordinates and coordinate system to the clipboard.
    • Use Paste Extent Paste—Pastes the extent coordinates and, optionally, the coordinate system from the clipboard. If the clipboard values do not include a coordinate system, the extent will use the map’s coordinate system.
    Note:

    The extent coordinates are copied to and pasted from the clipboard using the same formatting and order as the ArcPy Extent object: x-min, y-min, x-max, y-max, and the spatial reference.

  • Reset Extent Reset—The extent will be reset to the default value.
  • Manually entered coordinates—The coordinates must be numeric values and in the active map's coordinate system.
    Caution:

    The map may use different display units than the entered coordinates. The use of a cardinal direction (N, S, E, W) is not supported. Use a negative value sign for south and west coordinates.

Extent
Overwrite Tiles
(Optional)

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

  • Checked—The import 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 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

LabelExplanationData Type
Output Map Service URL

The output URL.

String

arcpy.management.ImportMapServerCache(input_service, source_cache_type, {source_cache_dataset}, {source_tile_package}, {upload_data_to_server}, {scales}, {num_of_caching_service_instances}, {area_of_interest}, {import_extent}, {overwrite})
NameExplanationData Type
input_service
Image Service; Map Server
source_cache_type

Imports a cache from a cache dataset or tile package to a cached map or image service running on the server.

  • 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.
  • TILE_PACKAGEA single compressed file where the cache dataset is added as a layer and consolidated so that it can be shared. It can be used in ArcGIS Desktop, ArcGIS Runtime, and mobile apps.
String
source_cache_dataset
(Optional)

The path to the cache folder matching the data frame name. You do not have to specify a registered server cache directory; most of the time you'll specify a location on disk where tiles have been previously exported. This location should be accessible to the ArcGIS Server account. If the ArcGIS Server account cannot be granted access to this location, set the upload_data_to_server parameter to UPLOAD_DATA.

Raster Dataset
source_tile_package
(Optional)

The path to the tile package (.tpk) that will be imported. This location should be accessible to the ArcGIS Server account. When importing a tile package file to a cached map or image service, the upload_data_to_server parameter is ignored as it is automatically set to UPLOAD_DATA.

File
upload_data_to_server
(Optional)

Set this parameter to UPLOAD_DATA if the ArcGIS Server account does not have read access to the source cache. The tool will upload the source cache to the ArcGIS Server uploads directory before moving it to the ArcGIS Server cache directory.

  • UPLOAD_DATATiles are placed in the server uploads directory and are then moved to the server cache directory. This is enabled by default when source_cache_type is TILE_PACKAGE.
  • DO_NOT_UPLOADTiles are imported directly into the server cache directory. The ArcGIS Server account must have read access to the source cache.
Boolean
scales
[scales,...]
(Optional)

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

Double
num_of_caching_service_instances
(Optional)
Long
area_of_interest
(Optional)

An area of interest polygon that spatially constrains where tiles are imported into the cache. This parameter is useful if you want to import tiles for irregularly shaped areas, as the tool clips the cache dataset, which intersects the polygon at pixel resolution and imports it to the service cache directory.

If you do not provide a value for this parameter, the value of the Import Extent parameter will be used. The default is to use the full extent of the map.

Feature Set
import_extent
(Optional)

A rectangular extent defining the tiles to be imported into the cache. 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 spatially constrain the imported tiles using an irregular shape. 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 destination cache will be merged with the tiles from the originating cache or overwritten by them.

  • OVERWRITEThe import 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
out_job_url

The output URL.

String

Code sample

ImportMapServerCache example 1 (stand-alone script)

Import a cache dataset to a cached service for the default number of scales. Tiles in the receiving cache will be overwritten by the tiles being imported.

# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
#               server cache from a source directory with CACHE_DATASET and
#               OVERWRITE existing cache on the service for the number
#               of scales specified without Uploading data to 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
sourceCacheType     = "CACHE_DATASET"
sourceCacheDataset  = "C:/data/destination_folder/Layers"
sourceTilePackage   = ""
uploadDataToServer  = "DO_NOT_UPLOAD"
scales              = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
areaOfInterest      = ""
importExtents       = ""
overwriteTiles      = "OVERWRITE"

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 "scales[0]","scales[-1]","scales[0:3]"

try:
    starttime = time.clock()
    result = arcpy.server.ImportMapServerCache(inputService, sourceCacheType,
                                               sourceCacheDataset,
                                               sourceTilePackage,
                                               uploadDataToServer, scales,
                                               numOfCachingServiceInstances,
                                               areaOfInterest, importExtents,
                                               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("Imported Map server Cache Tiles successfully for" + serviceName + \
        " from" + sourceCacheDataset + "\n in " + str(elapsedtime)+ "sec 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("Imported Map server Cache Tiles ")

report.close()
ImportMapServerCache example 1 (stand-alone script)

Import cache tiles for an area of interest from a tile package into a cache service.

# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
#               server cache from a source directory with Tile Package to an existing service for
#               the default number of scales specified using an AOI by uploading data to remote server
# To Import cache tiles for the scales specified for given feature class

# 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
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server = "arcgis on MyServer_6080 (publisher)"
serviceName = "Rainfall.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
sourceCacheType = "TILE_PACKAGE"
sourceCacheDataset = ""
sourceTilePackage = "C:\\data\\destination_folder\\TPK\\Rainfall.tpk"
uploadDataToServer = "UPLOAD_DATA"
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
cacheDir = "c:\\arcgisserver\\arcgiscache"
areaOfInterest = "C:/data/101/Portland/Portland_Metro.shp"
importExtents = ""
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 "scales[0]","scales[-1]","scales[0:3]"

try:
    starttime = time.clock()
    result = arcpy.server.ImportMapServerCache(inputService, sourceCacheType,
                                               sourceCacheDataset,
                                               sourceTilePackage,
                                               uploadDataToServer, scales,
                                               numOfCachingServiceInstances,
                                               areaOfInterest, importExtents,
					       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("Imported Map server Cache Tiles successfully for " + serviceName + \
        " from " + sourceTilePackage + " to " + cacheDir + "\n using "+ areaOfInterest + \
        " 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 2 \n" "Line %i" % tb.tb_lineno)
    report.write(str(e))

report.close()

print("Imported Map server Cache Tiles for the given feature class")

Environments

This tool does not use any geoprocessing environments.