如何进行层与层之间的逻辑运算
本例要实现的是将两个同一GeometryType图层联合成为一个图层,输出Shape文件,并且加载到Map中显示出来。
l 要点
定义ITable的两个接口变量,通过两个图层FeatureClass实例化。然后由接口IFeatureClassName、IWorkspaceName和IDatasetName实现创建一个新的shape文件。再创建IBasicGeoprocessor接口对象,使用IBasicGeoprocessor.Union方法实现两个图层的联合。
l 程序说明
过程UIButtonControl1_Click是实现模块。
l 代码
|
Option Explicit Private Sub UIButtonControl1_Click() Dim pMxDoc As IMxDocument Dim pLayer As ILayer Dim pInputTable As ITable Dim pOverlayTable As ITable Dim pFeatClassName As IFeatureClassName Dim pNewWSName As IWorkspaceName Dim pDatasetName As IDatasetName Dim dtol As Double Dim pBasicGeop As IBasicGeoprocessor Dim pOutputFeatClass As IFeatureClass Dim pOutputFeatLayer As IFeatureLayer Dim App As VBProject On Error GoTo ErrorHandler: Set pMxDoc = ThisDocument Set pLayer = pMxDoc.FocusMap.Layer(0) Set App = ThisDocument.VBProject ' Get the input table ' Use the Itable interface from the Layer (not from the FeatureClass) Set pInputTable = pLayer ' Get the overlay layer and table ' Use the Itable interface from the Layer (not from the FeatureClass) Set pLayer = pMxDoc.FocusMap.Layer(1) Set pOverlayTable = pLayer ' Error checking If pInputTable Is Nothing Then MsgBox "Table QI failed" Exit Sub End If If pOverlayTable Is Nothing Then MsgBox "Table QI failed" Exit Sub End If ' Define the output feature class name Set pFeatClassName = New FeatureClassName ' Set output location and feature class name Set pNewWSName = New WorkspaceName pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapeFileWorkspaceFactory.1" pNewWSName.PathName = App.FileName & "\.." Set pDatasetName = pFeatClassName pDatasetName.Name = "Union_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 dtol = 0# ' Perform the union Set pBasicGeop = New BasicGeoprocessor Set pOutputFeatClass = pBasicGeop.Union(pInputTable, False, pOverlayTable, False, _dtol, pFeatClassName) ' Add the output layer to the map Set pOutputFeatLayer = New FeatureLayer Set pOutputFeatLayer.FeatureClass = pOutputFeatClass pOutputFeatLayer.Name = pOutputFeatClass.AliasName pMxDoc.FocusMap.AddLayer pOutputFeatLayer Exit Sub ErrorHandler: MsgBox Err.Description End Sub |
浙公网安备 33010602011771号