Concatenate Events

Created:9/11/2000
Description:

Concatenating events combines adjacent records in a linear event table if they are on the same route and have the same value for the concatenate item(s). Concatenating events is useful for breaking up large event tables (many fields) into many smaller tables. Only the event key item, measure items and concatenate item(s) are written to the resulting event table.

Concatenating events produces different results than dissolving events (see Dissolve Events sample). Further, you can only concatenate line event tables.

The following diagram demonstrates the conceptual difference between concatenating and dissolving line events.







The code at the bottom of this sample shows how to concatenate a linear event table. The output table will have only those records that have the same route key and different number of lanes.



An event table called PAV.



The result of concatentating the PAV table using the Lanes as the concatenate field.



How to use:
  1. Paste the code into VB or VBA.
  2. Modify the code to match your data paths, etc.
  3. Run the code.
Public Sub ConcatenateEvents()

  On Error GoTo eh
  
  '+++ The input table and properties

  Dim pFact As IWorkspaceFactory
  Dim pFeatWS As IFeatureWorkspace
  Dim pInputTable As ITable
  Set pFact = New AccessWorkspaceFactory
  Set pFeatWS = pFact.OpenFromFile("\\rockytop\data\dyndata\oe.mdb", 0)
  Set pInputTable = pFeatWS.OpenTable("pav")
  
  Dim pInputProp As IRouteEventProperties
  Dim pInputRMProp As IRouteMeasureLineProperties
  Set pInputProp = New RouteMeasureLineProperties
  With pInputProp
    .EventMeasureUnit = esriUnknownUnits
    .EventRouteIDFieldName = "rkey"
  End With
  Set pInputRMProp = pInputProp
  With pInputRMProp
    .FromMeasureFieldName = "fmp"
    .ToMeasureFieldName = "tmp"
  End With
      
  '+++ Create a new table name for the output. We'll write the results out to the
  '+++ same workspace as the input event table
  
  Dim pTempDS As IDataset
  Dim pTempWs As IWorkspace
  Dim pOutDSN As IDatasetName
  Dim pOutWSN As IWorkspaceName
        
  Set pTempDS = pInputTable
  Set pTempWs = pTempDS.Workspace
  Set pOutWSN = New WorkspaceName
  pOutWSN.ConnectionProperties = pTempWs.ConnectionProperties
  If pTempWs.Type = esriRemoteDatabaseWorkspace Then
    pOutWSN.WorkspaceFactoryProgID = "esriCore.SdeWorkspaceFactory.1"
  ElseIf pTempWs.Type = esriLocalDatabaseWorkspace Then
    pOutWSN.WorkspaceFactoryProgID = "esriCore.AccessWorkspaceFactory.1"
  Else
    pOutWSN.WorkspaceFactoryProgID = "esriCore.ShapefileWorkspaceFactory.1"
  End If
  Set pOutDSN = New TableName
  Set pOutDSN.WorkspaceName = pOutWSN
  pOutDSN.Name = "Lanes_Concatenate"
   

  '+++ Create some output event properties.

  Dim pOutputProp As IRouteEventProperties2
  Dim pOutputRMProp As IRouteMeasureLineProperties
  Set pOutputProp = New RouteMeasureLineProperties
  With pOutputProp
    .EventMeasureUnit = esriUnknownUnits
    .EventRouteIDFieldName = "RouteID"
  End With
  Set pOutputRMProp = pOutputProp
  With pOutputRMProp
    .FromMeasureFieldName = "FromMeasure"
    .ToMeasureFieldName = "ToMeasure"
  End With


  '+++ Set up a RouteMeasureEventGeoprocessor
  
  Dim pRMEvtProc As IRouteMeasureEventGeoprocessor2
  Set pRMEvtProc = New RouteMeasureGeoprocessor
  With pRMEvtProc
    Set .InputEventProperties = pInputRMProp
    Set .InputTable = pInputTable
  End With
  
  '+++ Perform the concatenate on one field
  
  Dim pOutTable As ITable
  Set pOutTable = pRMEvtProc.Concatenate2(pOutputRMProp, "lanes", pOutDSN, Nothing, "")
  
  '+++ It is possible to concatenate on multiple fields
  'Dim sFlds(1) As String
  'sFlds(0) = "lanes"
  'sFlds(1) = "cracks"
  'Set pOutTable = pRMEvtProc.Concatenate2(pOutputRMProp, sFlds, pOutDSN, Nothing, "")
  
  GoTo endproc
eh:
  Dim lNum As Long, sSrc As String, sDesc As String
  lNum = Err.Number
  sSrc = Err.source
  sDesc = Err.Description
  Err.Raise lNum, sSrc, sDesc
  
endproc:

End Sub