Skip to content

spatial components on top of the Neo4j graph database

Notifications You must be signed in to change notification settings

dwins/neo4j-spatial

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Neo4j Spatial

This is a first prototype of a library to store spatial data in the Neo4j open source graph database. You can import geometries from a shapefile and perform spatial searches.

The most common 2D geometries are supported:

  • (multi) point
  • (multi) linestring
  • (multi) polygon

Spatial queries implemented:

  • Contain
  • Cover
  • Covered By
  • Cross
  • Disjoint
  • Intersect
  • Intersect Window
  • Overlap
  • Touch
  • Within
  • Within Distance

Building

You need a Java 6 environment, Neo4J, JTS and GeoTools:

  • jta-1.1.jar
  • neo4j-kernel-1.0.jar
  • neo4j-commons-1.0.jar
  • jts-1.10.jar
  • geoapi-2.3-M1.jar
  • gt-api-2.6.3.jar
  • gt-shapefile-2.6.3.jar
  • gt-main-2.6.3.jar
  • gt-metadata-2.6.3.jar
  • gt-data-2.6.3.jar

Importing a shapefile

Spatial data is divided in Layers and indexed by a RTree.

GraphDatabaseService database = new EmbeddedGraphDatabase(storeDir);
try {
	ShapefileImporter importer = new ShapefileImporter(database);
    importer.importShapefile("roads.shp", "layer_roads");
} finally {
	database.shutdown();
}

Executing a spatial query

GraphDatabaseService database = new EmbeddedGraphDatabase(storeDir);
try {
	Transaction tx = database.beginTx();
    try {
    	SpatialDatabaseService spatialService = new SpatialDatabaseService(database);
        Layer layer = spatialService.getLayer("layer_roads");
        SpatialIndexReader spatialIndex = layer.getIndex();
        	
        Search searchQuery = new SearchIntersectWindow(new Envelope(xmin, xmax, ymin, ymax));
        spatialIndex.executeSearch(searchQuery);
	    List<SpatialDatabaseRecord> results = searchQuery.getResults();
	       	
		tx.success();
	} finally {
    	tx.finish();
    }	        	        	
} finally {
	database.shutdown();
}

About

spatial components on top of the Neo4j graph database

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Java 97.4%
  • Ruby 1.8%
  • Python 0.8%