当前位置:网站首页>ArcGIS secondary development -- arcpy batch automatic map publishing service

ArcGIS secondary development -- arcpy batch automatic map publishing service

2022-06-26 14:22:00 Chaoying.

Reference blog

Add : Before publishing the map service , First you need to connect to ArcGIS for Server The server , Need to make use of arcpy.mapping.CreateGISServerConnectionFile Interface ,, stay ArcGIS There are also detailed instructions in the help document of , The code is as follows :

import arcpy

outdir = r'C:\Users\user\Desktop\SeaGIS\Server'
out_folder_path = outdir
out_name = 'connection.ags'
server_url = 'https://localhost:6443/arcgis/admin'
use_arcgis_desktop_staging_folder = False
staging_folder_path = outdir
username = 'siteadmin'
password = 'arcgis'

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

For the description of related functions, see ArcGIS Help document

import arcpy
import os


def publishServer(mxd):
    # define local variables
    wrkspc = 'C:/Users/user/Desktop/SeaGIS'
    mapDoc = arcpy.mapping.MapDocument(wrkspc + '/mxds' + '/{}'.format(mxd))
    con = wrkspc + '/Server' + '/connection.ags'
    service = mxd[0:-4]
    sddraft = wrkspc + '/Server' + '/' + service + '.sddraft'
    sd = wrkspc + '/Server' + '/' + service + '.sd'
    summary = '{} Ser Wave'.format(mxd[0:-4])
    tags = 'Sea Wave'

    # create service definition draft
    analysis = arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER',
                                              con, True, 'SeaGIS', summary, tags)

    # stage and upload the service if the sddraft analysis did not contain errors
    if analysis['errors'] == {
    }:
        # Execute StageService
        arcpy.StageService_server(sddraft, sd)
        # Execute UploadServiceDefinition
        arcpy.UploadServiceDefinition_server(sd, con)
        print '{} has been published!'.format(mxd)
    else:
        # if the sddraft analysis contained errors, display them
        print analysis['errors']


mds = os.listdir('./mxds')
for md in mds:
    publishServer(md)
print 'finished!'
原网站

版权声明
本文为[Chaoying.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202170508311096.html