GraphHopper - Quick Start Guide for Developers
Watch this video for a simple introduction.
git clone git://github.com/graphhopper/graphhopper.git cd graphhopper; git checkout 0.13 # fetches main.js, can be omitted if no UI is needed cd web/src/main/resources/ && ZFILE=/tmp/gh.jar && wget -O $ZFILE "https://repository.sonatype.org/service/local/artifact/maven/redirect?r=central-proxy&g=com.graphhopper&a=graphhopper-web&v=LATEST" && unzip $ZFILE assets/js/main.js && rm $ZFILE && cd ../../../.. ./graphhopper.sh -a web -i europe_germany_berlin.pbf # now go to http://localhost:8989/ and you should see something similar to GraphHopper Maps: https://graphhopper.com/maps/
In the last step the data is created to get routes within the Berlin area:
- The script downloads the OpenStreetMap data of that area
- It builds the graphhopper jar. If Maven is not available it will automatically download it.
- Then it creates routable files for graphhopper in the folder europe_germany_berlin-gh.
- It will create data for a special routing algorithm to dramatically improve query speed. It skips step 3. and 4. if these files are already present.
- It starts the web service to service the UI and also the many endpoints like /route
See also the instructions for Android
For you favourite area do e.g.:
$ ./graphhopper.sh -a web -i europe_france.pbf -o france-gh $ ./graphhopper.sh -a web -i north-america_us_new-york.pbf -o new-york-gh # the format follows the link structure at http://download.geofabrik.de
For larger maps you need to allow the JVM to access more memory. For example for 2GB you can do this using:
$ export JAVA_OPTS="-Xmx2g -Xms2g"
First you need to run the commands given in section Try out, if you have not done so yet.
Then open the project in your IDE, first class IDEs are NetBeans and IntelliJ where no further setup is required.
Running & Debbuging with IntelliJ
Run->Edit Configurations... and set the following to run GraphHopper from within IntelliJ:
Main class: com.graphhopper.http.GraphHopperApplication VM options: -Xms1g -Xmx1g -server -Dgraphhopper.datareader.file=[your-area].osm.pbf -Dgraphhopper.graph.location=./[your-area].osm-gh Program arguments: server config.yml
See this guide on how to contribute.
Java, Embedded Usage
Look here for the maven snippet to use GraphHopper in your application. To use an unreleased snapshot version of GraphHopper you need the following snippet in your pom.xml as those versions are not in maven central:
<repositories> <repository> <id>sonatype-oss-public</id> <url>https://oss.sonatype.org/content/groups/public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories>
When developing the UI for GraphHopper you need to enable serving files directly from local disc via your config.yml:
assets: overrides: /maps: web/src/main/resources/assets/
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash && \. $HOME/.nvm/nvm.sh && nvm install # create main.js via npm cd web && npm install && npm run bundleProduction && cd ..
For windows use nvm-windows.
There are more npm commands to e.g. change the main.js on the fly or create an uglified main.js for production:
cd web # For development just use watchify and all changes will be available on refresh: npm run watch # bundle creates the main file npm run bundle # create main.js for debugging npm run bundleDebug # create main.js for production and specify as CLI parameter `export NODE_ENV=development` which `options_*.js` file should be selected npm run bundleProduction # Forcing consistent code style with jshint: npm run lint # see the package.json where more scripts are defined
If you need offline routing in the browser like for smaller areas or hybrid routing solution then there is a highly experimental version of GraphHopper using TeaVM. Have a look into this blog post for a demo and more information.
For details on Android-usage have a look into this Android site
Swing and Desktop Usage
You can use Graphhopper on the Desktop with the help of mapsforge too. No example code is given yet but with the Android example combined with the Desktop example of the mapsforge project it should not be hard.
For smallish graph (e.g. size of Berlin) use a RAMDataAccess driven GraphStorage (loads all into memory). For larger ones use the ContractionHierarchies preparation class and MMapDataAccess to avoid OutOfMemoryErrors if you have only few RAM.
Raspberry Pi usage is also possible. Have a look into this blog post.