Graph Databases II: Routing Planning

0
124


I wrote a previous post on graph databases that did little
more than add some nodes and a relationship. The post required
me to install neo4j and python py2neo. It was simple, but it
was a start. I have moved on to other things since then, most
notably Go. But I have found myself coming back in a round
about way. I recently wrote a plugin for Open Trail Data in Leaflet. Trails are a
network but the data is really just lines. I thought if we add
nodes at the starting points, intersections and eds of the
trails, we could use them for routing. I set off to work.

The Data

The first step was grabbing a simple network. I used the
Open Trail Data dummy data. I was going to
draw nodes then import them in to a graph database, but I
decided to shelve that for later – when I know I can route. The
data is drawn in the image below.


Open Trail Data

Open Trail Data

The Graph

Next, I needed to create the graph database. I started with all
the endpoints of the lines and then added nodes to the
intersections. The code below shows how I created two nodes and
a path between them.

one = Node(“trail”,id=”1″,junction=”1″)
oneint = Node(“trail”,id=”1″,junction=”1,2,3,4″)
p=Path(one, Rel(“connects”),oneint)

The end result was a graph database as seen in the image below.


Finished Graph Database

Finished Graph Database



Read More

LEAVE A REPLY