In this lesson, you will learn how to integrate spatial coordinates into your graph model to calculate physical proximity alongside logical connections.
Beyond Logical Relationships
In a standard property graph, nodes represent entities (like Warehouse or Store) and edges represent logical connections (like SUPPLIES). However, these graphs often ignore the physical distance between nodes. A geospatial graph model enriches your nodes with spatial attributes (longitude/latitude) so you can query for "the nearest supplier" while simultaneously traversing the supply chain graph.
Calculating Spatial Relationships
To implement this, you must treat the spatial coordinate as a node property. When performing a graph traversal, you can compute the geographic distance—typically using the Haversine formula—to filter or rank your path results.
Consider a scenario where you have a RetailStore and several Warehouse nodes. You don't just want to know if a store is connected to a warehouse; you want to know the "best" warehouse based on proximity.
-- Conceptual query: Finding reachable warehouses sorted by spatial distance
MATCH (s:Store {id: 'NYC_01'})-[:CAN_BE_SUPPLIED_BY]->(w:Warehouse)
WITH w,
point.distance(s.location, w.location) AS distance
WHERE distance < 50000 -- Filter for warehouses within 50km
ORDER BY distance ASC
RETURN w.name, distance
Why Combine Them?
By storing spatial data directly within the nodes, you reduce the need for complex joins between a graph database and a separate RDBMS spatial extension. This allows you to perform "Spatial-Graph Hybrid" queries. For example, you can identify a community of interconnected nodes (via graph clustering) and then determine the geometric center (centroid) of that community to optimize logistics or service area planning.
Integrating these two models allows you to answer questions that neither system could solve alone: "Which warehouses are part of my primary supply chain and are within 100 miles of my distribution center?" This synthesis creates a powerful tool for logistics, retail expansion, and infrastructure planning.
Key Takeaway: Geospatial graph models treat latitude and longitude as node properties, allowing you to use geometric constraints to filter or rank the traversal of logical graph relationships.