This project demonstrates how to set up and extend a custom Java web application using GraphHopper for routing and map data processing.
- Custom GraphHopper Integration:
Usesgraphhopper-webas a dependency for routing and map data. - Custom Encoded Values:
Adds new time-dependent average speed encoded values (e.g.,avgspeed_mo_fr_0400_0700) for advanced routing scenarios. - Custom Tag Parser:
ImplementsAvgSpeedConditionalParserto parse and apply conditional average speed tags from OSM data. - Configurable via YAML:
New routing profiles, encoded values, and other settings are managed inconfig.yml. - Dropwizard Web Server:
Runs as a Dropwizard application with custom endpoints and resources. - Maven Build:
Uses Maven for dependency management and building a runnable JAR.
cd graphhopper-web-demo
mvn clean install -DskipTests- Import OSM data and build the graph (get sample data here):
java -jar target/graphhopper-web-demo-1.0-SNAPSHOT.jar import ../config.yml
- Start the web server:
java -jar target/graphhopper-web-demo-1.0-SNAPSHOT.jar server ../config.yml
graphhopper-web-demo/- Main Java application and custom codeconfig.yml- Main configuration file for GraphHopper and servertest_data.pbf- Example OSM data file for importgraph-cache/- Generated graph data (ignored by git).gitignore- Excludes build, cache, and log files
You can add custom routing rules directly in the UI by editing the custom model JSON. For example, to use your time-dependent average speed values, add a rule like this to the speed section:
"speed": [
{
"if": "avgspeed_mo_fr_1200_1400>0",
"limit_to": "avgspeed_mo_fr_1200_1400"
}
]- The
"if"condition checks if the encoded value (e.g.,avgspeed_mo_fr_1200_1400) is greater than 0 for the current edge. - The
"limit_to"field sets the speed to the value of that encoded value when the condition is true.
You can add similar rules for other time slots or custom encoded values. This allows you to create highly dynamic and context-aware routing profiles directly from the UI.
- Add/modify encoded values in
config.ymlundergraph.encoded_values. - Edit or extend tag parsers in
src/main/java/com/graphhopper/samples/parsers/. - Change routing profiles in
config.ymlunderprofiles:.
- Java 11+ (configured in Maven and devcontainer)
- Maven for builds
- Devcontainer setup for VS Code
