Introduction
Neo4j Spatial is a library of utilities for Neo4j that facilitate the enabling of spatial operations on data. In particular, you can add spatial indexes to already located data, and perform spatial operations on the data like searching for data within specified regions or within a specified distance of a point of interest. In addition, classes are provided to expose the data to GeoTools and thereby to GeoTools-enabled applications like GeoServer and uDig.
The key features include:
-
Utilities for importing from ESRI Shapefile as well as Open Street Map files
-
Support for all the common geometry types: Point, LineString, Polygon, etc.
-
An RTree index for fast searches on geometries
-
Support for topology operations during the search (contains, within, intersects, covers, disjoint, etc.)
-
The possibility to enable spatial operations on any graph of data, regardless of the way the spatial data is stored, as long as an adapter is provided to map from the graph to the geometries.
-
Ability to split a single layer or dataset into multiple sub-layers or views with pre-configured filters
Get Started
The easiest way to get started with neo4j-spatial is to grab the server-plugin-*.jar
from the latest release, copy it to your $NEO4J_HOME/plugins
and restart your Neo4j server.
From there you can use all the spatial-procedures in your Cypher queries to add Nodes to the spatial index and perform a number of spatial point, distance and intersection queries.
CALL spatial.addPointLayer('geom');
CALL spatial.layers();
CREATE (n:Node {latitude:60.1,longitude:15.2})
WITH n
CALL spatial.addNode('geom',n) YIELD node
RETURN node;
CALL spatial.bbox('geom',{lon:15.0,lat:60.0}, {lon:15.3, lat:61.0});
A good example blog post for how to use them with one of the neo4j drivers, is Spatial Procedures in Legis Graph by William Lyon (Part 1).
Max de Marzi explains the spatial-server-plugin in his two-part blog post around restaurant recommendations.
A general introduction to Neo4j Spatial and a simple example on how to use the Spatial Java APIs can be found in this blog post by Craig Taverner.