zoukankan      html  css  js  c++  java
  • 使用Python创建.sd服务定义文件,实现脚本自动发布ArcGIS服务

    借助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.comWPServiceshhPublishServiceToolData" //定义一个文件路径
    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']
    


    ------------------------------欢迎来访,拒绝转载------------------------------




    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    基于摸板匹配的目標跟蹤算法
    spoj 2713 Can you answer these queries IV
    zoj 3633 Alice's present
    hdu 3642 Get The Treasury
    poj 1195 Mobile phones
    poj 2760 End of Windless Days
    zoj 3540 Adding New Machine
    spoj 1716 Can you answer these queries III
    spoj 1043 Can you answer these queries I
    spoj 2916 Can you answer these queries V
  • 原文地址:https://www.cnblogs.com/gishh/p/4732854.html
Copyright © 2011-2022 走看看