Locate line features along routes

Created:9/6/2002
Description:

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.

Note: This sample code is similar to the 'Transform line events' sample. 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 VB/VBA.
  2. Change the code to point to your data
  3. Run the code.
Public Sub LocateLinesAlongRoutes()
  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("\\burt\data\dyndata", 0)
  Set pFWS = pWS
  Set pRouteFC = pFWS.OpenFeatureClass("roads_hwy")
  Set pLineFC = pFWS.OpenFeatureClass("path1")
  
  '+++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 = "RKEY"
    .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 = "Line_Output"    '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