Giter VIP home page Giter VIP logo

haytastan / osm2graph-neo4j Goto Github PK

View Code? Open in Web Editor NEW

This project forked from scenic-routing/osm2graph-neo4j

0.0 0.0 0.0 40 KB

Imports OpenStreetMap data into a Neo4j graph database. Produces a simple schema that includes nodes, ways, and all properties/tags contained in the source OSM data.

Home Page: https://taylor.callsen.me/loading-openstreetmap-data-into-a-graph-database/

License: Apache License 2.0

Shell 5.93% Java 94.07%

osm2graph-neo4j's Introduction

osm2graph Loader (Java-Neo4j)

Imports OpenStreetMap data into a Neo4j graph database. Produces a simple schema that includes nodes, ways, and all properties/tags contained in the source OSM data.

Designed to read OSM data in XML format. Uses SAX event-driven XML parsing to accomidate large XML files.

Concerns:

  • Does not make use of any spatial indexing, or the Noe4j Spatial plugin. Geometries are stored in WKT format as properties on the created nodes and relationships.

Schema

alt text

OSM Nodes are imported as graph nodes with the label of INTERSECTION. Their point geometry stored in WKT format in the geom property.

OSM Ways are imported as relationships between the nodes (or intersections). Ways are labeled as CONNECTS, with their LineString WKT geometry stored in the way property. Only ways with a highway tag are imported (must match Xpath: /osm/way[tag/@k = 'highway']). More information about possible highway values is avilable here.

All other properties and tags in the source OSM data are flattened and attached as properties on the graph nodes/relationships that are created during import.

Build

Built with the Java 8 JDK and Neo4j Server Community (version: 3.5.11). Code should be fairly portable, as no advanced features of Java or Neo4j are used.

This is a maven project and can be built using:

mvn clean install

Make sure the Neo4j library version in the pom.xml file matches the Neo4j Server version. Available versions in Maven Central can be found here.

Running

The importer is executed through Maven and accepts 3 paramters:

  1. osmFile - required - path to the source OSM XML file
  2. graphDb - required - filesystem path to the Neo4j GraphDB (web/Bolt API not supported)
  3. action - optional - allows execution of specific actions listed below (only needed in advanced scenarios)

To perform the default import:

mvn exec:java -DosmFile=/Users/Taylor/Downloads/SanFrancisco.osm -DgraphDb=/var/lib/neo4j/data/databases/graph.db 

To perform a specific action:

mvn exec:java -DosmFile=/Users/Taylor/Downloads/SanFrancisco.osm -DgraphDb=/var/lib/neo4j/data/databases/graph.db -Daction=loadnodes

A Bash script has been included (run.sh) to simplify execution and provide a menu for selecting actions. Just be sure to set the OSMFILEPATH and GRAPHDBPATH variables up top.

Available actions (all executed as part of defeault action):

  • loadnodes - Loads OSM nodes into GraphDB
  • loadways - Loads OSM ways into GraphDB
  • createnodeindex - Creates an GraphDB index of Nodes on the osm_id property; used to speed up node lookup during way import
  • resetgraphdb - Clears the GraphDB of all nodes, relationships, and indeces

Sample Cypher Queries

Get street by name:

MATCH (a)-[r{name: 'Marlene-Dietrich-Straße'}]-(b) RETURN a, r, b

Get street by type:

MATCH (a)-[r]-(b) WHERE r.highway = 'secondary' OR r.highway = 'residential' RETURN a, r, b

OSM Data Sources

City exports of OSM data are made avaiable via BBBike.

Exports by country/region are available from Geofabrik.

More Information

Here is a blog entry I wrote about creating this loader, which goes into further detail on a few of the design decisions and methodologies used.

osm2graph-neo4j's People

Contributors

tcallsen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.