Repository navigation
Conversation
# Conflicts: # core/src/main/java/com/graphhopper/reader/osm/OSMReader.java # core/src/main/java/com/graphhopper/routing/util/EncodingManager.java # core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
# Conflicts: # core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
# Conflicts: # core/src/main/java/com/graphhopper/reader/osm/OSMReader.java
# Conflicts: # core/src/main/java/com/graphhopper/reader/osm/OSMReader.java # core/src/test/java/com/graphhopper/reader/osm/OSMReaderTest.java
Member
Author
|
Just for completeness here is the waterway example again: WaySegmentParser waySegmentParser = new WaySegmentParser.Builder(ghStorage.getNodeAccess())
.setDirectory(ghStorage.getDirectory())
// setup the OSM ways we are interested in. normally highways, but here we use waterways
.setWayFilter(way -> way.getNodes().size() > 2 && way.hasTag("waterway"))
// here we retrieve the segments the OSM ways were split into and already receive
// unique ids (from/to) that represent the intersections between the ways. We use these
// as node ids for our routing graph
.setEdgeHandler((from, to, pointList, way, nodeTags) -> {
EdgeIteratorState edge = ghStorage.edge(from, to).setWayGeometry(pointList);
for (FlagEncoder encoder : encodingManager.fetchEdgeEncoders()) {
edge.set(encoder.getAccessEnc(), true, true);
edge.set(encoder.getAverageSpeedEnc(), Math.min(30, encoder.getMaxSpeed()));
edge.setDistance(DIST_EARTH.calcDistance(pointList));
}
})
// this is all we really need. now read the file
waySegmentParser.readOSM(osmFile); |
sfendrich
pushed a commit
to GIScience/graphhopper
that referenced
this pull request
Apr 15, 2026
sfendrich
pushed a commit
to GIScience/graphhopper
that referenced
this pull request
Apr 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OSMReader is quite complicated and does a lot of things. One of its main features is efficiently (fast and low memory usage) finding intersections between OSM ways and splitting these ways into several 'segments' which are then added as edges to the routing graph. This PR extracts a separate class from
OSMReaderthat does just this. This should make it easier to understand, easier to test and easier to customize.WaySegmentParserprovides several callback functions to customize the OSM file parsing. Take for example this very small change that turns GraphHopper into a simple router for waterways: 8d331af. Note that OSMReader is not really needed for this and we can build a graph just withWaySegmentParser.OSMReaderis just the default way GraphHopper uses to build a graph, but not the thing that is strictly needed to do so.Here is a route along the Danube river in Germany: