arcpy发布地图服务

#检查地图是否有错误

import arcpy.mapping as mapping
mxdpath=r"C:\Users\h\Desktop\fp.mxd"
wrkspc = r'd:'
mxd = mapping.MapDocument(wrkspc + r"\fp.mxd")

service = 'Crime'
sddraft = wrkspc + service + '.sddraft'
mapping.CreateMapSDDraft(mxd, sddraft, service)
analysis = mapping.AnalyzeForSD(wrkspc + "Crime.sddraft")

for key in ('messages', 'warnings', 'errors'):
    print("----" + key.upper() + "----")
    vars = analysis[key]
    for ((message, code), layerlist) in vars.iteritems():
        print "    ", message, " (CODE %i)" % code
        print("     applies to:")
        for layer in layerlist:
            print(layer.name)
#发布地图服务
import arcpy
import arcpy.mapping as mapping

wrkspc = r'd:'
mxd = mapping.MapDocument(wrkspc + r"\fp.mxd")

service = 'Crime'
sddraft = wrkspc + service + '.sddraft'
mapping.CreateMapSDDraft(mxd, sddraft, service)
analysis = mapping.AnalyzeForSD(wrkspc + "Crime.sddraft")
con=r"C:\Users\h\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\arcgis on localhost_6080 (publisher).ags"
if analysis['errors'] == {}:
    #execute StageService
    #arcpy.StageService_server(sddraft,wrkspc+"\\"+service+".sd")
    #execute UploadServiceDefinition
    arcpy.UploadServiceDefinition_server(wrkspc+"\\"+service+".sd", con)
else:
    #if the sddraft analysis contained errors, display them
    print(analysis['errors'])

转载自:https://blog.csdn.net/A873054267/article/details/85935648

You may also like...