Manage Map Server Cache Tiles (Server)

Summary

Creates and updates tiles in an existing map service cache. This tool is used to create new tiles, replace missing tiles, overwrite outdated tiles, and delete tiles.

Usage

Syntax

ManageMapServerCacheTiles_Server (server_name, object_name, data_frame, Layer, levels, update_mode, {constraining_extent}, {thread_count}, {Antialiasing}, {update_feature_class}, {ignore_status})
ParameterExplanationData Type
server_name

The ArcGIS Server machine hosting the map service whose tiles you want to update.

String
object_name

The map service whose cache tiles you want to update.

NoteNote:

Make sure you have a tiling scheme defined for your map service before using this tool. You can use the Caching tab of the Service Properties dialog box or the Create Map Server Cache tool to create the tiling scheme.

String
data_frame

The source data frame for the map service.

String
Layer
[Layer,...]

Layers to remove from the cache.

String
levels

The scale levels at which you will create or delete tiles when running this tool, depending on the Update Mode.

Double
update_mode

Choose a mode for updating the cache. The three modes are:

  • Recreate Empty TilesOnly tiles that are empty will be created. Existing tiles will be left unchanged.
  • Recreate All TilesExisting tiles will be replaced and new tiles will be added if the extent has changed or if layers have been added to a multilayer cache.
  • Delete TilesTiles will be deleted from the cache. The cache folder structure will not be deleted. If you wish to delete the entire cache, including the folder structure, use the Delete Map Server Cache tool.
String
constraining_extent
(Optional)

Rectangular extent at which to create or delete tiles, depending on the Update Mode.

Extent
thread_count
(Optional)

Number of map service instances to use while running this tool. 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's Service Properties dialog box, then raise this parameter when you run the tool.

Long
Antialiasing
(Optional)

This is a deprecated parameter that is ignored. The antialiasing property in your tiling scheme determines if antialiasing is applied to the cache.

Boolean
update_feature_class
(Optional)

You can use a polygon feature class to manage tiles (create, update, or delete) based on the extents of features of a feature class. For example, if you are caching a country, you might supply a feature class of major urban areas. By doing so, you are requesting that the server only pre-create tiles that cover those urban areas. The rest of the areas can be cached on demand when requested by clients. This can save you time and disk space that would be consumed by creating unneeded tiles in rural areas.

Feature Class
ignore_status
(Optional)

This parameter allows you to track the status of your caching if you are creating tiles based on feature class boundaries (see the update_feature_class parameter).

  • IGNORE_COMPLETION_STATUS_FIELDThe feature class's Completed field is ignored and tiles are created for all features in the feature class. This is the default.
  • TRACK_COMPLETION_STATUSThe feature class's Completed field is read (and created if it doesn't exist yet). Features marked No or null in this field are cached and marked Yes when caching has completed for the feature. Features already marked Yes in this field are not cached.
Boolean

Code Sample

This example creates or updates all the tiles in the cache using the "Recreate All" option.

# ManageMapServerCacheTiles example (stand-alone script)

# Name: ManageMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to Recreate all 
#               cache tiles for the default number of scales in the cache tiling
#               scheme.
# 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 = "" 
inputLayers = ""
scaleValues = ""
extents = ""
updateMode = "Recreate All Tiles"
antialiasing = "NONE"
threadCount = "2"
pathToFeatureClass = ""
ignoreStatus = "IGNORE_COMPLETION_STATUS_FIELD"

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')

try:
    starttime = time.clock()
    result = arcpy.ManageMapServerCacheTiles_server(server, service, dataFrame,
                                           inputLayers, scaleValues, updateMode,
                                           extents, threadCount ,Antialiasing,
                                           pathToFeatureClass, ignoreStatus)
    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 "Created cache tiles for given schema successfully for "
    + service + " 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)
report.close()
    
print "Created Map server Cache Tiles "

This example updates empty tiles for some of the scales using the "Recreate Empty Tiles" option.

# ManageMapServerCacheTiles example (stand-alone script)

# Name: ManageMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to Recreate  
#               empty tiles for one of the default number of scales in the cache
#               tiling scheme.
# 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 = ""
inputLayers = "" 
scaleValues = [500000,250000,125000,64000]
extents = ""
updateMode = "Recreate Empty Tiles"
antialiasing = "NONE"
threadCount = "2"
pathToFeatureClass = ""
cacheDir = "c:\\arcgisserver\\arcgiscache\\"
ignoreStatus = "IGNORE_COMPLETION_STATUS_FIELD"

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.ManageMapServerCacheTiles_server(server, service, dataframe,
                                           inputLayers, scaleValues[-1],
                                           updateMode, extents ,
                                           threadCount ,antialiasing,
                                           pathToFeatureClass, ignoreStatus)
    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 "Created cache tiles for scale =" + str(scaleValues[-1]) + "for "
    + service + "\n   at " + cacheDir + service + " 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)
    
report.close()   
print "Rereated Map server Cache Tiles for scale = " + str(scaleValues[-1])

This example constrains the update of tiles to the boundaries of a feature class.

# ManageMapServerCacheTiles example (stand-alone script)

# Name: ManageMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to Recreate all
#               tiles using given feature class with "Track completion status"  
#               turned on.

# 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\\"
inputLayers = ""
extents = ""
scaleValues = [500000,250000,125000,64000]
updateMode = "Recreate All Tiles"
antialiasing = "Antialiasing"
threadCount = "2"
pathToFeatureClass = "C:/data/shp/CaTxFlMaMin.shp"
ignoreStatus = "TRACK_COMPLETION_STATUS"

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.ManageMapServerCacheTiles_server(server, service, dataFrame, 
                                           inputLayers, scaleValues[-1],
                                           updateMode, extents ,
                                           threadCount ,antialiasing,
                                           pathToFeatureClass,ignoreStatus)                                           
    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 "Created cache tiles for scale =" + str(scaleValues[-1]) + "for "
    + service + "at " + cacheDir + service + "\n using specified feature class "
    + pathToFeatureClass + " 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 3 \n" "Line %i" % tb.tb_lineno)
    report.write(e.message)

report.close()     
print "Rereated Map server Cache Tiles"
print "for scale = " + str(scaleValues[-1]) + " using specified feature class"

Environments

This tool does not use any geoprocessing environments

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

5/9/2011