Skip to content

graphium-project/graphium-neo4j

Repository files navigation

Graphium Neo4j

Graphium Neo4j is an extension of the project Graphium implemented as Neo4j Server plugin.

Graphium Neo4j is an extension of the project Graphium based on Neo4j. Neo4j is a famous graph database which comes with various graph algorithms. Neo4j's graph model is built for answering graph dependent questions in a more flexible and performant way than you can do with a relational database. As transport graphs can be modeled as graphs and stored in Neo4j, we benefit from its features.

Graphium Neo4j is built for those who want to manage graphs and graph versions within Neo4j and / or need routing or even a map matching API. Graphium Neo4j consists of modules which have to be deployed as Neo4j Server plugins (so called unmanaged extensions). Therefore Graphium Neo4j is not a standalone server but requires a Neo4j Server.

Features

Graphium Core

Graphium Neo4j include all Graphium core features. See Graphium.

Routing

Graphium Neo4j's routing API handles routing requests between two coordinates on a transport graph. The result will be returned in a JSON format.


Map: basemap.at

Map Matching

Graphium Neo4j's map matching API matches trajectories onto a transport graph. In contrast to Hidden Markov Model implementations, Graphium Neo4j's map matching core implementation is built for processing trajectories having a high sampling rate (<20 seconds). The main focus was to enable a high-performance processing of those high-sampled trajectories with a very low error ratio. Also low-sampled trajectories can be processed, but with an increasing error ratio. With Graphium's ability of working in distributed systems, you can improve the performance by horizontal scaling. Graphium Neo4j's map matching supports offline and online map matching.

Map Matching of a lower sampled track (for better visualization); blue point show GPS track points, red linestring represents the map matched path on graph (thin black linestrings):


Map: basemap.at

Map Matching of a track whose GPS track points partially could not have been matched onto graph. The map matcher detects non matchable parts of the track and splits the map matched path:


Map: basemap.at

Please note

For both routing and map matching a valid graph version (especially validity has to be defined correctly) has to be imported and activated (state is ACTIVE). If a graph version has been imported its state is INITIAL, which normally means someone has to verify the data first or this graph version is only some kind of test version and should not be taken into account for the production system. Only after verification and activation of a graph version it can be used for processing.

API

Routing

Defining road blocks

Map Matching

Quickstart

  1. Graphium Neo4j is an extension of Graphium. Therefore Graphium has to be checked out and built before.

  2. Build Graphium Neo4j via Maven mvn clean install

  3. The following plugins have to be deployed in the Neo4j's plugins directory: graphium-neo4j-server-integration-plugin-XXX.jar (Graphium's core functionality and integration into Neo4j) graphium-api-neo4j-plugin-XXX.jar (API) graphium-routing-neo4j-plugin-XXX.jar (routing functionality and API) graphium-mapmatching-neo4j-plugin-XXX.jar (map matching functionality and API)

  4. Copy property files to Neo4j's conf directory and configure:

    graphVersionCapacities.properties
    import.properties
    log4j.xml
    mapmatcher.properties
    neo4j_db.properties
    server.properties
    

    Default property files can be found in neo4j-server-integration/doc/neo4j-default/conf.

    The following properties within server.properties have to be adapted. Be careful at changing other property values: graphium.server.name graphium.server.uri

  5. Register Graphium at Neo4j: neo4j.conf in Neo4j's conf directory has to be extended by:

    dbms.unmanaged_extension_classes=at.srfg.graphium.neo4j.bootstrap=/graphium-neo4j/api
    dbms.jvm.additional=-Dgraphium.conf.path=file:conf/
    graphium.secured=true/false
    
  6. Start Neo4j

    neo4j.bat console
  7. Download and convert OSM File into Graphium's JSON format, import into Graphium central server *):

    java -jar /osm2graphium.one-jar.jar -i http://download.geofabrik.de/europe/andorra-latest.osm.pbf -o / -n osm_andorra -fd true -v 200603 -q 20000 -t 5 --highwayTypes "motorway, motorway_link, primary, primary_link" -u "http://localhost:7474/graphium/api/segments/graphs/osm_andorra/versions/200603?overrideIfExists=true"
  8. Activate imported graph version

    curl -X PUT "http://localhost:7474/graphium/api/metadata/graphs/osm_andorra/versions/200603/state/ACTIVE"
  9. Check server state

    curl -X GET "http://localhost:7474/graphium/api/status"

Docker

  1. Start Docker setup

    docker-compose up -d

Application and database logs can be obtained via docker-compose logs.

If any of the following steps crashes because of a Java heap exception you have to configure memory definition of Docker and configure Neo4j's heap memory by setting the environment variable NEO4J_dbms_memory_heap_max__size within docker-compose.yml.

  1. Download and convert OSM File into Graphium's JSON format, import into Graphium central server *):

    docker exec -it graphium-neo4j-server java -jar /osm2graphium.one-jar.jar -i http://download.geofabrik.de/europe/andorra-latest.osm.pbf -o / -n osm_andorra -fd true -v 200603 -q 20000 -t 5 --highwayTypes "motorway, motorway_link, primary, primary_link" -u "http://localhost:7474/graphium/api/segments/graphs/osm_andorra/versions/200603?overrideIfExists=true"
  2. Activate imported graph version

    curl -X PUT "http://localhost:7474/graphium/api/metadata/graphs/osm_andorra/versions/200603/state/ACTIVE"
  3. Check server state

    curl -X GET "http://localhost:7474/graphium/api/status"

*) Notice parameter highwayTypes: only high level streets will be imported; adapt if needed (see OSM highway types).

Routing Example

curl -X GET "http://localhost:7474/graphium/api/routing/graphs/osm_andorra/route.do?coords=1.614733,42.5720773;1.5937977,42.56574"

Map Matching Example

curl -H "Accept:application/json" -H "Content-Type:application/json" -X POST "http://localhost:7474/graphium/api/matching/graphs/osm_andorra/versions/current/matchtrack?outputVerbose=true&timeoutMs=60000" -d '{"id":1,"trackPoints":[{"id":0,"timestamp":1591776000000,"x":1.5512481,"y":42.512805,"z":0},{"id":0,"timestamp":1591776002000,"x":1.5515414,"y":42.5130289,"z":0},{"id":0,"timestamp":1591776006000,"x":1.5520432,"y":42.5132296,"z":0},{"id":0,"timestamp":1591776011000,"x":1.5527147,"y":42.5135306,"z":0},{"id":0,"timestamp":1591776017000,"x":1.5533361,"y":42.514206,"z":0},{"id":0,"timestamp":1591776025000,"x":1.5538764,"y":42.5151092,"z":0},{"id":0,"timestamp":1591776035000,"x":1.5542151,"y":42.5162136,"z":0}]}'

Plugins Development

You can build your own Neo4j plugins based on Graphium Neo4j. Graphium Neo4j plugins use Spring Framework, which defines configuration information within ApplicationContexts. For integration of custom Neo4j plugins into Graphium Neo4j only one ApplicationContext with the name pattern application-context-graphium-neo4j-plugin*.xml has to be provided. All Beans defined within this ApplicationContext will be loaded automatically by Graphium Neo4j.

Dependencies