python页面驱动mxd_使用python添加矢量数据到mxd

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值