1、添加shp数据到mxd
# -*-coding:utf-8-*- import arcpy mxd = arcpy.mapping.MapDocument(r"E:\testmxd\testmxd.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] theShape = r"E:\testmxd\江夏区.shp" addLayer = arcpy.mapping.Layer(theShape) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") #Save to a new map document and clear variable references mxd.saveACopy(r"E:\testmxd\testmxd1.mxd") del mxd
2、添加sde中的要素类到mxd
# -*- coding: utf-8 -*- import arcpy from arcpy import env import os env.overwriteOutput = True def CopyDatabase(InputSDE,OutputSDE): print("Input SDE file Path "+InputSDE) print("Output SDE file Path"+OutputSDE) print("Open SDE") arcpy.env.workspace=InputSDE print("Start mxd...") for fea in arcpy.ListFeatureClasses(): try: if (fea=="SDE.jiangxia"): print "Copying table " + fea + " to " + OutputSDE mxd = arcpy.mapping.MapDocument(r"E:\testmxd\testmxd1.mxd") df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] addLayer = arcpy.mapping.Layer(fea) arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE") # Save to a new map document and clear variable references mxd.saveACopy(r"E:\testmxd\testmxd2.mxd") print "ok" except Exception: print("Filed Copy table "+fea) continue inputsde=r'C:\Users\admin\AppData\Roaming\Esri\Desktop10.6\ArcCatalog\Connection to orcl.sde' outputsde=r'C:\Users\admin\AppData\Roaming\Esri\Desktop10.6\ArcCatalog\Connection to orcl.sde' CopyDatabase(inputsde,outputsde)
效果图:
参考资料:
http://desktop.arcgis.com/zh-cn/arcmap/latest/analyze/arcpy-mapping/addlayer.htm
作者:gislaozhang
链接:https://blog.csdn.net/gislaozhang/article/details/91447835
来源:CSDN
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。