Python创建服务代码参考

#-*-coding:utf-8
__author__ = 'suwen'
import os
import arcpy
def CreateContectionFile(wrkspc,userName,password,serverName):

      # con = 'http://localhost:6080/arcgis/admin'
    con="http://"+str(serverName)+":6080/arcgis/admin"
    connection_file_path=str(wrkspc)+"/tmp.ags"
    #
    if os.path.exists(connection_file_path):
        os.remove(connection_file_path)
    agsname=os.path.basename(connection_file_path)
    arcpy.mapping.CreateGISServerConnectionFile("ADMINISTER_GIS_SERVICES",
                                                    wrkspc,
                                                   agsname,
                                                    con,
                                                    "ARCGIS_SERVER",
                                                    username=userName,
                                                    password=password,
                                                    save_username_password=True)

    return connection_file_path


def PublishService(connection_file_path,wrkspc,mapDoc):
    #get the serviceName
    serviceName =os.path.basename(mapDoc).replace(".mxd","")

   #create the .sddraft path
    sddraftname=os.path.basename(mapDoc).replace(".mxd",".sddraft")
    sddraft =str(wrkspc)+"/"+str(sddraftname)
    #create the .sd file path
    sdname=os.path.basename(mapDoc).replace(".mxd",".sd")
    sd=str(wrkspc)+"/"+str(sdname)
   #check the file exists or not
    if(os.path.exists(sd)):
        os.remove(sd)

    analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, 'ARCGIS_SERVER',
                                              connection_file_path, True, None,None,None)

    arcpy.StageService_server(sddraft, sd)
    arcpy.UploadServiceDefinition_server(sd, connection_file_path)

connection_file_path="C:\Users\suwen\AppData\Local\Esri\Desktop10.2\Staging"
mxdfolder=u"D:\数据\china"
userName="arcgis"
password="arcgis"
serverName="192.168.220.64"
wrkspc=r"d:\数据\china"

connection_file_path=CreateContectionFile(wrkspc,userName,password,serverName)
# the mxd file list of the mxdPath

mxds=os.listdir(mxdfolder)
mxd_files=[]
for file in mxds:
    if file.endswith(".mxd"):
        mxdpath=os.path.join(mxdfolder,file)
        mxd_files.append(mxdpath)

for mxd in mxd_files:
    PublishService(connection_file_path,wrkspc,mxd)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值