How to concatenate events


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 VBA.
  2. Modify the code to match your data paths, etc.
  3. Run the code.
[VBA]
Public Sub ConcatenateEvents(sAccessWS As String, sEventTable As String, sRouteIDField As String, _
                             sFromMeasureField As String, sToMeasureField As String, sOutEventTable As String, sConField As String)
    
    
    
    '+++ VARIABLES
    '+++ sAccessWS - access workspace
    '+++ sEventTable - event table
    '+++ sRouteIDField - route ID field
    '+++ sFromMeasureField - the from-measure field
    '+++ sToMeasureField - the to-measure field
    '+++ sOutEventTable - the output event table
    '+++ sConField - field to concatenate on
    
    
    
    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(sAccessWS, 0)
    Set pInputTable = pFeatWS.OpenTable(sEventTable)
    
    Dim pInputProp As IRouteEventProperties
    Dim pInputRMProp As IRouteMeasureLineProperties
    Set pInputProp = New RouteMeasureLineProperties
    With pInputProp
        .EventMeasureUnit = esriUnknownUnits
        .EventRouteIDFieldName = sRouteIDField
    End With
    Set pInputRMProp = pInputProp
    With pInputRMProp
        .FromMeasureFieldName = sFromMeasureField
        .ToMeasureFieldName = sToMeasureField
    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 = "esriDataSourcesGDB.SdeWorkspaceFactory.1"
    ElseIf pTempWs.Type = esriLocalDatabaseWorkspace Then
        pOutWSN.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory.1"
    Else
        pOutWSN.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory.1"
    End If
    Set pOutDSN = New TableName
    Set pOutDSN.WorkspaceName = pOutWSN
    pOutDSN.Name = sOutEventTable
    
    
    '+++ 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, sConField, 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