您的位置:首页 > 编程语言 > VB

VBA之添加Shape图层

2012-11-08 02:44 239 查看
参考DeskTop帮助文档

准备:添加一个Button控件

Tools—>Customize—>Commands tab—> UIControl—>IButtonControl

在该Button的Click事件中添加以下代码:

Dim pWorkspaceFactory As IWorkspaceFactory

Set pWorkspaceFactory = New ShapefileWorkspaceFactory

Dim pWorkSpace As IFeatureWorkspace

'Change ‘e:\street’ to the source location of the shapefile you wish to add

Set pWorkSpace = pWorkspaceFactory.OpenFromFile("e:\street", 0)

Dim pClass As IFeatureClass

'Change polygon to the name of the shapefile you wish to add

Set pClass = pWorkSpace.OpenFeatureClass("polygon")

Dim pLayer As IFeatureLayer

Set pLayer = New FeatureLayer

Set pLayer.FeatureClass = pClass

pLayer.Name = pClass.AliasName

Dim pMxDoc As IMxDocument

Set pMxDoc = ThisDocument

pMxDoc.AddLayer pLayer

pMxDoc.ActiveView.PartialRefresh esriViewGeography, pLayer, Nothing
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: