Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-08-2022 02:20 PM
I'm currently exploring Spatial support for Neo4j. Until now I've been using PostGIS for storing and querying Openstreetmap Data, but I want to use Neo4j for this approach. When using Neo4j I first discovered the very old neo4j-spatial-plugin. Using this plugin I was able to import first .osm-Files using the commandline, but only for Neo4j 4.1.6. Later I saw the Neo4j/osm github and used this Importer for a second Database, again only with the commandline. Both plugins where only compatible for Neo4j 4.1.6 or older Versions, which didn't satisfy me.
Next I discovered a third plugin Neo4j/spatial, which seems to provide an Importer with support for newer Versions and even had spatial functions included. But this plugin seems to be different than the other two. Since I use Neo4j as a Server and not as an embedded system, I couldnt figure out if it is possible to use this plugin. The other two plugins provided functions with the Commandline to import OSM Files. (procedures where very slow in importing so I had so cancel it)
So my question is, which of these programs should I use when using neo4j as a server? And apart from procedures, are these plugins usable with the Neo4j server? Using them in a Java Application would be cool.
LG Gregor.
04-10-2022 09:31 AM
Please create spatial indexing at appropriate Nodes so that the timings can be improved.
Many thanks
Mr Sameer Sudhir G
04-10-2022 01:38 PM
Thanks for the Response. I thought the Spatial-Index is created during the Import with the Neo4j-OSM-Plugin
04-10-2022 01:35 PM
First plugin: Neo4j Spatial
Second Plugin: Neo4j OSM
The first plugin has an OSMImporter with Support for newer Neo4j versions, but as far as I know only for Neo4j Embedded (?).
OSMImporter importer = new OSMImporter("sweden");
Map<String, String> config = new HashMap<String, String>();
config.put("neostore.nodestore.db.mapped_memory", "90M" );
config.put("dump_configuration", "true");
config.put("use_memory_mapped_buffers", "true");
BatchInserter batchInserter = BatchInserters.inserter(new File(dir), config);
importer.importFile(batchInserter, "sweden.osm", false);
batchInserter.shutdown();
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(dir);
importer.reIndex(db, 10000);
db.shutdown();
The second Plugin has an OSMImporter for Neo4j-4.1.6 and supports Neo4j-Embedded and Neo4j-Server via commandline.
java -Xms1280m -Xmx1280m \
-cp "target/osm-0.2.3-neo4j-4.1.6.jar:target/dependency/*" org.neo4j.gis.osm.OSMImportTool \
--skip-duplicate-nodes --delete --into target/neo4j --database map2 samples/map2.osm.bz2
So is there a way to Import OSM-Files into an Neo4j Server (not embedded) newer than Version 4.1.6 ?
04-11-2022 02:07 AM
After a some tests and research this is what I came up with:
Neo4j-OSM is a Importer and Model for OSM Data optimised for routing. There is no spatial index included, the spatial index of Neo4j for Points can be used. Here an offline Importer, via commandline, enables fast Imports for Neo4j-Server (See Java command above).
Neo4j-Spatial is an Importer an Model with an RTREE Spatial Index, like Postgis. Spatial functions like Within, Intersect or Contains can be executed. The Modell is a different one to Neo4j-OSM and not suitable for routing. For importing there are two ways:
OSMImporter importer = new OSMImporter("sweden");
Map<String, String> config = new HashMap<String, String>();
config.put("neostore.nodestore.db.mapped_memory", "90M" );
config.put("dump_configuration", "true");
config.put("use_memory_mapped_buffers", "true");
BatchInserter batchInserter = BatchInserters.inserter(new File(dir), config);
importer.importFile(batchInserter, "sweden.osm", false);
batchInserter.shutdown();
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(dir);
importer.reIndex(db, 10000);
db.shutdown();
GraphDatabaseService does not exists in the Java Driver for Neo4j-Server. Is there a Way to make this Java code work with the Neo4j-Server Java driver ?
CALL spatial.importOSM(osmfile);
This worked for a small file in Neo4j-4.1.6 and I think newer Versions will work to. This enabled the Import to an Neo4j-Server, but it’s really slow (which was mentioned by @craig.taverner in this post.
How can I Import larger files with the Neo4j-Spatial Model ?
Th Neo4j-OSM README says
But the two Models are completely different, for an example:
Neo4j-OSM:
Neo4j-Spatial:
The only similarity I see is the structure of ways and nodes.
So how are these two Importers compatible? Can I create a OSMLayer in the Neo4j-OSM Model ? Or can I use the routeIntersection from Neo4j-OSM in the Neo4j-Spatial Model ?
Many questions, sorry but I’m really confused by this statement
All the sessions of the conference are now available online