Mapping relationships between Neo4j spatial nodes with GeoPandas

By neub9
1 Min Read


Building upon our previous work on mapping neo4j spatial nodes, we are now moving forward to map the relationships between these nodes.

An excellent example of this approach is analyzing the relationships between GTFS StopTime and Trip nodes. For instance, here is the Cypher query to retrieve all StopTime nodes of Trip 17:

            (t:Trip {id: "17"})
        RETURN st

Furthermore, in order to obtain the stop locations, we also need to retrieve the stop nodes:

            (t:Trip {id: "17"})
        RETURN st ,s

Adapting the code from the previous post, we can plot the stops:


Ordering by stop sequence is optional, but for a different approach, we can use the NEXT_STOP relationships to generate a DataFrame of the start and end stops for each segment:


Finally, we can use Cypher to calculate the travel time between two stops:

        MATCH (t:Trip {id: "17"})
        MATCH (st1)-[:STOPS_AT]->(s1:Stop)
        MATCH (st2)-[:STOPS_AT]->(s2:Stop)
        RETURN st1.departureTime AS time1, 
           st2.arrivalTime AS time2, 
           s1.location AS geom1, 
           s2.location AS geom2, 
           ).seconds AS traveltime

Find the complete notebook here.


Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *