如何通过Arcpy打开mxd文档并添加数据

https://blog.csdn.net/zglybl/article/details/75214183

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”

addLayer = arcpy.mapping.Layer(theShape)

arcpy.mapping.AddLayer(df, addLayer, “AUTO_ARRANGE”)

arcpy.RefreshActiveView()

arcpy.RefreshTOC()

mxd.save()

x=os.startfile(mypath)

print mxd

print b
转载自:https://blog.csdn.net/hailiannanhai/article/details/80895506

You may also like...