Answers:
您可以使用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。它类似于我的文档...
总结(图像来自我上面给出的链接):
我希望它可以帮助您...
arcpy.mapping.CreateMapSDDraft
-> arcpy.StageService_server
->arcpy.UploadServiceDefinition_server
如果您想在C#中进行操作,则可以在我的博客中看到:http : //nicogis.blogspot.it/2012/10/ags-101-restful-administrative-api.html
对于转换mxd-> msd,您可以使用从c#调用的python
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']
使用此代码可能有更简单的方法,但对我有用。希望这可以帮助。