arcpy.server.ImportMapServerCache(input_service, source_cache_type, {source_cache_dataset}, {source_tile_package}, {upload_data_to_server}, {scales}, {num_of_caching_service_instances}, {area_of_interest}, {import_extent}, {overwrite})
|
名称
|
说明
|
数据类型
|
|
input_service
|
带有要导入的缓存切片的地图图像图层。
|
Image Service; Map Server
|
|
source_cache_type
|
指定将导入到服务器上运行的缓存地图或影像服务的缓存类型。
|
String
|
|
source_cache_dataset
(可选)
|
与数据框名称相匹配的缓存文件夹的路径。 您不必指定已注册的服务器缓存目录;通常,需要指定磁盘上之前已导入切片的位置。 ArcGIS Server 账户应能访问此位置。 如果无法向 ArcGIS Server 账户授予此位置的访问权限,请将 upload_data_to_server 参数设置为 UPLOAD_DATA。
|
Raster Dataset
|
|
source_tile_package
(可选)
|
要导入的切片包(.tpk 或 .tpkx)的路径。 ArcGIS Server 账户应能访问此位置。 将切片包文件导入到缓存的地图或影像服务时,将忽略 upload_data_to_server 参数,因为该参数自动设置为 UPLOAD_DATA。
|
File
|
|
upload_data_to_server
(可选)
|
指定将切片移至服务器缓存目录的方式。
如果 ArcGIS Server 账户没有源缓存的读取权限,请将此参数设置为 UPLOAD_DATA。 工具会在源缓存移至 ArcGIS Server 缓存目录前将其上传到 ArcGIS Server 上传目录。
|
Boolean
|
|
scales
[scales,...]
(可选)
|
导入切片时使用的比例级别列表。
|
Double
|
|
num_of_caching_service_instances
(可选)
|
用于更新或生成切片的实例数。 该参数的值将设置为无限 (-1),且无法进行修改。
|
Long
|
|
area_of_interest
(可选)
|
对将切片导入到缓存时所处的位置进行空间约束的感兴趣区域面。 此参数在导入形状不规则区域的切片时非常有用,因为该工具会按像素分辨率裁剪与面相交的缓存数据集,然后将其导入到服务器缓存目录。
如果未提供该参数的值,则将使用 import_extent 参数的值。 默认情况下将使用地图的全图范围。
|
Feature Set
|
|
import_extent
(可选)
|
矩形范围,用于定义将导入到缓存的切片。 默认情况下,此范围将设置为要导入切片所属的地图服务的全图范围。 可选感兴趣区域参数允许您使用不规则形状对已导入切片进行空间约束。 如果提供了两个参数的值,则将使用感兴趣区域参数的值。
矩形范围,用于定义将导入到缓存的切片。 默认情况下,此范围将设置为要导入切片所属的地图服务的全图范围。 可选 area_of_interest 参数允许您使用不规则形状对已导入切片进行空间约束。 如果提供了两个参数的值,则将使用 area_of_interest 参数的值。
|
Extent
|
|
overwrite
(可选)
|
指定目标缓存中的图像是与原始缓存中的切片合并,还是被其覆盖。
|
Boolean
|
派生输出
|
名称
|
说明
|
数据类型
|
|
out_job_url
|
输出 URL。
|
String
|
代码示例
ImportMapServerCache 示例 1(独立脚本)
将缓存数据集导入到默认比例级数的缓存服务。 接收缓存中的切片将被正在导入的切片所覆盖。
# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
# server cache from a source directory with CACHE_DATASET and
# OVERWRITE existing cache on the service for the number
# of scales specified without Uploading data to server
# Requirements: os, sys, time and 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
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server = "arcgis on MyServer_6080 (publisher)"
serviceName = "Rainfall.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
sourceCacheType = "CACHE_DATASET"
sourceCacheDataset = "C:/data/destination_folder/Layers"
sourceTilePackage = ""
uploadDataToServer = "DO_NOT_UPLOAD"
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
areaOfInterest = ""
importExtents = ""
overwriteTiles = "OVERWRITE"
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')
# use "scales[0]","scales[-1]","scales[0:3]"
try:
starttime = time.clock()
result = arcpy.server.ImportMapServerCache(inputService, sourceCacheType,
sourceCacheDataset,
sourceTilePackage,
uploadDataToServer, scales,
numOfCachingServiceInstances,
areaOfInterest, importExtents,
overwriteTiles)
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("Imported Map server Cache Tiles successfully for" + serviceName + \
" from" + sourceCacheDataset + "\n in " + str(elapsedtime)+ "sec 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("Imported Map server Cache Tiles ")
report.close()
ImportMapServerCache 示例 2(独立脚本)
将感兴趣区域的缓存切片从切片包导入到缓存服务。
# Name: ImportMapServerCache.py
# Description: The following stand-alone script demonstrates how to import map
# server cache from a source directory with Tile Package to an existing service for
# the default number of scales specified using an AOI by uploading data to remote server
# To Import cache tiles for the scales specified for given feature class
# Requirements: os, sys, time and 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
connectionFile = r"C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog"
server = "arcgis on MyServer_6080 (publisher)"
serviceName = "Rainfall.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
sourceCacheType = "TILE_PACKAGE"
sourceCacheDataset = ""
sourceTilePackage = "C:\\data\\destination_folder\\TPK\\Rainfall.tpk"
uploadDataToServer = "UPLOAD_DATA"
scales = [500000,250000,125000,64000]
numOfCachingServiceInstances = "2"
cacheDir = "c:\\arcgisserver\\arcgiscache"
areaOfInterest = "C:/data/101/Portland/Portland_Metro.shp"
importExtents = ""
overwriteTiles = "MERGE"
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')
# use "scales[0]","scales[-1]","scales[0:3]"
try:
starttime = time.clock()
result = arcpy.server.ImportMapServerCache(inputService, sourceCacheType,
sourceCacheDataset,
sourceTilePackage,
uploadDataToServer, scales,
numOfCachingServiceInstances,
areaOfInterest, importExtents,
overwriteTiles)
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("Imported Map server Cache Tiles successfully for " + serviceName + \
" from " + sourceTilePackage + " to " + cacheDir + "\n using "+ areaOfInterest + \
" 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 2 \n" "Line %i" % tb.tb_lineno)
report.write(str(e))
report.close()
print("Imported Map server Cache Tiles for the given feature class")