幾個(gè)注意點(diǎn)
- 連接的字符串可以從catalog中看嘿棘,不用加severs
- 服務(wù)的后綴
.MapServer
要加 -
scale
要和切片服務(wù)相匹配
代碼如下
# Name: ManageMapServerCacheTiles.py
# Description: The following stand-alone script demonstrates how to Recreate all
# cache tiles for the scales in the cache tiling scheme.
# Requirements: os, sys, time and 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 = "D:/workplace"
# List of input variables for map service properties
connectionFile = r"C:\Users\Administrator\AppData\Roaming\ESRI\Desktop10.4\ArcCatalog"
server = "arcgis on localhost_6080 (admin)"
serviceName = "qd.MapServer"
inputService = connectionFile + "\\" + server + "\\" + serviceName
scales = [250000, 125000, 64000,32000 ]
numOfCachingServiceInstances = 2
updateMode = "RECREATE_ALL_TILES"
areaOfInterest = ""
waitForJobCompletion = "WAIT"
updateExtents = ""
currentTime = datetime.datetime.now()
arg1 = currentTime.strftime("%H-%M")
arg2 = currentTime.strftime("%Y-%m-%d %H:%M")
file = "D:/workplace/report_%s.txt" % arg1
# print results of the script to a report
report = open(file, 'w')
try:
starttime = time.clock()
result = arcpy.ManageMapServerCacheTiles_server(inputService, scales,
updateMode,
numOfCachingServiceInstances,
areaOfInterest, updateExtents,
waitForJobCompletion)
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 tiles for given schema successfully for " + \
serviceName + " 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)
report.close()
print "Created Map server Cache Tiles "
參考ArcGIS 官方文檔