How to transform point events


This code demonstrates how to transform point events from one route reference to another. The new event table can be added to ArcMap as a layer using dynamic segmentation.
This code sample uses the LocatePointEvents method. This method uses a more complicated alogrithm than the LocatePointFeatures method. The LocatePointFeatures method is demonstrated in How to locate point features along routes.

How to use

  1. Paste the code into VBA.
  2. Change the code to point to your data
  3. Run the code.
[VBA]
Public Sub TransformPointEvents(sAccessWS As String, sSourceRouteFC As String, sRouteIDField As String, _
                                sEventTable As String, sEventRIDField As String, sMeasureField As String, sTargetRouteFC As String, _
                                sTargetRIDField As String, sOutEventTable As String)
    
    
    '+++ VARIABLES
    '+++ sAccessWS - access workspace
    '+++ sSourceRouteFC - the source route feature class
    '+++ sRouteIDField - route ID field of sSourceRouteFC
    '+++ sEventTable - event table to transform
    '+++ sMeasureField - the measure field of the sEventTable
    '+++ sTargetRouteFC - the target route feature class
    '+++ sTargetRIDField - route ID field of the target route FC
    '+++ sOutEventTable - the output event table (result of the transform)
    
    On Error GoTo eh
    
    '+++ Get the input point event table and route feature class.
    Dim pWS As IWorkspace
    Dim pWSF As IWorkspaceFactory
    Dim pFWS As IFeatureWorkspace
    Dim pInRouteFC As IFeatureClass
    Dim pEventTable As ITable
    
    Set pWSF = New AccessWorkspaceFactory
    Set pWS = pWSF.OpenFromFile(sAccessWS, 0)
    Set pFWS = pWS
    Set pInRouteFC = pFWS.OpenFeatureClass(sSourceRouteFC)
    Set pEventTable = pFWS.OpenTable(sEventTable)
    
    '+++ Create a RouteEventSource object for the point events. A RouteEventSource is a
    '+++ 'dynamic' feature class and can be used anywhere a regular feature class can be used.
    Dim pName As IName
    Dim pDS As IDataset
    Dim pRMLName As IRouteLocatorName
    
    Set pDS = pInRouteFC
    Set pName = pDS.FullName
    Set pRMLName = New RouteMeasureLocatorName
    With pRMLName
        Set .RouteFeatureClassName = pName
        .RouteIDFieldName = sRouteIDField
    End With
    
    Dim pRtProp As IRouteEventProperties2
    Dim pRMPtProp As IRouteMeasurePointProperties2
    Dim pRESN As IRouteEventSourceName
    Dim pRES As IRouteEventSource
    
    Set pRtProp = New RouteMeasurePointProperties
    pRtProp.EventRouteIDFieldName = sEventRIDField
    Set pRMPtProp = pRtProp
    pRMPtProp.MeasureFieldName = sMeasureField
    
    Set pDS = pEventTable
    Set pName = pDS.FullName
    Set pRESN = New RouteEventSourceName
    With pRESN
        Set .EventTableName = pName
        Set .EventProperties = pRMPtProp
        Set .RouteLocatorName = pRMLName
    End With
    Set pName = pRESN
    Set pRES = pName.Open
    
    '+++ Get the target route feature class. This is the feature class we will be
    '+++ transforming the events to. We'll assume this feature class is in the same workspace
    '+++ as the rest of out inputs.
    Dim pTargetRouteFC As IFeatureClass
    Set pTargetRouteFC = pFWS.OpenFeatureClass(sTargetRouteFC)
    
    '+++ Create a route locator for the target route feature class
    Dim pTargetRtLocName As IRouteLocatorName
    Dim pTargetRtLoc As IRouteLocator
    Set pDS = pTargetRouteFC
    Set pName = pDS.FullName
    Set pTargetRtLocName = New RouteMeasureLocatorName
    With pTargetRtLocName
        Set .RouteFeatureClassName = pName
        .RouteIDFieldName = sTargetRIDField
    End With
    Set pName = pTargetRtLocName
    Set pTargetRtLoc = pName.Open
    
    '+++ Create an output table name object. We'll write to the same workspace as the
    '+++ input routes and lines
    Dim pOutDSN As IDatasetName
    Dim pOutWSN As IWorkspaceName
    Set pDS = pWS
    Set pOutWSN = pDS.FullName
    Set pOutDSN = New TableName
    Set pOutDSN.WorkspaceName = pOutWSN
    pOutDSN.Name = sOutEventTable 'this table should not exist already
    '+++ Create a RouteLocatorOperations object.
    Dim pRouteLocOps As IRouteLocatorOperations
    Set pRouteLocOps = New RouteLocatorOperations
    With pRouteLocOps
        Set .RouteLocator = pTargetRtLoc
        Set .InputFeatureClass = pRES
    End With
    
    '+++ Set event properties for the output point event table. The field names specified will be written to the
    '+++ output table.
    Dim pEventProps As IRouteEventProperties2
    Dim pRMPointProps As IRouteMeasurePointProperties2
    Set pEventProps = New RouteMeasurePointProperties
    pEventProps.EventRouteIDFieldName = sTargetRIDField
    Set pRMPointProps = pEventProps
    pRMPointProps.MeasureFieldName = sMeasureField
    
    '+++ Locate the lines along the routes
    Dim pOutTable As ITable
    Dim dClusterTol As Double
    Dim bKeepAllFields As Boolean
    dClusterTol = 0.01 'specified in the units of the route feature class's coordinate system
    bKeepAllFields = True 'keep all of the input line feature class's attributes
    Set pOutTable = pRouteLocOps.LocatePointEvents(dClusterTol, pEventProps, bKeepAllFields, pOutDSN, "", Nothing)
    
    Exit Sub
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
End Sub






Additional Requirements
  • ArcEditor at 9.0; ArcView at 9.1 forward