美文网首页
使用python连接arcgis sever管理瓦片Manage

使用python连接arcgis sever管理瓦片Manage

作者: 家琦的三亩地 | 来源:发表于2016-10-11 16:25 被阅读0次

几个注意点

  1. 连接的字符串可以从catalog中看,不用加severs
  • 服务的后缀.MapServer要加
  • scale要和切片服务相匹配

代码如下

# 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 官方文档

相关文章

网友评论

      本文标题:使用python连接arcgis sever管理瓦片Manage

      本文链接:https://www.haomeiwen.com/subject/podbyttx.html