arcpy.server.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}, {ready_to_serve_format})
|
名称
|
说明
|
数据类型
|
|
input_service
|
将进行缓存的地图或图像图层。
|
Image Service; Map Server
|
|
service_cache_directory
|
用于缓存的父目录。 此目录必须是已注册的 ArcGIS Server 缓存目录。
|
String
|
|
tiling_scheme_type
|
指定切片方案的定义方式。 可以定义一个新的切片方案,也可以浏览到一个预定义的切片方案文件 (.xml)。 可以通过运行生成地图服务器缓存切片方案工具来创建预定义方案。
|
String
|
|
scales_type
|
指定切片的比例调整方式。
STANDARD—将根据比例级数值自动生成比例。 该比例将采用从 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)。 如果指定的 DPI 与输出设备的分辨率不匹配,则地图切片将显示错误比例。 默认值为 96。
|
Long
|
|
tile_size
|
指定缓存切片的宽度和高度(以像素为单位)。 为在性能和可管理性之间寻求最佳平衡,应避免偏离标准宽度 256 x 256 或 512 x 512。
128 x 128—缓存切片的宽度和高度将为 128 x 128 像素。
256 x 256—缓存切片的宽度和高度将为 256 x 256 像素。 这是默认设置。
512 x 512—缓存切片的宽度和高度将为 512 x 512 像素。
1024 x 1024—缓存切片的宽度和高度将为 1024 x 1024 像素。
|
String
|
|
predefined_tiling_scheme
(可选)
|
预定义切片方案文件(通常名为 conf.xml)的路径。
|
File
|
|
tile_origin
(可选)
|
切片方案原点(左上角),采用源地图文档空间参考的坐标值。 源地图文档的范围必须在此区域内(但不必与该区域重合)。
|
Point
|
|
scales
[scales,...]
(可选)
|
用于缓存的比例级别。 不使用分数表示比例级别, 例如,应使用 500 表示比例 1:500,依此类推。
|
Value Table
|
|
cache_tile_format
(可选)
|
指定将使用的缓存切片格式。
PNG—将使用具有不同位深度的 PNG 格式。 并且已根据切片中的颜色变化和透明度值对位深度进行了优化。 这是默认设置。
PNG8—将使用一种无损 8 位彩色图像格式,该格式使用索引调色板和 alpha 表。 每个像素都存储一个值(0 到 255),用于查看调色板中的颜色和 alpha 表中的透明度。 8 位 PNG 图像类似于 GIF 图像,且大多数 Web 浏览器支持在 PNG 图像中使用透明背景。
PNG24—将使用一种无损三通道图像格式,该格式支持大幅度的颜色变化(1600 万个颜色),并对透明度提供有限的支持。 每个像素包含三条 8 位颜色通道,并且文件头中包含用于表示透明背景的单一颜色。 Microsoft Internet Explorer 7 之前的版本不支持此类透明效果。 采用 PNG24 的缓存比采用 PNG8 或 JPEG 的缓存大得多,并且需要使用更多磁盘空间和更大带宽才能为客户端提供服务。
PNG32—将使用一种无损四通道图像格式,该格式支持大量的颜色变化(1600 万个颜色),并支持透明度。 每个像素包含三条 8 位颜色通道和一条表示每个像素的透明度级别的 8 位 alpha 通道。 虽然 PNG32 格式允许部分透明像素位于范围 0 到 255 之间,但是 ArcGIS Server 缓存生成工具仅将完全透明值 (0) 或完全不透明值 (255) 写入透明度通道。 采用 PNG32 的缓存比采用其他受支持的格式的缓存大得多,并且需要使用更多磁盘空间和更大带宽才能为客户端提供服务。
JPEG—将使用一种有损三通道图像格式,该格式支持大量的颜色变化(1600 万个颜色),但不支持透明度。 每个像素包含三条 8 位颜色通道。 采用 JPEG 的缓存可控制输出质量和大小。
MIXED—PNG32 格式将在检测到透明度的所有位置(也就是数据框背景可见的所有位置)进行创建。 系统将为其余的切片创建 JPEG 格式。 这可降低平均文件大小,同时可在其他缓存上进行完全叠加。
|
String
|
|
tile_compression_quality
(可选)
|
将使用的 JPEG 压缩质量 (1-100)。 对于 JPEG 切片格式,默认值为 75;对于其他切片格式,默认值为 0。
仅 JPEG 格式支持压缩。 如果选择较高的值,则生成的文件较大,但图像质量较好。 如果选择较低的值,则生成的文件较小,但图像质量较差。
|
Long
|
|
storage_format
(可选)
|
指定将用于切片的存储格式。
旧版本:
此参数已弃用。 将始终使用紧凑型 V2 存储格式,不考虑指定的存储格式。
|
String
|
|
ready_to_serve_format
(可选)
|
指定是否使用开放 切片包规范 生成缓存内容,并指定缓存方案的文件格式。
READY_TO_SERVE_FORMAT—将使用开放切片包规范 (https://github.com/Esri/tile-package-spec) 生成缓存内容。 可将切片包打包为 zip 存档作为切片包,以供离线工作流使用。 缓存格式将为紧凑型 V2,并且缓存方案将以 JSON 格式存储。
NON_READY_TO_SERVE_FORMAT—将使用以 XML 格式存储的方案生成缓存内容。 使用此选项可将缓存复制到先前版本的 ArcGIS Enterprise。 这是默认设置。
|
Boolean
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_service_url
|
输出地图服务 URL。
|
String
|
代码示例
CreateMapServerCache 示例 1(独立脚本)
以下示例使用 STANDARD 比例类型为地图服务缓存创建切片方案和预备文件夹。 在运行此脚本后,运行 管理地图服务器缓存切片 工具以将切片添加到缓存。
# Name: CreateMapServerCache.py
# Description: The following stand-alone script demonstrates how to create map
# using standard tiling schema for weblayers published to ArcGIS Enterprise and ArcGIS Online.
# and for map and image services on a stand alone ArcGIS Server
# Requirements: os, sys, time & traceback modules
# Any line that begins with a pound sign is a comment and will not be run
# 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 sys
import time
import datetime
# Set environment settings
env.workspace = "C:/data"
# Sign in to portal
myPortal= "https://MyPortal.domain.com/portalwebadaptor"
arcpy.SignInToPortal(myPortal, "siteadminValue", "siteadminPassword")
myServer="https://Myserver.domain.com/serverwebadaptor"
serviceName= "SampleWorldCities"
serviceType= "MapServer"
myPortalServiceURL = (myServer + "/" + "rest/services" +"/" + serviceName + "/"
+ serviceType)
print (myPortalServiceURL)
# Stand alone ArcGIS Server
##target_server_connection = r"C:\share\python3\arcgis on MyServer"
##serviceName= "States"
##serviceType= "MapServer"
##myServerServiceURL= target_server_connection + "/" + serviceName + "." + serviceType
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 = ""
ready_to_serve_format="READY_TO_SERVE_FORMAT"
#variables for reporting
currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = 'E:/data/report_%s.txt' % arg1
# print results of the script to a report
report = open(file,'w')
try:
## starttime = time.clock()
result = arcpy.server.CreateMapServerCache(myPortalServiceURL,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat,
ready_to_serve_format)
## 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" + \
## myServerServiceURL + " in " + str(elapsedtime) + " sec \n on " + arg2)
print("Created cache schema with 4 scales & default properties for" + \
myServerServiceURL + " in " + arg2)
except Exception as 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)
report.write(str(e))
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 run
# 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 sys
import time
import datetime
# Set environment settings
env.workspace = "C:/data"
# List of input variables for map service properties
# Sign in to portal
myPortal= "https://MyPortal.domain.com/portalwebadaptor"
arcpy.SignInToPortal(myPortal, "siteadminValue", "siteadminPassword")
myServer= "https://Myserver.domain.com/serverwebadaptor"
serviceName= "SampleWorldCities"
serviceType= "MapServer"
myPortalServiceURL = (myServer + "/" + "rest/services" +"/" + serviceName + "/"
+ serviceType)
print (myPortalServiceURL)
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:
result = arcpy.server.CreateMapServerCache(myPortalServiceURL,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat)
#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 as 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(str(e))
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
# using existing predefined schema in a ready to serve format
# Requirements: os, sys, time & traceback modules
# Any line that begins with a pound sign is a comment and will not be run
# 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 sys
import time
import datetime
# Set environment settings
env.workspace = "E:/data"
# Sign in to portal
myPortal= "https://MyPortal.domain.com/portalwebadaptor"
arcpy.SignInToPortal(myPortal, "siteadminValue", "siteadminPassword")
myServer= "https://Myserver.domain.com/serverwebadaptor"
serviceName= "SampleWorldCities"
serviceType= "MapServer"
myPortalServiceURL = (myServer + "/" + "rest/services" +"/" + serviceName + "/"
+ serviceType)
print (myPortalServiceURL)
# Stand alone ArcGIS Server
##target_server_connection = r"C:\share\python3\arcgis on MyServer"
##serviceName= "States"
##serviceType= "MapServer"
##myServerServiceURL= target_server_connection + "/" + serviceName + "." + serviceType
# List of input variables for map service properties
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"
ready_to_serve_format="READY_TO_SERVE_FORMAT"
#variables for reporting
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:
result = arcpy.server.CreateMapServerCache(myPortalServiceURL,
serviceCacheDirectory,
tilingSchemeType, scalesType,
numOfScales, dotsPerInch,
tileSize, predefinedTilingScheme,
tileOrigin, scales,
cacheTileFormat,
tileCompressionQuality,
storageFormat,
ready_to_serve_format)
#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 " + arg2)
except Exception as 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(str(e))
print("Executed creation of map server Cache schema using tiling scheme")
report.close()