阅读:1255回复:2
在ARCSCENE环境里, 如何在VBA里面写合并两个层的代码??主要是用哪个接口?有人知道吗??谢谢了。。。
<P>在ARCSCENE环境里, 如何在VBA里面写合并两个层的代码??主要是用哪个接口?有人知道吗??谢谢了。。。</P>
|
|
1楼#
发布于:2006-07-31 11:16
<TABLE cellSpacing=0 cellPadding=2 width="75%" align=center border=0>
<TR> <TD class=tdWhite> <DIV>Public Sub Merge() <BR><BR>' Get the first layer in the map <BR>Dim pMxDoc As IMxDocument <BR>Set pMxDoc = ThisDocument <BR>Dim pLayer As ILayer <BR>Set pLayer = pMxDoc.FocusMap.Layer(0) <BR>Dim pFeatLayer As IFeatureLayer <BR>Set pFeatLayer = pLayer <BR>Dim pFirstFeatClass As IFeatureClass <BR>Set pFirstFeatClass = pFeatLayer.FeatureClass <BR><BR>' Get the first layer’s table <BR>' Use the Itable interface from the Layer (not from the FeatureClass) <BR>' This table defines which fields are to be used in the output <BR>Dim pFirstTable As ITable <BR>Set pFirstTable = pLayer <BR><BR>' Get the second layer and its table <BR>' Use the Itable interface from the Layer (not from the FeatureClass) <BR>Set pLayer = pMxDoc.FocusMap.Layer(1) <BR>Dim pSecondTable As ITable <BR>Set pSecondTable = pLayer <BR><BR>' Error checking <BR>If pFirstTable Is Nothing Then <BR>MsgBox "Table QI failed" <BR>Exit Sub <BR>End If <BR><BR>If pSecondTable Is Nothing Then <BR>MsgBox "Table QI failed" <BR>Exit Sub <BR>End If <BR><BR>' Define the output feature class name and shape type <BR>Dim pFeatClassName As IFeatureClassName <BR>Set pFeatClassName = New FeatureClassName <BR><BR>With pFeatClassName <BR>.FeatureType = esriFTSimple <BR>.ShapeFieldName = "Shape" <BR>.ShapeType = pFirstFeatClass.ShapeType <BR>End With <BR><BR>' Set the output location and feature class name <BR>Dim pNewWSName As IWorkspaceName <BR>Set pNewWSName = New WorkspaceName <BR><BR>With pNewWSName <BR>.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1" <BR>.PathName = "C:\temp" <BR>End With <BR><BR>Dim pDatasetName As IDatasetName <BR>Set pDatasetName = pFeatClassName <BR>pDatasetName.Name = "Merge_result" <BR><BR>Set pDatasetName.WorkspaceName = pNewWSName <BR><BR>' Build the input set/array – these are the layers to be merged <BR>Dim inputArray As IArray <BR>Set inputArray = New esriCore.Array ' in ArcGIS 9.0 and newer versions replace with '= New esriSystem.Array' <BR>inputArray.Add pFirstTable <BR>inputArray.Add pSecondTable <BR><BR>' Perform the merge <BR>Dim pBGP As IBasicGeoprocessor <BR>Set pBGP = New BasicGeoprocessor <BR>Dim pOutputFeatClass As IFeatureClass <BR>Set pOutputFeatClass = pBGP.Merge(inputArray, pFirstTable, pFeatClassName) <BR><BR>' Add the output to the map <BR>Dim pOutputFeatLayer As IFeatureLayer <BR>Set pOutputFeatLayer = New FeatureLayer <BR>Set pOutputFeatLayer.FeatureClass = pOutputFeatClass <BR>pOutputFeatLayer.Name = pOutputFeatClass.AliasName <BR>pMxDoc.FocusMap.AddLayer pOutputFeatLayer <BR><BR>End Sub <BR></DIV></TD></TR></TABLE> |
|
|
2楼#
发布于:2006-07-31 11:11
<P>使用IBasicGeoprocessor接口</P>
|
|
|