Calculate distance between points along a route

08-17-2021 09:59 AM
Labels (2)
New Contributor

Hi everyone,

I have a network of bus routes and bus stops generated from GTFS data and I need to calculate the distance between each stop along the routes. After much Googling, I have not found a straightforward way to accomplish this task with a Basic License. I have tried the "Locate Features Along Routes" tool from the Linear Referencing Dataset, but I am not achieving usable results. Network Analyst isn't helpful because I am unable to create my own Network Dataset from the routes shape (again, Basic License).

For context, I ensured that each of my stops (points) intersects with the route (polyline) using the "Near" tool and then displaying the newly calculated coordinates.

Does anyone have any suggestions? I feel as if this might be a relatively simple task that is sitting in my blind spot. 

0 Kudos
4 Replies
Regular Contributor

You can perhaps try creating multiple lines and editing each line between stops. That should give you the lengths that you need to determine the distances. The basic license is extremely limiting but this may help with what you are trying to accomplish.

0 Kudos
MVP Esteemed Contributor

Field calculator

Python expression


Code block

# Enter below into the Code block
x0 = 0.0
y0 = 0.0
import math
def dist_between(shape):
    """Useage ... dist_between(!Shape!)"""
    global x0
    global y0
    x = shape.firstpoint.X
    y = shape.firstpoint.Y
    if x0 == 0.0 and y0 == 0.0:
        x0 = x
        y0 = y
    distance = math.sqrt((x - x0)**2 + (y - y0)**2)
    x0 = x
    y0 = y
    return distance



... sort of retired...
Tags (1)
0 Kudos
New Contributor II

Hi Dan, 

By any chance is there any similar code block that takes into consideration also a polyline layer that represents the road?



0 Kudos
Regular Contributor

From what is sounds like, are you trying to get routing information to and from the stops without using the network analyst extension because you only have a basic license? If that is the case, then you would need to use a python script to read the geometries, loop through each road intersection to find the next closest road intersection to the next stop(s), and append to either feature class or table for all of the roads closest to the stop(s). It is possible, but it does require some strong knowledge and understanding of python. 

0 Kudos