创建地图服务器缓存 (Server)

许可等级:BasicStandardAdvanced

摘要

为地图或影像服务缓存创建切片方案和备用文件夹。运行此工具后,运行管理地图服务器缓存切片以将切片添加到缓存。

用法

语法

CreateMapServerCache_server (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,选择“目录”树中的服务,并注意位置 工具条中的文本。然后将反斜线改为正斜线,例如,MYSERVER (admin)/USA.MapServer 上的 GIS Servers/arcgis

String
service_cache_directory

用于缓存的父目录。此目录必须是已注册的 ArcGIS Server 缓存目录。

String
tiling_scheme_type

选择采用 NEW 还是 PREDEFINED 切片方案。可以使用此工具定义一个新的切片方案,也可以浏览到一个预定义的切片方案文件 (.xml)。可以通过运行生成地图服务器缓存切片方案工具来创建预定义方案。

  • NEW将使用此工具中的其他各种参数来定义一个新的切片方案,从而对比例级别、图像格式和存储格式等设置加以定义。这是默认设置。
  • PREDEFINED指定一个磁盘上已存在的切片方案 .xml 文件。也可使用生成地图服务器缓存切片方案工具创建一个切片方案文件。
String
scales_type

指定如何定义切片的比例。

  • STANDARD根据比例级数(Python 中的 num_of_scales)参数中定义的数字自动生成比例。该比例将采用从 1:1,000,000 递增或递减一半的级别,并将最接近于源地图文档范围的级别作为起始比例。例如,如果源地图文档的范围是 1:121,000,000 并且定义了 3 个比例级别,则该地图服务将创建一个缓存,其比例级别可以是 1:128,000,000、1:64,000,000 和 1:32,000,000。这是默认值。
  • CUSTOM允许缓存设计器输入任何所需比例。
String
num_of_scales

要在缓存中创建的比例级数。如果要创建一个自定义的比例列表,则此选项不可用。

Long
dots_per_inch

专用输出设备的每英寸点数。如果所选择的 DPI 与输出设备的分辨率不匹配,则地图切片将显示错误比例。默认值为 96。

Long
tile_size

缓存切片的宽度和高度(以像素为单位)。默认值为 256 X 256。为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 X 256 或 512 X 512。

  • 128 x 128128 x 128 像素
  • 256 x 256256 x 256 像素
  • 512 x 512512 x 512 像素
  • 1024 x 10241024 x 1024 像素
String
predefined_tiling_scheme
(可选)

预定义切片方案文件的路径(通常名为 conf.xml)。

File
tile_origin
(可选)

切片方案原点(左上角),采用源地图文档空间参考的坐标值。源地图文档的范围必须在此原点范围内(但不必与原点重合)。

Point
scales
[scales,...]
(可选)

用于缓存的比例级别。不使用分数表示比例级别,而使用 500 表示比例 1:500,依此类推。

Value Table
cache_tile_format
(可选)

为缓存中的切片选择 PNG、PNG8、PNG24、PNG32、JPEG 或 MIXED 文件格式。PNG8 为默认选项。

  • PNG使用不同的位深度创建 PNG 格式。并且已根据切片中的颜色变化和透明度值对位深度进行了优化。
  • PNG8一种无损 8 位彩色图像格式,使用索引调色板和 alpha 表。每个像素都存储一个 0-255 之间的值,用于查看调色板中的颜色和 alpha 表中的透明度。8 位 PNG 类似于 GIF 图像,并对多数 Web 浏览器的透明背景提供最佳支持。
  • PNG24一种无损三通道图像格式,支持大量的颜色变化(1600 万个颜色),并对透明度提供有限的支持。每个像素包含三条 8 位颜色通道,并且文件头中包含用于表示透明背景的单一颜色。可在 ArcMap 中对表示透明背景色的颜色进行设置。低于版本 7 的 Internet Explorer 版本不支持此透明类型。采用 PNG24 的缓存比采用 PNG8 或 JPEG 的缓存大得多,并且需要占用更多磁盘空间和更大带宽才能为客户端提供服务。
  • PNG32一种无损四通道图像格式,支持大量的颜色变化(1600 万个颜色),并支持透明度。每个像素包含三条 8 位颜色通道和一条表示每个像素的透明度级别的 8 位 alpha 通道。虽然 PNG32 格式允许部分透明像素位于范围 0 到 255 之间,但是 ArcGIS Server 缓存生成工具仅将完全透明值 (0) 或完全不透明值 (255) 写入透明度通道。采用 PNG32 的缓存比采用其他受支持的格式的缓存大得多,并且需要占用更多磁盘空间和更大带宽才能为客户端提供服务。
  • JPEG一种有损三通道图像格式,支持大量的颜色变化(1600 万个颜色),但不支持透明度。每个像素包含三条 8 位颜色通道。采用 JPEG 的缓存可对输出质量和大小加以控制。
  • MIXED在检测到透明度的所有位置(也就是数据框背景可见的所有位置)创建 PNG 32。而为其余部分创建 JPEG。这可降低平均文件大小,同时可在其他缓存上进行完全叠加。
String
tile_compression_quality
(可选)

针对 JPEG 压缩质量输入一个介于 1 和 100 之间的值。对于 JPEG 切片格式,默认值为 75;对于其他切片格式,默认值为 0。

仅 JPEG 格式支持压缩。如果选择较高的值,则生成的文件较大,但图像质量较好。如果选择较低的值,则生成的文件较小,但图像质量较差。

Long
storage_format
(可选)

确定切片的存储格式。

  • COMPACT将切片分组到较大的包文件中。此存储格式在存储和移动性方面更高效。
  • EXPLODED将每个切片存储为单独的文件。
String

代码实例

CreateMapServerCache 示例 1

在本例中,创建了一个采用 STANDARD 比例类型的地图缓存。

# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
#               using standard tiling schema 
# 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
#              using Custom scales & jpg image format.
# 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

在本例中,创建了一个采用预定义切片方案的地图缓存。

# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
#               using existing predefined schema
# 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()

环境

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

相关主题

许可信息

ArcGIS for Desktop Basic: 是
ArcGIS for Desktop Standard: 是
ArcGIS for Desktop Advanced: 是
5/25/2014