python自动发布arcgis服务

-- coding: utf-8 --自动发布mxd到server

Publishes a service to machine myserver using USA.mxd

A connection to ArcGIS Server must be established in the

Catalog window of ArcMap before running this script

Import arcpy module

import arcpy

Define local variables

wrkspc = ‘D:/arcgisdata/’
mapDoc = arcpy.mapping.MapDocument(wrkspc + ‘denggaoxian.mxd’)

Provide path to connection file

To create this file, right-click a folder in the Catalog window and

click New > ArcGIS Server Connection

out_folder_path = wrkspc
con_Filename = “connection.ags”
server_url = “http://192.168.7.42:6080/arcgis/admin
staging_folder_path = wrkspc
username = “siteadmin”
password = “hgdyfb”

arcpy.mapping.CreateGISServerConnectionFile(“ADMINISTER_GIS_SERVICES” ,
out_folder_path,
con_Filename,
server_url,
“ARCGIS_SERVER”,
False,
staging_folder_path,
username,
password,
“SAVE_USERNAME”)

Provide other service details

serviceName = ‘pythonTest’
sddraft = wrkspc + serviceName + ‘.sddraft’
sd = wrkspc + serviceName + ‘.sd’
summary = ‘summary’
tags = ‘tags’

Create service definition draft

arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, serviceName, ‘ARCGIS_SERVER’, con_Filename, True, None, summary, tags)

Analyze the service definition draft

analysis = arcpy.mapping.AnalyzeForSD(sddraft)

Print errors, warnings, and messages returned from the analysis

print “The following information was returned during analysis of the MXD:”
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,
print

Stage and upload the service if the sddraft analysis did not contain errors

if analysis[‘errors’] == {}:
# Execute StageService. This creates the service definition.
arcpy.StageService_server(sddraft, sd)

# Execute UploadServiceDefinition. This uploads the service definition and publishes the service.
arcpy.UploadServiceDefinition_server(sd, con_Filename)
print "Service successfully published"

else:
print “Service could not be published because errors were found during analysis.”

print arcpy.GetMessages()

服务器端修改,可以直接替换数据,样式不用修改

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值