arcpy批量发布影像服务-10.2以后,不用再创建mxd

import arcpy
import os
import arcpy.mapping as mapping
def check_PubMXD(imgpath,imgName,wrkspc,service,con):

    sddraft = wrkspc + service + '.sddraft'
    arcpy.CreateImageSDDraft(imgpath, sddraft, service, 'ARCGIS_SERVER', con, True, "cs3", "Publish las MD",
                             "las,image service")
    analysis = mapping.AnalyzeForSD(sddraft)
   
    if analysis['errors'] == {}:
        arcpy.StageService_server(sddraft,wrkspc+"\\"+service+".sd")
        arcpy.UploadServiceDefinition_server(wrkspc + "\\" + service + ".sd", con)
    else:
        print(analysis['errors'])
imgpath=r"E:\TU\1.img"
imgName="2"
wrkspcm=r"E:\TU"
list = os.listdir(wrkspcm)
for f in list:
    print type(f)
    name=f.split(".")
    if(name[1]=="sd"):
        os.remove(wrkspcm+"\\"+f)
con=r"C:\Users\ThinkPad\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\arcgis on localhost_6080 (发布者).ags"

arcpy.env.workspace=wrkspcm

fsc=arcpy.ListRasters()
for fc in fsc:
    cs=fc.split('.')
    try:
        check_PubMXD(wrkspcm+"\\"+fc,"cs",wrkspcm,cs[0],con)
    except:
        b=1

你可能感兴趣的:(arcpy)