import osm file to Neo4j 3.3.2

942 Views Asked by At

I am new to neo4j & using neo4j version 3.3.2 neo4j spacial branch - 0.25-neo4j-3.3

Could you provide a code snippet to import osm file?

I have tried https://github.com/maxdemarzi/OSM . Neo4j spacial ReadMe(Importing an Open Street Map file) example does not work.

/Thanks

1

There are 1 best solutions below

2
stdob-- On

You can just install the Neo4j Spatial plugin and run the cypher query for import:

CALL spatial.addLayer('layerTestName', 'osm', '')
CALL spatial.importOSMToLayer('layerTestName', '/path/to/file.osm')

Java example (from doc):

OSMImporter importer = new OSMImporter("/path/to/file.osm");
importer.setCharset(Charset.forName("UTF-8"));
BatchInserter batchInserter = getBatchInserter();
importer.importFile(batchInserter, "map.osm", false);
//batchInserter.shutdown();
//GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase(databasePath);
reActivateDatabase(false, false, false);
GraphDatabaseService db = graphDb();
importer.reIndex(db);
db.shutdown();