Howto: 如何在VBA中使用IBasicGeoprocessor的Dissolve方法

文章编号 : 20606
软件: 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
已邀请:

EsriSupport

赞同来自:

摘要:
IBasicGeoprocessor包含五种方法:Dissolve, Merge, Clip, Intersect和union ,用户可在VB或VBA中调用这些方法。 Dissolve方法将创建一个新的表格,并根据指定字段值从输入各表中向其添加记录。本文说明了如何用Dissolve方法生成的输出表创建一个新的要素图层或是单独表。
内容:
Dissolve语法为: Set variable = object.Dissolve (InputTable, useSelected, dissolveField, summaryFields, outputName )
object - is an object expression that evaluates to an IBasicGeoprocessor object.
variable - is a reference to an object that implements ITable.
InputTable - is an ITable object.
useSelected - is a Boolean expression that represents the useSelected state. It controls whether or not a selected subset of the InputTable will be dissolved. True signifies a selected subset will be dissolved. False signifies Dissolve will ignore any selected subset and will dissolve the entire set.
dissolveField - is a string expression that represents the dissolveField.
summaryFields - is a string expression that represents the summaryFields.
outputName - is an IDatasetName object.
总结字段列表以?开头,列出了生成的摘要字段列表。摘要操作包括:
? Dissolve
? Count
? Minimum
? Maximum
? Sum
? Average
? Variance
? StdDev

字段总结语法为:
"Dissolve.Shape, Sum.Area, StdDev.Population"
如果你想创建一个单独的摘要列表,你可以从摘要字段列表中忽略Dissolve.shape。
输出中代表dissolve字段的那个字段就像在地里空间处理向导中一样,不会被自动计算。你有可能希
望在输出文件中返回dissolve字段中的最小值。
"Sum.Area, StdDev.Population"
下面的VBA示例代码假设你有一个名为STATES的图层,SUB_REGION和AREA字段名。

示例1:
Public Sub Dissolve()
Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap

' Find the layer named STATES
Dim pLayer As ILayer
Dim pInputFeatLayer As IFeatureLayer
Dim intCount As Integer
For intCount = 0 To pMap.LayerCount - 1
Set pLayer = pMap.Layer(intCount)
If TypeOf pLayer Is IFeatureLayer Then
If pLayer.Name = "STATES" Then
Set pInputFeatLayer = pLayer
Exit For
End If
End If
Next
If pInputFeatLayer Is Nothing Then
MsgBox "The STATES layer was not found"
Exit Sub
End If

' Get input table
' Use the Itable interface from the Layer (not from the FeatureClass)
Dim pInputTable As ITable
Set pInputTable = pInputFeatLayer

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

' Make sure there is a field call SUB_REGION in the input layer
If pInputTable.FindField("SUB_REGION") = -1 Then
MsgBox "There must be a field named SUB_REGION in STATES"
Exit Sub
End If

' Get feature class properties needed for output
Dim pInputFeatCLass As IFeatureClass
Set pInputFeatCLass = pInputFeatLayer.FeatureClass
Dim pFeatClassName As IFeatureClassName
Set pFeatClassName = New FeatureClassName
With pFeatClassName
.FeatureType = esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = pInputFeatCLass.ShapeType
End With

' Set output location and output feature class name
Dim pNewWSName As IWorkspaceName
Set pNewWSName = New WorkspaceName
pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
pNewWSName.PathName = "c:\temp"

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

Set pDatasetName.WorkspaceName = pNewWSName

' Perform the dissolve.
' Note the summary fields string (Dissolve.Shape, Minimum.state_name ...)
' below. This is a comma-delimited string that lists the generated summary
' fields. The syntax for the summaryFields argument is
' <operation_code1>.<field_name1>, <operation_codeN>.<field_nameN>?
' Operation codes include: Dissolve, Count, Minimum, Maximum, Sum,
' Average, Variance and StdDev.
'
' Since we are performing a spatial dissolve, we must use the operation code
' Dissolve' on the Shape field.
Dim iBGP As IBasicGeoprocessor
Set iBGP = New BasicGeoprocessor
Dim pOutputTable As ITable
Set pOutputTable = iBGP.Dissolve(pInputTable, False, "SUB_REGION", _
"Dissolve.Shape, Minimum.SUB_REGION, Count.SUB_REGION, Average.AREA", _
pDatasetName)

