VBA之添加Shape图层

来源:互联网 发布:php兄弟连毕业怎么样 编辑:程序博客网 时间:2024/06/08 12:30
参考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
原创粉丝点击