首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計綜合問答

ArcPy 發布地圖服務並同時啟用 WMS 的官方解決方案

     編輯:程式設計綜合問答

問題背景

使用 ArcPy 在 ArcGIS 10.1 中發布地圖服務,需同時啟用 WMS 能力。

官方幫助文檔指引

已解決,具體參考 Esri 官方文檔:

ArcGIS 10.1 Help: Enable WMS capability when publishing a map service with ArcPy

關鍵步驟摘要

  1. 創建 MapServer 服務定義草稿(.sddraft)
  2. 修改草稿 XML,添加 <TypeName>WMS</TypeName> 到 <Capabilities> 節點
  3. 使用 arcpy.StageService 編譯為 .sd
  4. 用 arcpy.UploadServiceDefinition 發布到 Server

核心代碼片段

import arcpy, xml.dom.minidom as DOM

# 1. 創建草稿
arcpy.mapping.CreateMapSDDraft(map_doc, sddraft_path, service_name, 'ARCGIS_SERVER', 
                               connection_file, True, None, summary, tags)

# 2. 修改 XML 啟用 WMS
doc = DOM.parse(sddraft_path)
type_names = doc.getElementsByTagName('TypeName')
for type_name in type_names:
    if type_name.firstChild.data == 'WMS':
        # 找到父節點 Configuration,設置 Enabled = 'true'
        config = type_name.parentNode
        for child in config.childNodes:
            if child.tagName == 'Enabled':
                child.firstChild.data = 'true'
                break
doc.writexml(open(sddraft_path, 'w'))

# 3. 編譯與發布
arcpy.StageService_server(sddraft_path, sd_path)
arcpy.UploadServiceDefinition_server(sd_path, connection_file)

注意事項

  • 需 ArcGIS Server 已安裝 WMS 擴展並授權
  • 服務屬性中 capabilities 需包含 "WMS"
  • 10.1 版本較老,建議升級至 10.8+ 或 ArcGIS Enterprise 10.9+ 獲得更好支持
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved