I'm working on a Grails app over Neo4J which I'd like to also export as a GIS database.
Looking at the examples for how to use neo4j in GeoServer/uDig it appears that the Spatial integration is only via embedded neo4j databases.
Does anyone know whether it's possible to set things up so that my Neo4J is available over REST, so that I can interface to it from a variety of places?
At first sight it appears that it ought to be possible:
// Works with this embedded database
//def graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("/tmp/foo.db");
// Doesn't work with this REST database
graphDb = new RestGraphDatabase("http://localhost:7474/db/data");
Transaction tx = graphDb.beginTx()
SpatialDatabaseService spatialService = new SpatialDatabaseService(graphDb)
SimplePointLayer layer = spatialService.createSimplePointLayer("points")
With an embedded database, the spatial index gets created just fine. However, with the REST database, I just get a null pointer:
Caused by NullPointerException: null
->> 149 | createCompiler in org.neo4j.cypher.ExecutionEngine
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| 48 | <init> in ''
| 59 | createInnerEngine in org.neo4j.cypher.javacompat.ExecutionEngine
| 43 | <init> in ''
| 41 | getReferenceNode in org.neo4j.gis.spatial.utilities.ReferenceNodes
| 78 | getSpatialRoot in org.neo4j.gis.spatial.SpatialDatabaseService
| 114 | getLayer in ''
| 259 | containsLayer in ''
| 303 | createLayer in ''
| 287 | createSimplePointLayer in ''
| 267 | createSimplePointLayer in ''
| 37 | <init> in net.foo.db.neo4j.Neo4JService
The SpatialDatabaseService takes a GraphDatabaseService, so I'm confused as to why it doesn't work with a REST one.
Is this a bug or a feature (or a misunderstanding on my part?)
I can, of course, use the create index
API to create a spatial index:
graphDb.index().forNodes( "points", ["provider": "spatial", "geometry_type": "point", "lat": "lat", "lon":"lon"])
so that works, but I can't create new layer that way.
Though I don't really understand what you are doing with this Grail App and stuff, from the look of your exceptions, it looks like you are trying to do something like this:
ExecutionEngine builds upon our internal Kernel API, which it can only get from an embedded kind of database.
To run Cypher queries on a RestGraphDatabase, you need grab its RestAPI from getRestAPI, and use the query method on that.
A post on this google groups explains this: https://groups.google.com/forum/#!topic/neo4j/Q6lsOakSgyA
Below is a sample program that I made which uses the RestGraphDatabase to create and execute queries. Hope this helps.
The RestGraphDatabase is a fake database which doesn't offer all capabilities. It could be made work in theory but would be very wasteful as each presumably embedded operation would go over the wire as http requests.
Install Spatial as Plugin to your server and then access it via the plugin REST methods.
See: http://neo4j-contrib.github.io/spatial/#spatial-server-plugin