arcpy.server.ExportMapServerCache(input_service, target_cache_path, export_cache_type, copy_data_from_server, storage_format_type, scales, {num_of_caching_service_instances}, {area_of_interest}, {export_extent}, {overwrite}, {ready_to_serve_format})
|
名称
|
说明
|
数据类型
|
|
input_service
|
带有要导出的缓存切片的地图图像图层。
|
Image Service; Map Server
|
|
target_cache_path
|
缓存将被导出到的目标文件夹。 此文件夹不必是一个已注册的服务器缓存目录。 ArcGIS Server 账户必须拥有目标缓存文件夹的写入权限。 如果无法向服务器账户授予目标缓存文件夹的写入权限,但 ArcGIS Desktop 或 ArcGIS Pro 客户端拥有目标缓存文件夹的写入权限,则选中从服务器复制数据参数。
|
Folder
|
|
export_cache_type
|
指定将导出的缓存类型。 切片包适用于与 ArcGIS Maps SDKs for Native Apps 配合使用。
CACHE_DATASET—将导出使用 ArcGIS Server 生成的地图或影像服务缓存。 其可用于 ArcGIS Desktop 以及 ArcGIS Server 地图或影像服务。 此选项可用于生成即用型格式的内容。 这是默认设置。
TILE_PACKAGE—将导出单个压缩文件,将在该文件中添加缓存数据集作为图层并对其进行合并,以便进行共享。 其可用于 ArcGIS Pro 中,并与 ArcGIS Maps SDKs for Native Apps 配合使用。
|
String
|
|
copy_data_from_server
|
指定将切片移至目标文件夹的方式。
如果无法向 ArcGIS Server 账户授予目标文件夹的写入权限,但 ArcGIS Desktop 或 ArcGIS Pro 客户端拥有目标文件夹的写入权限,则将此参数设置为 COPY_DATA。 软件会在将切片移至目标文件夹之前,先将其导出到服务器输出目录中。
|
Boolean
|
|
storage_format_type
|
指定将用于已导出缓存的存储格式。
COMPACT—切片被组织到包和 bundlex 文件中以节省磁盘空间并允许以较快的速度复制缓存。 如果将 export_cache_type 参数设置为 TILE_PACKAGE,则此为默认设置。
COMPACT_V2—仅能将切片组织到包文件中。 此格式将在网络共享和云存储目录上提供更好的性能。 如果将 export_cache_type 参数设置为 TILE_PACKAGE,则切片包的扩展名为 .tpkx,ArcGIS 产品的较新版本(如 ArcGIS Online、ArcGIS Enterprise 12.0、ArcGIS Maps SDKs for Native Apps 200.0 或更高版本,以及 ArcGIS Runtime 100.5-100.15)均支持该格式。
EXPLODED—每个切片都将以单个文件的形式存储。
|
String
|
|
scales
[scales,...]
|
导出切片时使用的比例级别列表。
|
Double
|
|
num_of_caching_service_instances
(可选)
|
用于更新或生成切片的实例数。 该参数的值将设置为无限 (-1),且无法进行修改。
|
Long
|
|
area_of_interest
(可选)
|
对将从缓存中导出切片的位置进行空间约束的感兴趣区域。 由于该工具在像素级别上裁剪缓存数据集,所以此参数在导出形状不规则的区域时非常有用。
若未指定感兴趣区域,则将导出地图的全图范围。
|
Feature Set
|
|
export_extent
(可选)
|
矩形范围,用于定义将导出的切片。 默认情况下,此范围将设置为要导入切片所属的地图服务的全图范围。 可选感兴趣区域参数允许您使用面要素进行导入操作。 建议您不要为两个参数都提供值。 如果为两个参数都提供了值,则感兴趣区域参数的优先级高于此参数。
|
Extent
|
|
overwrite
(可选)
|
指定接收缓存中的图像是与原始缓存中的切片合并,还是被其覆盖。
|
Boolean
|
|
ready_to_serve_format
(可选)
|
指定是否使用开放切片包规范 生成缓存内容,并指定缓存方案的文件格式。 仅当 export_cache_type 参数值为 CACHE_DATASET 时,可使用此参数。
READY_TO_SERVE_FORMAT—将使用开放切片包规范 (https://github.com/Esri/tile-package-spec) 生成缓存内容。 可将切片包打包为 zip 存档作为切片包,以供离线工作流使用。 缓存格式将为紧凑型 V2,并且缓存方案将以 JSON 格式存储。
NON_READY_TO_SERVE_FORMAT—将使用以 XML 格式存储的方案生成缓存内容。 使用此选项可将缓存复制到先前版本的 ArcGIS Enterprise。 这是默认设置。
|
Boolean
|
派生输出
|
名称
|
说明
|
数据类型
|
|
output_cache_path
|
缓存已被导出到的目标文件夹。
|
String
|
代码示例
ExportMapServerCache 示例 1(独立脚本)
将存储格式从 EXPLODED 更改为 COMPACT 时导出某一要素类的缓存切片。
# Name: ExportMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to export
# cache from a map layer in ArcGIS Enterprise portal,
# as CACHE_DATASET in COMPACT_V2 storage format and MERGE tiles
# using an AREA_OF_INTEREST to TARGET_CACHE_PATH
# which is accessible to server instances
# Example: This sample script updates map cache tiles.
import arcpy
from arcpy import env
import sys
import time
import datetime
# Set environment settings
env.workspace = "C:/data"
# Sign in to ArcGIS Enterprise
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)
# Stand alone ArcGIS Server
##target_server_connection = r"C:\share\python3\arcgis on MyServer.ags"
##serviceName= "MyServiceName"
##serviceType= ".MapServer"
##myPortalServiceURL = (target_server_connection + "\\" + serviceName + serviceType)
print (myPortalServiceURL)
#variables for reporting
currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = r'C:\test\report_%s.txt'% arg1
# List of input variables for map or image service
targetCachePath = "C:/data/temp"
exportCacheType = "CACHE_DATASET"
copyDataFromServer = "DO_NOT_COPY"
storageFormat = "COMPACT_V2"
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
areaOfInterest = "C:/data/101/Portland/Metro.shp"
exportExtents = ""
overwriteTiles = "MERGE"
ready_to_serve_format = "NON_READY_TO_SERVE_FORMAT"
# Print results of the script to a report
report = open(file,'w')
try:
result = arcpy.server.ExportMapServerCache(myPortalServiceURL, targetCachePath,
exportCacheType,
copyDataFromServer,
storageFormat, scales,
numOfCachingServiceInstances,
areaOfInterest, exportExtents,
overwriteTiles,
ready_to_serve_format)
while result.status < 4:
time.sleep(0.2)
resultValue = result.getMessages()
report.write ("completed " + str(resultValue))
print ("Exported cache successfully for " + serviceName )
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
report.write("Failed at step 1 \n" "Line %i" % tb.tb_lineno)
report.write(str(e))
report.close()
ExportMapServerCache 示例 2(独立脚本)
ArcGIS Server 实例无法访问目标文件夹时将使用 TILE_PACKAGE 导出缓存。
# Name: ExportMapServerCacheTiles2.py
# Description: The following stand-alone script demonstrates how to export cache
# on a map service on standalone server as TILE_PACKAGE for default number of scales of a service, to a
# TARGET_CACHE_PATH which is inaccessible to server instances using
# COPY_DATA_FROM_SERVER
# Example: This sample script updates map cache tiles.
import arcpy
from arcpy import env
import sys
import time
import datetime
# Set environment settings
env.workspace = "C:/data"
### Sign in to ArcGIS Enterprise
##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)
# Stand alone ArcGIS Server
target_server_connection = r"C:\share\python3\arcgis on MyServer.ags"
serviceName= "MyServiceName"
serviceType= ".MapServer"
myPortalServiceURL = (target_server_connection + "\\" + serviceName + serviceType)
print (myPortalServiceURL)
#variables for reporting
currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = r'C:\test\report_%s.txt'% arg1
# List of input variables for map or image service
targetCachePath = "C:/temp/usa"
exportCacheType = "TILE_PACKAGE"
copyDataFromServer = "COPY_DATA"
storageFormat = "COMPACT_V2"
scaleValues = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
exportExtents = ""
areaOfInterest = ""
overwriteTiles = "MERGE"
ready_to_serve_format = "NON_READY_TO_SERVE_FORMAT"
# Print results of the script to a report
report = open(file,'w')
try:
result = arcpy.server.ExportMapServerCache(inputService, targetCachePath,
exportCacheType,
copyDataFromServer,
storageFormat, scales,
numOfCachingServiceInstances,
areaOfInterest,
exportExtents, overwriteTiles,
ready_to_serve_format)
while result.status < 4:
time.sleep(0.2)
resultValue = result.getMessages()
report.write ("completed " + str(resultValue))
print ("Exported cache successfully for " + serviceName )
except Exception as e:
# If an error occurred, print line number and error message
import traceback, sys
tb = sys.exc_info()[2]
report.write("Failed at step 1 \n" "Line %i" % tb.tb_lineno)
report.write(str(e))
report.close()