ArcPy导入地图服务器缓存


上一篇使用了ArcPy创建缓存,这一篇就该讲讲怎么导入缓存了,我这里使用的数据是png格式的缓存,数据格式在之前的博客中有提到。

import arcpy
from arcpy import env
import os, sys, time, datetime, traceback, string

# Set environment settings
env.workspace = "D:/Project"

# List of input variables for map service properties
connectionFile      = env.workspace
server              = "test163"
serviceName         = "WuHanTest.MapServer"
inputService        = connectionFile + "\\" + server + "\\" + serviceName
sourceCacheType     = "CACHE_DATASET"
sourceCacheDataset  = env.workspace + "/Layers" #切片数据的目录
sourceTilePackage   = ""
uploadDataToServer  = "DO_NOT_UPLOAD"
scales              = "73957338.86;36978669.43;18489334.72;9244667.36;4622333.68;2311166.84;1155583.42;577791.71;288895.85;144447.93;72223.96;36111.98;18055.99"
numOfCachingServiceInstances = "2"
areaOfInterest      = ""
importExtents       = ""
overwriteTiles      = "OVERWRITE"

currentTime         = datetime.datetime.now()
arg1                = currentTime.strftime("%H-%M")
arg2                = currentTime.strftime("%Y-%m-%d %H:%M")
file                = 'D:/Project/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.ImportMapServerCache_server(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 ")

    print "Imported Map server Cache Tiles successfully for" + serviceName
    " from" + sourceCacheDataset + "\n in " + str(elapsedtime)+ "sec 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 "Imported Map server Cache Tiles "

report.close()

参数说明
在这里就只有sourceCacheDataset需要修改一下,指定到你自己的切片位置就行,我这里是放在了工作目录下,根据你自己的实际位置修改。

转载自:https://blog.csdn.net/qq_21231159/article/details/77108689

You may also like...