因为太多的服务需要发布,后期考虑使用arcpy脚本自动发布服务。
以下是预研记录。
arcgis server 10.2.2 的python是64位的,服务器上安装vscode ,要选择使用64位版本的python ,并参考如下配置
其次,arcgis server发布服务的数据源需要是 file GeoDatabase,或者是SDE 的,而不能是 mdb或者shapefile 。看官方文档:
不然就会报这样的错误, 不可访问,其实数据源都可以连接。
初始版本
#coding=utf-8 import arcpy import arcpy.mapping as mapping import os folder=r'd:out' files=os.listdir(folder) for f in files: if not f.endswith(".mxd"): continue service=f.replace(".mxd","") mxdpath=os.path.join(folder,f) print f sddraft=mxdpath.replace(".mxd",".sddraft") mxd=mapping.MapDocument(mxdpath) mapping.CreateMapSDDraft(mxd,sddraft,service) #将地图文档 (.mxd) 文件转换为服务定义草稿 (.sddraft) 文件。 analysis=mapping.AnalyzeForSD(r'd:out est3.sddraft') #分析服务定义草稿 (.sddraft) 文件以便在将服务定义草稿文件转换为服务定义 (.sd) 文件之前确定适用性和潜在性能问题的来源 sd=mxdpath.replace(".mxd",".sd") insever=r'connection.ags' if analysis['errors']=={}: arcpy.StageService_server(sddraft,sd) #函数StageService_server将服务定义草稿(.sddraft)转换成服务定义;sd为生成的服务定义,默认情况下跟草稿服务定义写入同一目录;过渡完成后,输入的服务定义草稿即被删除 arcpy.UploadServiceDefinition_server(sd,insever) #根据服务定义文件上传发布GIS服务至特定的服务器 else: print(analysis['errors'])
发布成功
connection.ags创建
# -*- coding: utf-8 -*- import arcpy import os import xml.dom.minidom as DOM out_folder_path='d:out' out_name = 'connection.ags' server_url = 'http://192.168.119.233:6080/arcgis/manager/' use_arcgis_desktop_staging_folder = False staging_folder_path = out_folder_path username = 'arcgisadmin' password = 'arcgisadmin' out_file_path = os.path.join(out_folder_path, out_name) if os.path.exists(out_file_path): os.remove(out_file_path) arcpy.mapping.CreateGISServerConnectionFile('ADMINISTER_GIS_SERVICES', out_folder_path, out_name, server_url, 'ARCGIS_SERVER', use_arcgis_desktop_staging_folder, staging_folder_path, username, password, True) print 'over'