导出地图服务器缓存 (Server)
摘要
将地图或影像服务缓存的切片作为缓存数据集或切片包导出至磁盘上的文件夹中。切片可导入至其他缓存中,也可以以独立于其父服务的方式,作为一个栅格数据集从 ArcGIS for Desktop 或移动设备中进行访问。
用法
运行此工具前,请在磁盘上创建文件夹,以保存导出的切片。
ArcGIS Server 帐户必须拥有对目标缓存文件夹的写入权限。如果无法向 ArcGIS Server 帐户授予目标缓存文件夹的写入权限,但 ArcGIS for Desktop 客户端拥有目标缓存文件夹的写入权限,请选择从服务器复制数据 (copy_data_from_server) 参数。
在 10.1 Service Pack 1 中,向该工具中添加了“覆盖切片 (Overwrite Tiles)”参数,此参数允许导出的切片完全覆盖目标缓存中的切片,而不是混合图像。仍可将导出的切片限制在感兴趣区域。
在 10.1 版本中,此工具的各个参数都发生了变化。在 10.1 版本之前使用该工具编写的模型或脚本均需要经过修改才能在 10.1 版本中使用。
在迁移至 10.1 Service Pack 1 时,必须打开并验证使用该工具的模型,因为该工具具有新参数。此过程将在使用地理处理工具自动执行缓存创建和更新中进行说明。
语法
参数 | 说明 | 数据类型 |
input_service | 要导出缓存切片的地图或影像服务。 这是一个包含服务器和服务器信息的字符串。要查看构建此字符串的方法,请打开 ArcCatalog,选择“目录”树中的服务,并注意位置 工具条中的文本。然后将反斜线改为正斜线,例如,MYSERVER (admin)/USA.MapServer 上的 GIS Servers/arcgis。 | String |
target_cache_path |
缓存将被导出到的目标文件夹。此文件夹不必是一个已注册的服务器缓存目录。ArcGIS Server 帐户必须拥有对目标缓存文件夹的写入权限。如果无法对服务器帐户授予目标文件夹的写入权限,但 ArcGIS for Desktop 客户端拥有目标文件夹的写入权限,请选择从服务器复制数据参数。 | Folder |
export_cache_type |
选择将缓存作为缓存数据集或切片包导出。切片包适用于 ArcGIS Runtime 和 ArcGIS Mobile 部署。
| String |
copy_data_from_server | 只在以下情况下将该选项设置为 COPY_DATA:无法向 ArcGIS Server 帐户授予目标文件夹的写入权限但 ArcGIS for Desktop 客户端拥有目标文件夹的写入权限。软件会在将服务器输出目录中的切片移至目标文件夹前将其导出。
| Boolean |
storage_format_type |
导出的缓存的存储格式。
| String |
scales [scales,...] |
导出切片时使用的比例级别列表。 | Double |
num_of_caching_service_instances (可选) |
专用于运行该工具的系统/缓存工具服务实例的总数。您可以通过与 ArcGIS Server 的管理连接,使用 服务编辑器 窗口,增加系统/缓存工具服务的每台计算机的最大实例数。确保您的服务器计算机可以支持所选数量的实例。 | Long |
area_of_interest (可选) |
对从缓存中导出切片的位置进行空间约束的感兴趣区(面)。它可能是一个要素类,也可能是在 ArcMap 中以交互方式定义的要素。由于该工具在像素级别上裁剪缓存数据集,所以此参数在您想要导出形状不规则的区域时非常有用。 若未指定感兴趣区,则会导出地图的全图范围。 | Feature Set |
export_extent (可选) |
定义要导出的切片的矩形范围。默认情况下,此范围被设置为要导入切片所属的地图服务的全图范围。请注意此感兴趣区工具中的可选参数,它允许您使用面要素进行导入操作。建议不要为一个作业的两个参数都提供值。如果为两个参数都提供了值,则感兴趣区的优先级高于导入范围 | Extent |
overwrite (可选) |
| Boolean |
代码实例
导出地图服务器缓存 (ExportMapServerCache) 示例 1
将存储格式从 EXPLODED 更改为 COMPACT 时导出某一要素类的缓存切片。
# Name: ExportMapServerCache.py for ArcGIS Server
# Description: The following stand-alone script demonstrates how to export
# cache as CACHE_DATASET in COMPACT storage format and MERGE tiles
# using an AREA_OF_INTEREST to TARGET_CACHE_PATH
# which is accessible to server instances
# 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
targetCachePath = "C:/data/temp"
exportCacheType = "CACHE_DATASET"
copyDataFromServer = "DO_NOT_COPY"
storageFormat = "COMPACT"
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
areaOfInterest = "C:/data/101/Portland/Metro.shp"
exportExtents = ""
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 "scaleValues[0]","scaleValues[-1]","scaleValues[0:3]"
# Enter rectangular custom extent values for the "exportExtents" variable to
# constrain the exporting cache along the rectangular extents
try:
starttime = time.clock()
result = arcpy.ExportMapServerCache_server(inputService, targetCachePath,
exportCacheType,
copyDataFromServer,
storageFormat, scales,
numOfCachingServiceInstances,
areaOfInterest, exportExtents,
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 "Exported cache successfully for mapservice " + serviceName
" to " + targetCachePath + "\n using " + areaOfInterest + "\n 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)
print "Exported Map server Cache using area of Interest"
report.close()
导出地图服务器缓存 (ExportMapServerCache) 示例 2
ArcGIS Server 实例无法访问目标文件夹时将缓存导出为 TILE_PACKAGE。
# Name: ExportMapServerCache.py
# Description: The following stand-alone script demonstrates how to export cache
# as TILE_PACKAGE for default number of scales of a service, to a
# TARGET_CACHE_PATH which is inaccessible to server instances using
# COPY_DATA_FROM_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
targetCachePath = "C:/temp/usa"
exportCacheType = "TILE_PACKAGE"
copyDataFromServer = "COPY_DATA"
storageFormat = "COMPACT"
scaleValues = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
exportExtents = ""
areaOfInterest = ""
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 "scaleValues[0]","scaleValues[-1]","scaleValues[0:3]"
try:
starttime = time.clock()
result = arcpy.ExportMapServerCache_server(inputService, targetCachePath,
exportCacheType,
copyDataFromServer,
storageFormat, scales,
numOfCachingServiceInstances,
areaOfInterest,
exportExtents, 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 "Exported cache successfully for mapservice " + serviceName + " to "
targetCachePath + " 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)
print "Exported Map server Cache "
report.close()