创建地图服务器缓存 (服务器)
摘要
为地图服务缓存创建切片方案和预备文件夹。运行此工具后,运行管理地图服务器缓存切片以将切片添加到缓存。
用法
- 
此工具只适用于 ArcGIS Server 地图服务。 
- 
一次只能缓存一个数据框。如需使用多个数据框中的地图,则必须创建单独的地图服务并针对每个数据框进行缓存。 
- 
一旦创建切片方案,就无法进行修改。不过,您可使用“管理地图服务器缓存比例”工具来添加或删除比例。 
- 
为获取最佳性能,请使用融合缓存。对将在 Web 应用程序中使用的切片应始终应用融合缓存。 
- 
栅格数据最适合采用 JPEG 或 MIXED 图像格式。使用 JPEG 或 MIXED 格式的矢量地图时,应使用较高的压缩质量值(如 90),从而减轻线和文本的模糊程度。尽管应避免对将在 Web 应用程序中使用的缓存应用 PNG 24 格式,但矢量数据却可以采用 PNG 格式。 
- 
多图层缓存不支持 JPEG 文件格式。 
- 
一旦生成缓存,就无法对缓存图像格式进行更改。必须先删除缓存,然后才能将其切换到其他格式。 
- 
抗锯齿选项用于对线和文本的边缘进行平滑处理,但对栅格图像的质量增强效果并不明显。 
语法
| 参数 | 说明 | 数据类型 | 
| server_name | 对要建立缓存的服务进行托管的 ArcGIS Server 计算机。 | String | 
| object_name | 要建立缓存的地图服务。 | String | 
| data_frame | 要建立缓存的地图数据框。 | String | 
| out_folder | 用于缓存的父目录。此目录必须是已注册的 ArcGIS Server 缓存目录。 | String | 
| tiling_scheme_type | 选择采用 NEW 还是 PREDEFINED 切片方案。可以使用此工具定义一个新的切片方案,也可以浏览到一个预定义的切片方案文件 (.xml)。预定义方案的创建可以通过运行“生成地图服务器缓存切片方案”工具来实现。 
 | String | 
| scales_type | 指定将如何定义切片的比例。 
 | String | 
| num_of_scales | 要在缓存中创建的比例级数。如果要创建比例的自定义列表,则此选项不可用。 | Long | 
| dpi | 专用输出设备的每英寸点数。如果所选择的 DPI 与输出设备的分辨率不匹配,则地图切片将显示错误比例。默认值为 96。 | Long | 
| tile_width | 缓存切片的宽度(以像素为单位)。默认值为 256。为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 或 512。 | Long | 
| tile_height | 缓存切片的高度(以像素为单位)。默认值为 256。为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 或 512。 | Long | 
| map_or_layers (可选) | 选择生成FUSED 或 MULTI_LAYER 缓存: 
 | String | 
| tiling_schema (可选) | 预定义切片方案文件(通常名为 conf.xml)的路径。 | File | 
| tile_origin (可选) | 源地图文档空间参考的坐标中的切片方案原点(左上角)。源地图文档的范围必须在此原点范围内(但不必与原点重合)。 | Point | 
| levels [levels,...] (可选) | 可用于缓存的比例级别。不使用分数表示比例级别,而使用 500 表示比例 1:500,依此类推。 | String | 
| Layer [Layer,...] (可选) | 选择 MULTI_LAYER 缓存类型时要包含在缓存中的图层。 | String | 
| Antialiasing (可选) | 指定是否在渲染切片时使用抗锯齿功能。如果选择了抗锯齿功能,则会对线、边框和文本的边缘进行平滑处理。此选项会带来性能开销。使用基于 MXD 的地图服务时(相对于已在 MSD 文件中定义了抗锯齿功能的基于 MSD 的地图服务而言),性能开销较大。抗锯齿功能不会给栅格影像带来任何益处。 如果地图服务源是 MSD 文件且已在 MSD 中定义了抗锯齿功能,则无论是否选择此工具中的该选项,抗锯齿功能都会应用到缓存中。 
 | Boolean | 
| cache_format (可选) | 为缓存中的切片选择 PNG8、PNG24、PNG32、JPEG 或 MIXED 文件格式。PNG8 为默认选项。 
 | String | 
