Import Map Server Cache (Server)

License Level:BasicStandardAdvanced

Summary

Imports tiles from a folder on disk into a map or image service cache. 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

Syntax

ImportMapServerCache_server (input_service, source_cache_type, {source_cache_dataset}, {source_tile_package}, {upload_data_to_server}, {scales}, {num_of_caching_service_instances}, {import_extent}, {area_of_interest}, {overwrite})
ParameterExplanationData Type
input_service

The map or image service into which tiles will be imported.

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. Then change the backslashes to forward slashes, for example, GIS Servers/arcgis on MYSERVER (admin)/USA.MapServer.

String
source_cache_type

Choose to import cache from a CACHE_DATASET or TILE_PACKAGE to a cached map or image service running on the server.

  • CACHE_DATASETMap or image service cache that is generated using ArcGIS Server. Usable in ArcMap 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 easily. Usable in ArcGIS for Desktop, as well as in ArcGIS Runtime and mobile applications.
String
source_cache_dataset
(Optional)

The path to the cache folder matching the data frame name. You do not have to enter a registered server cache directory; in fact, most of the time you'll enter 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 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/image service, the upload_data_to_server parameter is ignored as it will be automatically be 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, then moved to the server cache directory. This is by default enabled when storage_format_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)

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
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 the optional parameter on this tool Area Of Interest that allows you to spatially constrain the tiles imported using an irregular shape. If values are provided for both parameters, the Area Of Interest takes precedence over Import Extent.

Extent
area_of_interest
(Optional)

An area of interest polygon that spatially constrains where tiles are imported into the cache. This can be a feature class, or it can be a feature that you interactively define in ArcMap. 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 then import 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
overwrite
(Optional)
  • 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 behavior.
Boolean

Code Sample

Example 1

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.ImportMapServerCache_server(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, 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 "Imported Map server Cache Tiles "

report.close()

Example 2

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.ImportMapServerCache_server(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, 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(e.message)
report.close()

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

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
1/21/2015