Howto: 如何在VBA中使用IBasicGeoprocessor合并两个要素图层

文章编号 : 20665
软件: ArcGIS - ArcEditor 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2, 9.3, 9.3.1 ArcGIS - ArcInfo 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2, 9.3, 9.3.1 ArcGIS - ArcView 8.1, 8.1.2, 8.2, 8.3, 9.0, 9.1, 9.2, 9.3, 9.3.1
操作系统: Windows 4.0 ,2000,ME,XP
已邀请:

易智瑞技术支持

赞同来自:

摘要:
IBasicGeoprocessor包含五种方法:Dissolve, Merge, Clip, Intersect和union ,用户可在VB或VBA中调用这些方法。 Merge将相同几何类型的两个或多个要素图层进行合并并创建一个新的要素类。
内容: Merge语法为:

Set variable = object.Merge (Tables, fieldsTable, outputName)
variable - is a reference to an object that implements IFeatureClass
object - is an object expression that evaluates to an IBasicGeoprocessor object.
Tables - is an IArray object of the tables to be merged.
fieldsTable - is an ITable object that specifies the table used to determine the fields in the output feature class.
"Dissolve.Shape, Sum.Area, StdDev.Population"
合并两个要素图层的VBA代码示例如下:
示例:

Public Sub Merge()

' Get the first layer in the map
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pLayer As ILayer
Set pLayer = pMxDoc.FocusMap.Layer(0)
Dim pFeatLayer As IFeatureLayer
Set pFeatLayer = pLayer
Dim pFirstFeatClass As IFeatureClass
Set pFirstFeatClass = pFeatLayer.FeatureClass

' Get the first layer?s table
' Use the Itable interface from the Layer (not from the FeatureClass)
' This table defines which fields are to be used in the output
Dim pFirstTable As ITable
Set pFirstTable = pLayer

' Get the second layer and its table
' Use the Itable interface from the Layer (not from the FeatureClass)
Set pLayer = pMxDoc.FocusMap.Layer(1)
Dim pSecondTable As ITable
Set pSecondTable = pLayer

' Error checking
If pFirstTable Is Nothing Then
MsgBox "Table QI failed"
Exit Sub
End If

If pSecondTable Is Nothing Then
MsgBox "Table QI failed"
Exit Sub
End If

' Define the output feature class name and shape type
Dim pFeatClassName As IFeatureClassName
Set pFeatClassName = New FeatureClassName

With pFeatClassName
.FeatureType = esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = pFirstFeatClass.ShapeType
End With

' Set the output location and feature class name
Dim pNewWSName As IWorkspaceName
Set pNewWSName = New WorkspaceName

With pNewWSName
.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
.PathName = "C:\temp"
End With

Dim pDatasetName As IDatasetName
Set pDatasetName = pFeatClassName
pDatasetName.Name = "Merge_result"

Set pDatasetName.WorkspaceName = pNewWSName

' Build the input set/array ? these are the layers to be merged
Dim inputArray As IArray
Set inputArray = New esriCore.Array ' in ArcGIS 9.0 and newer versions replace with '= New esriSystem.Array'
inputArray.Add pFirstTable
inputArray.Add pSecondTable
' Perform the merge
Dim pBGP As IBasicGeoprocessor
Set pBGP = New BasicGeoprocessor
Dim pOutputFeatClass As IFeatureClass
Set pOutputFeatClass = pBGP.Merge(inputArray, pFirstTable, pFeatClassName)
' Add the output to the map
Dim pOutputFeatLayer As IFeatureLayer
Set pOutputFeatLayer = New FeatureLayer
Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
pOutputFeatLayer.Name = pOutputFeatClass.AliasName
pMxDoc.FocusMap.AddLayer pOutputFeatLayer
End Sub




创建时间:2001-11-04
最近更新: 2010-06-17


原文链接
http://support.esrichina.com.cn/2001/1104/752.html

要回复问题请先登录注册