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
This tool may take a long time to run for caches that cover a large geographic extent or very large map scales. If the tool is cancelled, tile creation is stopped, but the existing tiles are not deleted. This means you can cancel the tool if you run out of time and re-run it later on the same cache using the "Recreate Empty Tiles" update mode. Another way you can continue where you've left off is to use the status tracking described below in the description of the final parameter Ignore Status.
Syntax
Parameter | Explanation | Data 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. Note: 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:
| 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).
| 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"