alearner
路人甲
路人甲
  • 注册日期2006-09-11
  • 发帖数74
  • QQ
  • 铜币433枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1237回复:0

基于IBasicGeoprocessor的Dissolve方法的使用(源代码)

楼主#
更多 发布于:2007-05-17 15:29
基于IBasicGeoprocessor的Dissolve方法的使用(源代码)<BR><BR>
<DIV >Option Explicit<BR>Sub CreateSummaryTableFromLayer()<BR>' Creates a summary table from STATES layer using Dissolve and adds it as a standalone table.<BR>  Dim pDoc As IMxDocument<BR>  Set pDoc = ThisDocument<BR>  Dim pMap As IMap<BR>  Set pMap = pDoc.FocusMap<BR>  <BR>  ' Find the layer named STATES<BR>  Dim pLayer As ILayer<BR>  Dim pInputFeatLayer As IFeatureLayer<BR>  Dim intCount As Integer<BR>  For intCount = 0 To pMap.LayerCount - 1<BR>    Set pLayer = pMap.Layer(intCount)<BR>    If TypeOf pLayer Is IFeatureLayer Then<BR>      If pLayer.Name = "STATES" Then<BR>        Set pInputFeatLayer = pLayer<BR>        Exit For<BR>      End If<BR>    End If<BR>  Next<BR>  If pInputFeatLayer Is Nothing Then<BR>    MsgBox "The STATES layer was not found"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Get input table<BR>  ' Use the Itable interface from the Layer (not from the FeatureClass)<BR>  Dim pInputTable As ITable<BR>  Set pInputTable = pInputFeatLayer<BR>  <BR>  ' Error checking<BR>  If pInputTable Is Nothing Then<BR>    MsgBox "Table QI failed"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Make sure there is a field call SUB_REGION in the input layer<BR>  If pInputTable.FindField("SUB_REGION") = -1 Then<BR>    MsgBox "There must be a field named SUB_REGION in STATES"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Set up the output location<BR>  Dim pNewWSName As IWorkspaceName<BR>  Set pNewWSName = New WorkspaceName<BR>  ' shapefile flavor will work just fine<BR>  pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"<BR>  pNewWSName.PathName = "c:\temp"<BR>  <BR>  ' Set up the output table<BR>  Dim pOutTabName As ITableName<BR>  Set pOutTabName = New TableName<BR>  Dim pDatasetName As IDatasetName<BR>  Set pDatasetName = pOutTabName<BR>  pDatasetName.Name = "dissolve_sumfromlayer_tab"<BR>  Set pDatasetName.WorkspaceName = pNewWSName<BR>  <BR>  ' Perform the dissolve.<BR>  ' We are using the output table to build a standalone table, so we<BR>  ' can omit Shape.Dissolve from the beginning of the string<BR>  Dim iBGP As IBasicGeoprocessor<BR>  Set iBGP = New BasicGeoprocessor<BR>  Dim pOutputTable As ITable<BR>  Set pOutputTable = iBGP.Dissolve(pInputTable, True, "SUB_REGION", "Minimum.SUB_REGION, Average.AREA", pDatasetName)<BR>  <BR>  ' add the table to map<BR>  Dim pStTab As IStandaloneTable<BR>  Set pStTab = New StandaloneTable<BR>  Set pStTab.Table = pOutputTable<BR>  Dim pStTabColl As IStandaloneTableCollection<BR>  Set pStTabColl = pMap<BR>  pStTabColl.AddStandaloneTable pStTab<BR>  <BR>  ' Refresh the TOC<BR>  pDoc.UpdateContents<BR>  <BR>End Sub<BR>Sub CreateSummaryTableFromTable()<BR>' Creates a summary table from STATESDBF table using Dissolve and adds it as a standalone table.<BR>  Dim pDoc As IMxDocument<BR>  Set pDoc = ThisDocument<BR>  Dim pMap As IMap<BR>  Set pMap = pDoc.FocusMap<BR>' Find the table named STATESDBF<BR>  Dim i As Integer<BR>  Dim pStTab As IStandaloneTable, pStTabOut As IStandaloneTable<BR>  Dim pStTabColl As IStandaloneTableCollection<BR>  Set pStTabColl = pMap<BR>  <BR>  Set pStTabOut = Nothing<BR>  For i = 0 To pStTabColl.StandaloneTableCount - 1<BR>    Set pStTab = pStTabColl.StandaloneTable(i)<BR>    If pStTab.Name = "STATESDBF" Then<BR>      Set pStTabOut = pStTab<BR>      Exit For<BR>    End If<BR>  Next i<BR>  If pStTabOut Is Nothing Then<BR>    MsgBox "The STATESDBF table was not found"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Get input table<BR>  Dim pInputTable As ITable<BR>  Set pInputTable = pStTabOut.Table<BR>  <BR>  ' Error checking<BR>  If pInputTable Is Nothing Then<BR>    MsgBox "Table not found"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Make sure there is a field call SUB_REGION in the input layer<BR>  If pInputTable.FindField("SUB_REGION") = -1 Then<BR>    MsgBox "There must be a field named SUB_REGION in STATES"<BR>    Exit Sub<BR>  End If<BR>  <BR>  ' Set up the output location<BR>  Dim pNewWSName As IWorkspaceName<BR>  Set pNewWSName = New WorkspaceName<BR>  ' shapefile flavor will work just fine<BR>  pNewWSName.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"<BR>  pNewWSName.PathName = "c:\temp"<BR>  <BR>  ' Set up the output table<BR>  Dim pOutTabName As ITableName<BR>  Set pOutTabName = New TableName<BR>  Dim pDatasetName As IDatasetName<BR>  Set pDatasetName = pOutTabName<BR>  pDatasetName.Name = "dissolve_sumfromtable_tab"<BR>  Set pDatasetName.WorkspaceName = pNewWSName<BR>  <BR>  ' Perform the dissolve.<BR>  ' We are using the output table to build a standalone table, so we<BR>  ' can omit Shape.Dissolve from the beginning of the string<BR>  Dim iBGP As IBasicGeoprocessor<BR>  Set iBGP = New BasicGeoprocessor<BR>  Dim pOutputTable As ITable<BR>  Set pOutputTable = iBGP.Dissolve(pInputTable, False, "SUB_REGION", "Minimum.SUB_REGION, Average.AREA", pDatasetName)<BR>  <BR>  ' add the table to map<BR>'  Dim pStTab As IStandaloneTable<BR>  Set pStTab = New StandaloneTable<BR>  Set pStTab.Table = pOutputTable<BR>'  Dim pStTabColl As IStandaloneTableCollection<BR>  Set pStTabColl = pMap<BR>  pStTabColl.AddStandaloneTable pStTab<BR>  <BR>  ' Refresh the TOC<BR>  pDoc.UpdateContents<BR>End Sub</DIV>
喜欢0 评分0
游客

返回顶部