Import Map Server Cache (Server)

Summary

Imports tiles from a folder on disk into a map cache. The source folder can be a child of a registered server cache directory or it can be some other folder into which tiles have been previously exported. The target map service must have the same tiling scheme and the storage format as the source map cache.

Usage

Syntax

ImportMapServerCache_Server (server_name, object_name, data_frame, source_cache_dataset, {import_extent}, {levels}, thread_count, {import_feature_class})
ParameterExplanationData Type
server_name

The ArcGIS Server machine hosting the service into which tiles will be imported.

String
object_name

The name of the map service into which tiles will be imported. This map service must have a tiling scheme defined that matches the tiling scheme of the tiles being imported.

String
data_frame

The source data frame for the map service.

String
source_cache_dataset

The path to the tiles that will be imported. This is represented by a raster dataset icon in the tool user interface. If you are scripting, it is the path to the cache folder matching the data frame name. You do not have to point this parameter at a registered server cache directory; in fact, most of the time you'll be pointing at a location on disk where tiles have been previously exported.

Raster Dataset
import_extent
(Optional)

A rectangular extent defining the tiles to be imported. 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 that allows you to alternatively constrain tile import to a feature class boundary.

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

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

Double
thread_count

Number of map service instances to use while importing 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
import_feature_class
(Optional)

A polygon feature class that defines where tiles are imported into the cache. This is useful if you want to import tiles for irregularly shaped areas.

Feature Class

Code Sample

To Import Map Cache using default values.

# ImportMapServerCache example (stand-alone script)

# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
#               server cache from a source directory to an existing service for 
#               the default number of scales specified
# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
cacheDir = "c:\\arcgisserver\\arcgiscache\\"
importExtents = ""
scaleValues = [500000,250000,125000,64000]
threadCount = "2"
sourceCache= "C:/data/destination_folder/Layers"
specifiedFeatureClass = "C:/data/94/Portland/Portland_Metro.shp"

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.ImportMapServerCache_server(server, service, dataFrame, sourceCache,
                                      threadCount, importExtents , scaleValues,
                                      specifiedFeatureClass )
    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 " + service + "  from "
    + sourceCache + " to " + cacheDir + service + "\n using "+ specifiedFeatureClass
    + " 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"



To Import Map Cache constrained along given feature class boundaries.

# ImportMapServerCache example (stand-alone script)

# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
#               server cache from a source directory to an existing service for 
#               the default number of scales specified
# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
cacheDir = "c:\\arcgisserver\\arcgiscache\\"
importExtents = ""
scaleValues = [500000,250000,125000,64000]
threadCount = "2"
sourceCache= "C:/data/destination_folder/Layers"
specifiedFeatureClass = "C:/data/94/Portland/Portland_Metro.shp"

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.ImportMapServerCache_server(server, service, dataFrame, sourceCache,
                                      threadCount, importExtents , scaleValues,
                                      specifiedFeatureClass )
    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 " + service + "  from "
    + sourceCache + " to " + cacheDir + service + "\n using "+ specifiedFeatureClass
    + " 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

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

5/9/2011