| tile_compression_quality (可选) | 针对 JPEG 压缩质量输入一个介于 1 和 100 之间的值。对于 JPEG 切片格式,默认值为 75;对于其他切片格式,默认值为 0。 仅 JPEG 格式支持压缩。如果选择较高的值,则生成的文件较大,但图像质量较好。如果选择较低的值,则生成的文件较小,但图像质量较差。 | Long | 
| storage_format (可选) | 选择是否使用“紧密”存储格式将切片分组到大型 .bundle 文件中,而不选择使用“松散”格式将每个切片存储为单独的文件。紧密存储格式在存储和移动性方面更为有效。 | String | 
| use_local_cache_dir | 选择 bundle 文件是否应在创建紧密缓存时写入服务器上的本地目录,而不是直接写入共享的缓存目录。如果选择此选项,bundle 文件在完成后将写入共享的缓存目录。当多台计算机处理缓存作业时,此选项可提升性能。 
 | Boolean | 
代码示例
在本例中,创建了一个采用“标准”比例类型的地图缓存。
# CreateMapServerCache example (stand-alone script)
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
#               using Custom scales & jpg image format with Antialiasing feature turned on
# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
cacheDir = "C:\\arcgisserver\\arcgiscache\\"
tilingScheme = "NEW"
scalesType = "CUSTOM"
extents = ""
tileOrigin = ""
scales = "4"
dpi = "96"
scaleValues = "600265;350200;225400;44000"
tileWidth = "256"
tileHeight = "256"
cacheType = "FUSED"
inputLayers = ""
pathToXML = ""
antialiasing = "ANTIALIASING"
tileFormat = "JPEG"
tileCompressionQuality = "75"
storageFormat = "Compact"
useLocalCacheDir = "True"
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(server, service, dataFrame, cacheDir,
                                      tilingScheme, scalesType, scales, dpi,
                                      tileWidth, tileHeight, cacheType,
                                      pathToXml, tileOrigin, scaleValues,
                                      inputLayers, antialiasing, tileFormat,
                                      tileCompressionQuality,
                                      storageFormat, useLocalCacheDir)
    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 "
    + 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)
print "Executed creation of map server Cache schema using custom scales"
report.close()
在本例中,创建了一个采用“自定义”比例的地图缓存。
# CreateMapServerCache example (stand-alone script)
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
#               using Custom scales & jpg image format with Antialiasing feature turned on
# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
cacheDir = "C:\\arcgisserver\\arcgiscache\\"
tilingScheme = "NEW"
scalesType = "CUSTOM"
extents = ""
tileOrigin = ""
scales = "4"
dpi = "96"
scaleValues = "600265;350200;225400;44000"
tileWidth = "256"
tileHeight = "256"
cacheType = "FUSED"
inputLayers = ""
pathToXML = ""
antialiasing = "ANTIALIASING"
tileFormat = "JPEG"
tileCompressionQuality = "75"
storageFormat = "Compact"
useLocalCacheDir = "True"
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(server, service, dataFrame, cacheDir,
                                      tilingScheme, scalesType, scales, dpi,
                                      tileWidth, tileHeight, cacheType,
                                      pathToXml, tileOrigin, scaleValues,
                                      inputLayers, antialiasing, tileFormat,
                                      tileCompressionQuality,
                                      storageFormat, useLocalCacheDir)
    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 "
    + 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)
print "Executed creation of map server Cache schema using custom scales"
report.close()
在本例中,创建了一个采用预定义切片方案的地图缓存。
# CreateMapServerCache example (stand-alone script)
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
#               using Custom scales & jpg image format with Antialiasing feature turned on
# 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
server = "MyServer"
service = "Rainfall"
dataFrame = "" 
cacheDir = "C:\\arcgisserver\\arcgiscache\\"
tilingScheme = "NEW"
scalesType = "CUSTOM"
extents = ""
tileOrigin = ""
scales = "4"
dpi = "96"
scaleValues = "600265;350200;225400;44000"
tileWidth = "256"
tileHeight = "256"
cacheType = "FUSED"
inputLayers = ""
pathToXML = ""
antialiasing = "ANTIALIASING"
tileFormat = "JPEG"
tileCompressionQuality = "75"
storageFormat = "Compact"
useLocalCacheDir = "True"
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(server, service, dataFrame, cacheDir,
                                      tilingScheme, scalesType, scales, dpi,
                                      tileWidth, tileHeight, cacheType,
                                      pathToXml, tileOrigin, scaleValues,
                                      inputLayers, antialiasing, tileFormat,
                                      tileCompressionQuality,
                                      storageFormat, useLocalCacheDir)
    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 "
    + 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)
print "Executed creation of map server Cache schema using custom scales"
report.close()