管理地图服务器缓存切片 (Server)

许可等级:BasicStandardAdvanced

摘要

在现有地图或影像服务缓存中创建和更新切片。此工具用于创建新切片、恢复缺失切片、覆盖过时切片以及删除切片。

用法

语法

ManageMapServerCacheTiles_server (input_service, scales, update_mode, {num_of_caching_service_instances}, {update_extent}, {area_of_interest}, {wait_for_job_completion})
参数说明数据类型
input_service

待更新缓存切片所属的地图或影像服务。

这是一个包含服务器和服务器信息的字符串。要查看构建此字符串的方法,请打开 ArcCatalog,选择“目录”树中的服务,并注意位置 工具条中的文本。然后将反斜线改为正斜线,例如,MYSERVER (admin)/USA.MapServer 上的 GIS Servers/arcgis

String
scales

一系列比例级别,运行此工具时将在这些比例级别上创建或删除切片(具体要取决于更新模式)。

Double
update_mode

缓存的更新模式。

  • RECREATE_EMPTY_TILES只重新创建空切片。现有切片将保持不变。
  • RECREATE_ALL_TILES如果范围发生改变,则需要更换现有切片并添加新切片。
  • DELETE_TILES将从缓存中删除切片。缓存文件夹结构不会删除。如果要删除包括文件夹结构在内的整个缓存,请使用删除地图服务器缓存工具。
String
num_of_caching_service_instances
(可选)

专用于运行该工具的系统/缓存工具服务实例的总数。您可以通过与 ArcGIS Server 的管理连接,使用 服务编辑器 窗口,增加系统/缓存工具服务的每台计算机的最大实例数。确保您的服务器计算机可以支持所选数量的实例。

Long
update_extent
(可选)

创建或删除切片时所参照的矩形范围,具体取决于 update_mode 参数的值。建议不要同时提供 update_extentarea_of_interest 两个参数的值。如果同时提供了这两个参数的值,则会使用 area_of_interest 的值。

Extent
area_of_interest
(可选)

定义感兴趣区以对将创建或删除的切片进行约束。它可能是一个要素类,也可能是在 ArcMap 中以交互方式定义的要素。该参数用于为形状不规则的区域管理切片。它对您要对某些区域进行预缓存或让较少访问的区域保持未缓存的状态等情形也同样有用。

若未提供该参数的值,则会默认使用地图的全图范围。

Feature Set
wait_for_job_completion
(可选)

可以通过该参数查看在服务器上运行的缓存作业的进度。

  • WAIT该工具将继续在 ArcGIS for Desktop 中运行,同时缓存作业在 ArcGIS for Server 或 ArcGIS Online 上运行。使用此选项,您可以随时请求详细的进度报告并查看显示的地理处理消息。这是默认选项。建议在 Python 脚本中使用此选项。
  • DO_NOT_WAIT地理处理工具会将作业提交至服务器,让您可以在 ArcGIS for Desktop 或类似 ArcGIS for Desktop 的程序中执行其它地理处理任务。在您选择在发布服务之际自动构建缓存时使用此选项,您还可在您所构建的任何其他缓存中设置此选项。要追踪缓存作业的状态,请打开 ArcGIS for Desktop,右键单击目录 窗口中的服务,然后单击查看缓存状态。您也可以使用工具生成消息中所提供的 URL。如果服务缓存目录中不存在 Status.gdb 文件地理数据库,则此选项不可用。
Boolean

代码实例

示例 1

使用 RECREATE_ALL_TILES 选项在缓存中创建或更新所有切片

# 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

# 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
scales = ""
numOfCachingServiceInstances = 2
updateMode = "RECREATE_ALL_TILES"
areaOfInterest = ""
waitForJobCompletion = "WAIT"
updateExtents = ""

currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = r'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(inputService, scales,
                                                    updateMode,
                                                    numOfCachingServiceInstances,
                                                    areaOfInterest, updateExtents,
                                                    waitForJobCompletion)
    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 "
    serviceName + " 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 "

示例 2

使用 RECREATE_EMPTY_TILES 选项更新部分比例的空切片

# 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

# 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
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = 2
updateMode = "RECREATE_EMPTY_TILES"
areaOfInterest = ""
waitForJobCompletion = "WAIT"
updateExtents = ""
cacheDir = "c:\\arcgisserver\\arcgiscache\\"

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.ManageMapServerCacheTiles_server(inputService, scales[-1],
                                                    updateMode, numOfCachingServiceInstances,
                                                    areaOfInterest, updateExtents,
                                                    waitForJobCompletion)
    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(scales[-1]) + "for "
    serviceName + "\n   at " + cacheDir + " 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])

示例 3

使用“感兴趣区”更新切片

# ManageMapServerCacheTiles example for ArcGIS Server 10.1(stand-alone script)

# Name: ManageMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to Recreate all
#               tiles using 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
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = 2
updateMode = "RECREATE_ALL_TILES"
areaOfInterest = "C:/data/shp/CaTxFlMaMin.shp"
waitForJobCompletion = "WAIT"
updateExtents = ""


currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = r'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.ManageMapServerCacheTiles_server(inputService, scales[-1],
                                                    updateMode,
                                                    numOfCachingServiceInstances,
                                                    areaOfInterest, updateExtents,
                                                    waitForJobCompletion)                                           
    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(scales[-1]) + "for "
    serviceName + "at " + cacheDir + "\n using specified feature class "
    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 \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 area of Interest"

环境

此工具不使用任何地理处理环境

相关主题

许可信息

ArcGIS for Desktop Basic:是
ArcGIS for Desktop Standard:是
ArcGIS for Desktop Advanced:是
9/15/2013