Howto: 如何在VBA中使用IBasicGeoprocessor裁切一个要素图层

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

易智瑞技术支持

赞同来自:

摘要:
IBasicGeoprocessor包含五种方法:Dissolve, Merge, Clip, Intersect和union ,用户可在VB或VBA中调用这些方法。 Clip方法根据覆盖图层的空间范围对点、线、面要素图层要素进行裁切。输入要素图层的属性被赋值到输出要素类中。
内容: Clip语法为:

Set variable = object.Clip(InputTable, useSelectedInput, clipTable, useSelectedClip, Tolerance, outputName)
参数意义如下:
Variable-是对实现了IFeatureClass接口对象的一个引用
Object-等同于IBasicGeoprocessor的对象
InputTable-一个ITable对象
useSelectedInput-一个布尔值,代表输入图层中的选中状态。用于指示是否只裁切输入图层中选中的
要素。False代表裁切操作将忽略输入图层中的选中子集。
clipTable-一个ITable对象。
useSelectedClip-是个布尔值,代表裁切图层中的选中状态。用于指示在裁切过程中是否使用裁切图
层中的选中要素,False代表裁切操作将忽略裁切图层中的选中子集。
Tolerance-代表容差的一个双精度值。是裁切过程中的容差,如果输入0.0则将使用系统默认值,数
据框架范围的10000分之一。
outputName-一个IFeatureClassName对象。
VBA中的示例如下:

Public Sub Clip()
' Get the input layer and feature class.
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument
Dim pLayer As ILayer
Set pLayer = pMxDoc.FocusMap.Layer(0)
Dim pInputFeatLayer As IFeatureLayer
Set pInputFeatLayer = pLayer
Dim pInputTable As ITable
Set pInputTable = player
' Get the input feature class.
' Use the Itable interface from the Layer (not from the FeatureClass)
' The Input feature class properties, such as shape type,
' will be needed for the output.
Dim pInputFeatClass As IFeatureClass
Set pInputFeatClass = pInputFeatLayer.FeatureClass
' Get the clip/overlay layer
' Use the Itable interface from the Layer (not from the FeatureClass)
Set pLayer = pMxDoc.FocusMap.Layer(1)
Dim pClipTable As ITable
Set pClipTable = pLayer
' Error checking
If pInputTable Is Nothing Then
MsgBox "Table QI failed"
Exit Sub
End If
If pClipTable Is Nothing Then
MsgBox "Table QI failed"
Exit Sub
End If
' Define the output feature class name and shape type (taken from the
' properties of the input feature class)
Dim pFeatClassName As IFeatureClassName
Set pFeatClassName = New FeatureClassName
With pFeatClassName
.FeatureType = esriFTSimple
.ShapeFieldName = "Shape"
.ShapeType = pInputFeatClass.ShapeType
End With
' Set output location and feature class name
Dim pNewWSName As IWorkspaceName
Set pNewWSName = New WorkspaceName
' For ArcGIS 8.x, uncomment and use this line:
'pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory"
' For ArcGIS 9.0 and 9.1, use this line instead:
pNewWSName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory"
pNewWSName.PathName = "C:\temp"
Dim pDatasetName As IDatasetName
Set pDatasetName = pFeatClassName
pDatasetName.Name = "Clip_result"
Set pDatasetName.WorkspaceName = pNewWSName
' Set the tolerance. Passing 0.0 causes the default tolerance to be used.
' The default tolerance is 1/10,000 of the extent of the data frame?s spatial domain
Dim tol As Double
tol = 0#
' Perform the clip
Dim pBGP As IBasicGeoprocessor
Set pBGP = New BasicGeoprocessor
Dim pOutputFeatClass As IFeatureClass
Set pOutputFeatClass = pBGP.clip(pInputTable, False, pClipTable, False, _
tol, pFeatClassName)
' Add the output layer (clipped features) 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
在ArcGIS Desktop 8.3中运行如上代码。
在ArcGIS 9.2 SP1版本之前,有一个已知的问题导致该段代码无法正常运行。在该版本下,请用Clip地理空间处理工具来完成同样的功能。

Public Sub Clip_GP()
Dim pParams As IVariantArray
Set pParams = New VarArray
' Input feature layer name in TOC
pParams.Add "states"
' Clip feature layer name in TOC
pParams.Add "Clip_layer"
' Output feature class name and location
pParams.Add "C:\temp\Clip_states.shp"
' Execute the tool
Dim pGP As IGeoProcessor
Set pGP = New GeoProcessor
Dim pGPResults As IGeoProcessorResult
Set pGPResults = pGP.Execute("Clip_analysis", pParams, Nothing)
End Sub




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


原文链接
http://support.esrichina.com.cn/2001/1010/753.html

要回复问题请先登录注册