如何在ArcGIS Server 10.1中自动发布许多MXD文件?


12

如何自动在ArcGIS Server 10.1中发布许多mxd文件?

我大约有60个mxd文件,我想自动发布它们。有什么办法吗?


Btelliot,您的代码也适用于10.2!显然需要定义有关服务的一些细节,但这是一个了不起的起点!10X

Answers:


14

您可以使用arcpy发布您的mxd文件。

要列出您的mxd文件,请使用os.walk:

import os
import arcpy

path= r"c:\path"
for (path, dirs, files) in os.walk(path):
  for fl in files:
     if fl.lower().endswith(".mxd"):
       mxd = arcpy.mapping.MapDocument(os.path.join(path, fl))
       print mxd.filePath

然后这样:

1. AnalyzeForMSD()函数(info):分析地图文档(.mxd),以确定将地图转换为地图服务定义(MSD)文件时潜在的适用性和性能问题的来源。

例:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\ReadyForMSD.mxd")
analysis = arcpy.mapping.AnalyzeForMSD(mxd)

2. ConvertToMSD()函数(info):将地图转换为地图服务定义(MSD)文件。

例:

import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Project\ReadyForMSD.mxd")
msd = r"C:\Project\Output\Project.msd"
df = arcpy.mapping.ListDataFrames(mxd, "County Maps")[0]
arcpy.mapping.ConvertToMSD(mxd, msd, df, "NORMAL", "NORMAL")
del mxd, msd

3. PublishMSDToServer()函数(信息):将现有的地图服务定义(MSD)文件发布到指定的ArcGIS Server。

例:

import arcpy
msd = r"C:\Project\Project.msd"
arcpy.mapping.PublishMSDToServer (msd, "http://<MyServer>/arcgis/services", 
              "<MyServer>", "MyMapService", "MyMapServiceFolder", ["WMS", "KML"])

最后一件事是您应该合并所有满足您需要的功能。其实有一个教程,可以帮助ü 这里关于使用ArcPy中映射到发布地图文件到ArcGIS Server。它类似于我的文档...

总结(图像来自我上面给出的链接):

Arcgis

我希望它可以帮助您...


它会与AGS 10.1合作吗?在10.1中是* .sd而不是* .msd。
user7172 2012年

是的,这是针对10的,但是您可以针对10.1更新新的arcpy ...
Aragon

1
谢谢阿拉贡,这非常有帮助!刚刚完成了130多个MXD的自动发布。:)仅出于后代考虑,10.1工作流程为:arcpy.mapping.CreateMapSDDraft-> arcpy.StageService_server->arcpy.UploadServiceDefinition_server
Mintx


4

Aragon有一个很好的答案,但不幸的是,它不适用于ArcGIS / ArcServer 10.1。

我刚尝试过的新方法基于ArcGIS 10.1帮助。您可以在此处找到帮助文件的链接:http : //resources.arcgis.com/en/help/main/10.1/index.html#//00s30000006q000000

这是我使用代码基于指定文件夹发布MXD的方式:

#import modules
import arcpy, sys, os, string

#specify folder containing MXDs
inFolder = raw_input("Please enter folder containing 10.1 MXDs to Publish to ArcServer: ")

#specify connection File Path
connectionFilePath = r'C:\Users\<your user name>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog\<your connection file location.ags>'

#look in folder for mxds
MapPath= []
MapFolder = os.listdir(inFolder)
for file in MapFolder:
    fileExt = os.path.splitext(file)[1]
    if fileExt == ".mxd":
        MapPath = os.path.join(inFolder, file)
        file = MapPath.strip('\'')
        mxd = arcpy.mapping.MapDocument(file)
        base = os.path.basename(file)
        serviceName = base[:-4]
        SDDraft = file[:-4] + ".sddraft"
        sd = file[:-4] + ".sd"

        #Create Map SD Draft
        print "\n" + "Publishing: " + base
        analysis = arcpy.mapping.CreateMapSDDraft(mxd, SDDraft, serviceName, "FROM_CONNECTION_FILE", connectionFilePath, "False", <Service Folder Name>,  "None", "None")

        # stage and upload the service if the sddraft analysis did not contain errors
        if analysis['errors'] == {}:
            # Execute StageService
            print "Staging Service"
            arcpy.StageService_server(SDDraft, sd)
            # Execute UploadServiceDefinition
            print "Uploading Service Definition"
            arcpy.UploadServiceDefinition_server(sd, connectionFilePath)
            print "Publishing " + base +" succeeded" + "\n"
        else:
            # if the sddraft analysis contained errors, display them
            print analysis['errors']

使用此代码可能有更简单的方法,但对我有用。希望这可以帮助。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.