创建地图服务器缓存 (Server)
摘要
为地图或影像服务缓存创建切片方案和备用文件夹。运行此工具后,运行管理地图服务器缓存切片以将切片添加到缓存。
用法
- 此工具只适用于 ArcGIS Server 地图或影像服务。
一次只能缓存一个数据框。如需使用多个数据框中的地图,则必须创建单独的地图服务并针对每个数据框进行缓存。
-
切片方案一旦创建,就无法进行修改。不过,您可使用管理地图服务器缓存比例工具添加或删除比例。
-
栅格数据最适合采用 JPEG 或 MIXED 图像格式。使用 JPEG 或 MIXED 格式的矢量地图时,应使用高压缩质量值(如 90),从而减轻线和文本的模糊程度。也能提供 PNG 格式的矢量数据。
-
缓存一旦生成,就无法对缓存图像格式进行更改。必须先删除缓存,然后才能将其切换到其他格式。
语法
参数 | 说明 | 数据类型 |
input_service | 要进行缓存的地图或影像服务。 这是一个包含服务器和服务器信息的字符串。要查看构建此字符串的方法,请打开 ArcCatalog,选择“目录”树中的服务,并注意位置 工具条中的文本。然后将反斜线改为正斜线,例如,MYSERVER (admin)/USA.MapServer 上的 GIS Servers/arcgis。 | String |
service_cache_directory |
用于缓存的父目录。此目录必须是已注册的 ArcGIS Server 缓存目录。 | String |
tiling_scheme_type | 选择采用 NEW 还是 PREDEFINED 切片方案。可以使用此工具定义一个新的切片方案,也可以浏览到一个预定义的切片方案文件 (.xml)。可以通过运行生成地图服务器缓存切片方案工具来创建预定义方案。
| String |
scales_type |
指定如何定义切片的比例。
| String |
num_of_scales |
要在缓存中创建的比例级数。如果要创建一个自定义的比例列表,则此选项不可用。 | Long |
dots_per_inch |
专用输出设备的每英寸点数。如果所选择的 DPI 与输出设备的分辨率不匹配,则地图切片将显示错误比例。默认值为 96。 | Long |
tile_size |
缓存切片的宽度和高度(以像素为单位)。默认值为 256 X 256。为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 X 256 或 512 X 512。 | Long |
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 为默认选项。
| String |
tile_compression_quality (可选) |
针对 JPEG 压缩质量输入一个介于 1 和 100 之间的值。对于 JPEG 切片格式,默认值为 75;对于其他切片格式,默认值为 0。 仅 JPEG 格式支持压缩。如果选择较高的值,则生成的文件较大,但图像质量较好。如果选择较低的值,则生成的文件较小,但图像质量较差。 | Long |
storage_format (可选) |
确定切片的存储格式。
| String |
代码实例
在本例中,创建了一个采用 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()
在本例中,创建了一个采用 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()
在本例中,创建了一个采用预定义切片方案的地图缓存。
# 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()