使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务

借助ArcGIS桌面发布ArcGIS服务是一个很熟悉的过程了,发布服务的前提是需要拥有一个已连接的ArcGIS Server服务站点,经过对mxd进行制图配置,定义服务参数,才能实现服务的发布,那么这个过程的自动化和一体化又该如何使用python脚本实现呢?直奔主题~~~~

-------------------------欢迎来访,拒绝转载--------------------------

1.创建ArcGIS Server的连接文件:


# -*- coding: utf-8 -*-
# ---------------------------------------------------------------------------
# PublishMapService.py
# Created on: 2015-08-15 15:49:27.00000
#   (generated by HUIHUI)
# Usage:  
# Description: python publish service
# ---------------------------------------------------------------------------

# Import arcpy module
import os as OS
import arcpy

# createGISServerConnectionFile,define local variable
wrkpc = r"\\qnap.geoWindPower.com\WPServices\hh\PublishService\ToolData" //定义一个文件路径
out_folder_path = wrkpc
con_Filename = "test.ags"
server_url = r"http://gisserver018207.geoWindPower.com/arcgis" //ArcGIS Server站点的URL
staging_folder_path = wrkpc
username = "admin" //站点用户名
password = "admin" //密码

arcpy.mapping.CreateGISServerConnectionFile("PUBLISH_GIS_SERVICES",
                                            out_folder_path,
                                            con_Filename,
                                            server_url,
                                            "ARCGIS_SERVER",
                                            False,
                                            staging_folder_path,
                                            username,
                                            password,
                                            "SAVE_USERNAME")

2. creste service definition draft


# define local variables
mxdpath = OS.path.join(wrkpc,"mymxd.mxd")  //指定MXD所在的路径
mapDoc = arcpy.mapping.MapDocument(mxdpath)
servicename = "GeoTurbine_Test"
sddraft = OS.path.join(wrkpc,"GeoTurbine_Test.sddraft") //指定<span style="font-family: Arial, Helvetica, sans-serif;">.sddraft文件所在的路径</span>
sd = OS.path.join(wrkpc,"GeoTurbine_Test.sd")
connectionfile = <span style="font-family:Arial, Helvetica, sans-serif;font-size:12px;">con_Filename</span>
summary = "this is a test"
tags = "this is a test"

# creste service definition draft
analysis = arcpy.mapping.CreateMapSDDraft(mapDoc,
                                          sddraft,
                                          servicename,
                                          "ARCGIS_SERVER",
                                          connectionfile,
                                          False,
                                          "WP_MapService",
                                          summary,tags)

3.上传.sddraft的草稿文件(发布服务)

#stage and upload the service if the sddraft analysis didn't contain errors
if analysis['errors'] == {}:
    # excute StageService
    arcpy.StageService_server(sddraft,sd)
    # excute UploadServiceDfinition
    arcpy.UploadServiceDefinition_server(sd,connectionfile)
else:
    # if the sddraft analysis contained errors,display them
    print analysis['errors']


------------------------------欢迎来访,拒绝转载------------------------------




版权声明:本文为博主原创文章,未经博主允许不得转载。

转载于:https://www.cnblogs.com/gishh/p/4732854.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值