藉助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']