gorik
gorik

Reputation: 13

graph network with Neo4j Spatial based on SHP file

I'm trying to use Neo4j Spatial to do a distance calculation on a network. The goal is to define points within a certain distance but only point that are located on a road.

I loaded a SHP with my road network data using ShapefileImporter in Java. Now I can see a bunch of nodes with geometry property but I don't see any relationships.

How do I add relationships between connecting lines so that I have a real graph?

I had expected the the ShapeFileImporter would have taking start and endpoint for each line as a node and add relationship between both.

BTW, I'm using Neo4j Community 2.1.1 with Spatial 0.13 plugin.

Upvotes: 0

Views: 817

Answers (2)

Craig Taverner
Craig Taverner

Reputation: 769

Each of the example importers provided with Neo4j Spatial makes a decision about how to structure that data in the graph. This decision is made by the choice of GeometryEncoder implementation. The GeometryEncoder decides how to structure the Geometry in the graph. The simplest generic choice for data sources that have all geometries separated, like Shapefile, is to just store each geometry as either WKT or WKB in a single property of a single node.

So, if you want to have geometries separated into graph structure, you would need to write an encoder for that. Or perhaps re-use or modify/extend one that already does that, like the OSMGeometryEncoder.

I think, however, the first question to ask yourself is why you want to see the geometry as a sub-graph? If it is to perform routing, for example, then this is not sufficient, you will also need to connect all the LineString segments together to create a complete network. In this case is it much easier to use an already connected dataset, like OpenStreetMap, which is already loaded into Neo4j as a fully connected graph.

If you specifically need to use Shapefiles, then the process would be:

  • Write a GeometryEncoder that converts LineString to sub-graphs (modelled perhaps on OSMGeometryEncoder)
  • Extend or modify the Shapefile importer to use instead this new geometry encoder during import
  • Write code that finds the possible connections between the LineStrings and joins them (either by merging the common end nodes, or by creating a special relationships between them)
  • Add any extra meta-data you think you need for routing (turn restrictings, etc.)
  • Write your routing algorithm

Upvotes: 1

Dan G
Dan G

Reputation: 1128

I haven't played with it, but it looks like it takes each feature in the shapefile, imports each as a node, and allows spatial (within, overlap, intersect, etc) queries on it's properties via spatial index- not translating a layer of linesegments to nodes and relationships.

If you're going to translate road linesegments -> graph, remember that the roads would become the relationships, and the intersections of the roads would become the nodes.

Upvotes: 0

Related Questions