描述
为地图或影像服务缓存创建切片方案和备用文件夹。运行此工具后,使用管理地图服务器缓存切片工具以将切片添加到缓存。
使用
切片方案一旦创建,就无法进行修改。不过,您可使用管理地图服务器缓存比例工具添加或删除比例。
栅格数据最适合使用 JPEG 或 MIXED 图像格式进行发布。使用 JPEG 或 MIXED 格式的矢量地图时,应使用高压缩质量值(如 90),从而减轻线和文本的模糊程度。也可使用 PNG 格式发布矢量数据。
缓存一旦生成,就无法对缓存图像格式进行更改。必须先删除缓存,然后才能将其切换到其他格式。
语法
CreateMapServerCache(input_service, service_cache_directory, tiling_scheme_type, scales_type, num_of_scales, dots_per_inch, tile_size, {predefined_tiling_scheme}, {tile_origin}, {scales}, {cache_tile_format}, {tile_compression_quality}, {storage_format})
参数 | 说明 | 数据类型 |
input_service | 要进行缓存的地图或影像服务。 这是一个包含服务器和服务器信息的字符串。要查看构建此字符串的方法,请打开 ArcCatalog,选择目录树中的服务,并注意位置 工具条中的文本。将反斜线改为正斜线,例如 GIS Servers/arcgis on MYSERVER (admin)/USA.MapServer。 | Image Service; MapServer |
service_cache_directory | 用于缓存的父目录。此目录必须是已注册的 ArcGIS Server 缓存目录。 | String |
tiling_scheme_type | 指定切片方案的定义方式。使用此工具可以定义一个新的切片方案,也可以浏览到一个预定义的切片方案文件 (.xml)。可以通过运行生成地图服务器缓存切片方案工具来创建预定义方案。
| String |
scales_type | 指定切片的比例调整方式。
| String |
num_of_scales | 要在缓存中创建的比例级数。如果要创建一个自定义的比例列表,则此选项不可用。 | Long |
dots_per_inch | 专用输出设备的每英寸点数 (DPI)。如果所选择的 DPI 与输出设备的分辨率不匹配,则地图切片将显示错误比例。默认值为 96。 | Long |
tile_size | 指定缓存切片的宽度和高度(以像素为单位)。为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 x 256 或 512 x 512。
| String |
predefined_tiling_scheme (可选) | 预定义切片方案文件(通常名为 conf.xml)的路径。 | File |
tile_origin (可选) | 切片方案原点(左上角),采用源地图文档空间参考的坐标值。源地图文档的范围必须在此区域内(但不必与该区域重合)。 | Point |
scales [scales,...] (可选) | 用于缓存的比例级别。不使用分数表示比例级别, 而是使用 500 表示比例 1:500,依此类推。 | Value Table |
cache_tile_format (可选) | 指定缓存切片格式。
| String |
tile_compression_quality (可选) | JPEG 压缩质量 (1-100)。对于 JPEG 切片格式,默认值为 75;对于其他切片格式,默认值为 0。 仅 JPEG 格式支持压缩。如果选择较高的值,则生成的文件较大,但图像质量较好。如果选择较低的值,则生成的文件较小,但图像质量较差。 | Double |
storage_format (可选) | 指定切片的存储格式。
| String |
代码示例
CreateMapServerCache 示例 1(独立脚本)
以下示例使用 STANDARD 比例类型为地图服务缓存创建切片方案和预备文件夹。执行此脚本后,运行管理地图服务器缓存切片工具以将切片添加到缓存。
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
# cache tiling scheme using standard scales.
# Note: Use ManageMapServerCacheTile tool to generate cache tiles
# Requirements: os, sys, time & 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
serviceCacheDirectory = "C:\\arcgisserver\\arcgiscache\\"
tilingSchemeType = "NEW"
scalesType = "STANDARD"
numOfScales = "4"
scales = ""
dotsPerInch = "96"
tileOrigin = ""
scales = ""
tileSize = "256 x 256"
cacheTileFormat = "PNG32"
tileCompressionQuality = ""
storageFormat = "COMPACT"
predefinedTilingScheme = ""
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.CreateMapServerCache_server(inputService,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat)
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 schema with 4 scales & default properties 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)
print "Executed creation of Map server Cache schema "
report.close()
CreateMapServerCache 示例 2(独立脚本)
以下示例使用 CUSTOM 比例为地图服务缓存创建切片方案和预备文件夹。执行此脚本后,运行管理地图服务器缓存切片工具以将切片添加到缓存。
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
# cache tiling scheme using Custom scales & jpg image format.
# Note: Use ManageMapServerCacheTile tool to generate cache tiles
# Requirements: os, sys, time & 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, string, datetime, traceback
# 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
serviceCacheDirectory = "C:\\arcgisserver\\arcgiscache"
tilingSchemeType = "NEW"
scalesType = "CUSTOM"
numOfScales = "4"
dotsPerInch = "96"
tileSize = "256 x 256"
predefinedTilingScheme = ""
tileOrigin = ""
scales = "600265;350200;225400;44000"
cacheTileFormat = "JPEG"
tileCompressionQuality = "75"
storageFormat = "COMPACT"
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.CreateMapServerCache_server(inputService,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat)
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 schema with custom scales 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)
print "Executed creation of map server Cache schema using custom scales"
report.close()
CreateMapServerCache 示例 3(独立脚本)
以下示例使用 PREDEFINED 切片方案为地图服务缓存创建切片方案和预备文件夹。执行此脚本后,运行管理地图服务器缓存切片工具以将切片添加到缓存。
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
# cache tiling scheme using existing predefined schema.
# Note: Use ManageMapServerCacheTile tool to generate cache tiles
# Requirements: os, sys, time & 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
serviceCacheDirectory = "C:\\arcgisserver\\directories\\arcgiscache"
tilingSchemeType = "PREDEFINED"
scalesType = ""
tileOrigin = ""
scalesType = ""
numOfScales = ""
scales = ""
dotsPerInch = "96"
tileSize = "256 x 256"
cacheTileFormat = "MIXED"
tileCompressionQuality = "75"
storageFormat = "COMPACT"
predefinedTilingScheme = "C:/data/TilingSchemes/ArcGIS_Online_Bing_Maps_Google_Maps.xml"
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.CreateMapServerCache_server (inputService,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat)
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 schema using predefined tiling schema 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)
print "Executed creation of map server Cache schema using tiling scheme"
report.close()
环境
此工具不使用任何地理处理环境。
许可信息
- Basic: 是
- Standard: 是
- Advanced: 是