Question

What is the cause and how to fix this exception:

org.neo4j.graphdb.NotFoundException: More than one relationship[RTREE_CHILD, INCOMING] found for NodeImpl#105
at org.neo4j.kernel.impl.core.NodeImpl.getSingleRelationship(NodeImpl.java:344)
at org.neo4j.kernel.impl.core.NodeProxy.getSingleRelationship(NodeProxy.java:191)
at org.neo4j.collections.rtree.RTreeIndex.getIndexNodeParent(RTreeIndex.java:768)
at org.neo4j.collections.rtree.RTreeIndex.adjustPathBoundingBox(RTreeIndex.java:672)
at org.neo4j.collections.rtree.RTreeIndex.add(RTreeIndex.java:90)
at org.neo4j.gis.spatial.EditableLayerImpl.add(EditableLayerImpl.java:44)
at org.neo4j.gis.spatial.ShapefileImporter.importFile(ShapefileImporter.java:209)
at org.neo4j.gis.spatial.ShapefileImporter.importFile(ShapefileImporter.java:122)

I am using 2.0.0 and spatial jars coming from compiled github project.

The exception is thrown when I try to import Shapefile (this is code in unmanaged extension):

GraphDatabaseService spatialDb = new GraphDatabaseFactory().newEmbeddedDatabase("/home/db/data/spatial.db");
    Transaction tx = spatialDb.beginTx();
    try {
        ShapefileImporter importer = new ShapefileImporter(spatialDb, new NullListener());
        importer.importFile("/home/bla/realshp/users_location.shp", "users_location");
        tx.success();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        tx.close();
        return Response.status(200).entity("Done. ").build();
    }

The shape file is generated from CSV file with ogr2ogr - it seems legit and is read without exceptions. In the original file there was around 30000 points defined as follows (ogr2ogr will pull longitude and latitude):

id,longitude,latitude,gender,updated
3,-122.1171925,37.4343361,1,2013-11-20 05:03:22
304,-122.0919000,37.3094000,1,2013-11-03 00:42:01
311,-122.0919000,37.3094000,1,2013-11-03 00:42:01

How to get around it? I need to load milions of points to the db. Side question: now I create new graph-spatial datastore - is it correct? Maybe I should load it to existing graph db?

UPDATE:

I tried to input coordinates "manually" using methods from TestSimplePointLayer. I got the same exception around 450th coordinate. Bunch of them are the same as you can see in the sample, but they are valid points. How to get around it?

Was it helpful?

Solution

You are skipping a step here. You create a spatial index and then you add the users to the index.

So for example if you had a shape file of all the states or counties or zip codes in the US, you can create a spatial layer with those shapes and add the users to them.

You can use a simple point layer as well if you want, but they have to be unique, but the user nodes that reside in those locations don't have to be. See http://java.dzone.com/articles/running-along-graph-using-0 and http://www.markhneedham.com/blog/2013/03/10/neo4jcypher-finding-football-stadiums-near-a-city-using-spatial/ for a better idea.

OTHER TIPS

I meet the same error when I try to add node with same lon/lat (0,0) to the layer. When more than 100 RTREE_CHILD ref node inserted, this exception appears. It's a bug of the source code.

src/main/java/org/neo4j/gis/spatial/rtree/RTreeIndex.java

try this forked plugin:

https://github.com/linkedin-inc/spatial
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top