How to locate point features along routes


This code demonstrates how to create a new point event table by locating point features along routes. The new event table can be added to ArcMap as a layer using dynamic segmentation.

How to use

  1. Paste the code into your project.
  2. Change the code to point to your data
  3. Run the code.
[VBA]
Public Sub LocatePointsAlongRoutes(sAccessWS As String, sRouteFC As String, sPointFC As String, sRouteIDField As String, sOutEvents As String)
    
    '+++ sAccessWS - access workspace
    '+++ sRouteFC - the route feature class
    '+++ sPointFC - the point feature class
    '+++ sRouteIDField - the route identifier field for sRouteFC
    '+++ sOutEvents - the output event table
    
    On Error GoTo eh
    
    '+++ Get the point 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 pPointFC As IFeatureClass
    Set pWSF = New ShapefileWorkspaceFactory
    Set pWS = pWSF.OpenFromFile(sAccessWS, 0)
    Set pFWS = pWS
    Set pRouteFC = pFWS.OpenFeatureClass(sRouteFC)
    Set pPointFC = pFWS.OpenFeatureClass(sPointFC)
    
    '+++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 points
    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 = sOutEvents 'this table should not exist already
    
    '+++ Create RouteLocatorOperations object. Note that you can use a selection set of points. 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 = pPointFC
    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 IRouteEventProperties
    Dim pRMPointProps As IRouteMeasurePointProperties
    Set pEventProps = New RouteMeasurePointProperties
    pEventProps.EventRouteIDFieldName = "RKEY"
    pEventProps.LateralOffsetFieldName = "DIST" 'optional
    Set pRMPointProps = pEventProps
    pRMPointProps.MeasureFieldName = "MEASURE"
    
    '+++ Locate the points along the routes
    Dim pOutTable As ITable
    Dim dSearchRadius As Double
    Dim bSearchMultiple As Boolean
    Dim bKeepAllFields As Boolean
    dSearchRadius = 1 'specified in the units of the route feature class's coordinate system
    bSearchMultiple = False 'find only the closest route location
    bKeepAllFields = True 'keep all of the input point feature class's attributes
    Set pOutTable = pRouteLocOps.LocatePointFeatures(dSearchRadius, bSearchMultiple, 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