借助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']
------------------------------欢迎来访,拒绝转载------------------------------
版权声明:本文为博主原创文章,未经博主允许不得转载。