' Add the output to the map
Dim pOutputFeatClass As IFeatureClass
Set pOutputFeatClass = pOutputTable

' Error checking
If pOutputFeatClass Is Nothing Then
MsgBox "FeatureClass QI Failed"
Exit Sub
End If

Dim pOutputFeatLayer As IFeatureLayer
Set pOutputFeatLayer = New FeatureLayer
Set pOutputFeatLayer.FeatureClass = pOutputFeatClass
pOutputFeatLayer.Name = pOutputFeatClass.AliasName
pMap.AddLayer pOutputFeatLayer

End sub

示例2:
Option Explicit

Sub CreateSummaryTable()
' creates a summary table using Dissolve and adds it to ArcMap
' as a standalone table. run the macro, then make sure the Source
' tab is active in the Table of Contents to see the new table.

Dim pDoc As IMxDocument
Set pDoc = ThisDocument
Dim pMap As IMap
Set pMap = pDoc.FocusMap

' Find the layer named STATES
Dim pLayer As ILayer
Dim pInputFeatLayer As IFeatureLayer
Dim intCount As Integer
For intCount = 0 To pMap.LayerCount - 1
Set pLayer = pMap.Layer(intCount)
If TypeOf pLayer Is IFeatureLayer Then
If pLayer.Name = "STATES" Then
Set pInputFeatLayer = pLayer
Exit For
End If
End If
Next
If pInputFeatLayer Is Nothing Then
MsgBox "The STATES layer was not found"
Exit Sub
End If

' Get input table
' Use the Itable interface from the Layer (not from the FeatureClass)
Dim pInputTable As ITable
Set pInputTable = pInputFeatLayer

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

' Make sure there is a field call SUB_REGION in the input layer
If pInputTable.FindField("SUB_REGION") = -1 Then
MsgBox "There must be a field named SUB_REGION in STATES"
Exit Sub
End If

' Set up the output location
Dim pNewWSName As IWorkspaceName
Set pNewWSName = New WorkspaceName
' shapefile flavor will work just fine
pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
pNewWSName.PathName = "c:\temp"

' Set up the output table
Dim pOutTabName As ITableName
Set pOutTabName = New TableName
Dim pDatasetName As IDatasetName
Set pDatasetName = pOutTabName
pDatasetName.Name = "dissolve_summary_tab"
Set pDatasetName.WorkspaceName = pNewWSName

' Perform the dissolve.
' Note the summary fields string (Minimum.SUB_REGION...)
' below. This is a comma-delimited string that lists the generated summary
' fields. The syntax for the summaryFields argument is
' <operation_code1>.<field_name1>, <operation_codeN>.<field_nameN>?
' Operation codes include: Dissolve, Count, Minimum, Maximum, Sum,
' Average, Variance and StdDev.
'
' We are using the output table to build a standalone table, so we
' can omit Shape.Dissolve from the beginning of the string
Dim iBGP As IBasicGeoprocessor
Set iBGP = New BasicGeoprocessor
Dim pOutputTable As ITable
Set pOutputTable = iBGP.Dissolve(pInputTable, False, "SUB_REGION", _
"Minimum.SUB_REGION, Count.SUB_REGION, Average.AREA", _
pDatasetName)

' add the table to map
Dim pStTab As IStandaloneTable
Set pStTab = New StandaloneTable
Set pStTab.Table = pOutputTable
Dim pStTabColl As IStandaloneTableCollection
Set pStTabColl = pMap
pStTabColl.AddStandaloneTable pStTab

' Refresh the TOC
pDoc.UpdateContents

End Sub






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


原文链接
http://support.esrichina.com.cn/2001/1004/751.html

要回复问题请先登录注册