1、在打开ArcMap工程文档的前提下,使用内嵌在ArcMap里的命令行窗口,将数据添加到当前的mxd文档中,参考代码如下:
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
theShape = r"E:\zgl.shp"
addLayer = arcpy.mapping.Layer(theShape)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
2、只通过脚本文件.py,实现打开mxd文档并添加数据。
import arcpy
import os
mypath=r"E:\zgl2.mxd"
mxd = arcpy.mapping.MapDocument(mypath)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
theShape = r"E:\zgl.shp"
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.save()
x=os.startfile(mypath)
print mxd
print b
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
theShape = r"E:\zgl.shp"
addLayer = arcpy.mapping.Layer(theShape)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
2、只通过脚本文件.py,实现打开mxd文档并添加数据。
import arcpy
import os
mypath=r"E:\zgl2.mxd"
mxd = arcpy.mapping.MapDocument(mypath)
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
theShape = r"E:\zgl.shp"
addLayer = arcpy.mapping.Layer(theShape)
arcpy.RefreshActiveView()
arcpy.RefreshTOC()
mxd.save()
x=os.startfile(mypath)
print mxd
print b
本文介绍了两种在ArcMap中添加图层的方法:一种是在ArcMap工程文档打开状态下使用命令行窗口添加;另一种是通过.py脚本文件实现mxd文档的打开及数据的添加,并保存与启动mxd文档。

4307

被折叠的 条评论
为什么被折叠?



