How to locate line features along routes


This code demonstrates how to create a new line event table by locating line features along routes. That is, you will be performing a 'line on route' overlay. The new event table can be added to ArcMap as a layer using dynamic segmentation.
This sample code is similar to How to transform line events. To transform line events from one route reference to another, you use the same LocateLineFeatures method demonstrated below.

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 LocateLinesAlongRoutes(sAccessWS As String, sRouteFC As String, sLineFC As String, sRouteIDField As String, sOutputEvents As String)
    
    '+++ sAccessWS - access workspace
    '+++ sRouteFC - the route feature class
    '+++ sLineFC - the lines FC to locate
    '+++ sRouteIDField - the route identifier field for the route FC
    '+++ sOutputEvents - the name of the output event table
    
    
    On Error GoTo eh
    
    '+++ Get the line feature class and the route feature class. We'll assume that they come from the
    '+++ same workspace.
    Dim pWS As IWorkspace
    Dim pWSF As IWorkspaceFactory
    Dim pFWS As IFeatureWorkspace
    Dim pRouteFC As IFeatureClass
    Dim pLineFC As IFeatureClass
    Set pWSF = New ShapefileWorkspaceFactory
    Set pWS = pWSF.OpenFromFile(sAccessWS, 0)
    Set pFWS = pWS
    Set pRouteFC = pFWS.OpenFeatureClass(sRouteFC)
    Set pLineFC = pFWS.OpenFeatureClass(sLineFC)
    
    '+++Set up a RouteMeasureLocator object.
    Dim pTempName As IName
    Dim pTempDs As IDataset
    Dim pRMLocName As IRouteLocatorName
    Dim pRtLoc As IRouteLocator
    Set pTempDs = pRouteFC
    Set pTempName = pTempDs.FullName
    Set pRMLocName = New RouteMeasureLocatorName
    With pRMLocName
        Set .RouteFeatureClassName = pTempName
        .RouteIDFieldName = sRouteIDField
        .RouteIDIsUnique = True
    End With
    Set pTempName = pRMLocName
    Set pRtLoc = pTempName.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 pTempDs = pWS
    Set pOutWSN = pTempDs.FullName
    Set pOutDSN = New TableName
    Set pOutDSN.WorkspaceName = pOutWSN
    pOutDSN.Name = sOutputEvents 'this table should not exist already
    
    '+++ Create RouteLocatorOperations object. Note that you can use a selection set of lines. If you want to do this,
    '+++ set the InputFeatureSelection property instead of the InputFeatureClass property.
    Dim pRouteLocOps As IRouteLocatorOperations
    Set pRouteLocOps = New RouteLocatorOperations
    With pRouteLocOps
        Set .RouteLocator = pRtLoc
        Set .InputFeatureClass = pLineFC
    End With
    
    '+++ Set event properties for the output line event table. The field names specified will be written to the
    '+++ output table.
    Dim pEventProps As IRouteEventProperties
    Dim pRMlineProps As IRouteMeasureLineProperties
    Set pEventProps = New RouteMeasureLineProperties
    pEventProps.EventRouteIDFieldName = "RKEY"
    Set pRMlineProps = pEventProps
    pRMlineProps.FromMeasureFieldName = "FROM_M"
    pRMlineProps.ToMeasureFieldName = "TO_M"
    
    '+++ 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.LocateLineFeatures(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