[solved] Minimalistic new routing profile / Cannot find point


Probably a very basic beginner question. But I’m trying to create a new minimalistic routing profile for trains. First I did a copy of the CarFlagEncoder and adjusted it to simply stay on the railtracks. The code compiles successfull but whenever I send an API request I get the message: “Cannot find point …”.

When running graphhopper I have the following output in the messages:

2017-10-11 13:23:58,729 [main] INFO com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks - 37732 subnetworks found for rail, totalMB:976, usedMB:176
2017-10-11 13:23:58,761 [main] INFO com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks - optimize to remove subnetworks (37732), unvisited-dead-end-nodes (43238), maxEdges/node (4)
2017-10-11 13:23:58,763 [main] WARN com.graphhopper.storage.BaseGraph - More than a half of the network should be removed!? Nodes:39430, remove:37730
2017-10-11 13:23:58,815 [main] INFO com.graphhopper.reader.osm.GraphHopperOSM - edges: 45498, nodes 1700, there were 37732 subnetworks. removed them => 37730 less nodes

Could it be that for some reason most edges are removed and therefore no point can be found? Who is removing these edges and how can I debug this?

This is my code (very minimalistic approach):
package com.graphhopper.routing.util;

import com.graphhopper.reader.ReaderRelation;
import com.graphhopper.reader.ReaderWay;
import com.graphhopper.util.Helper;
import com.graphhopper.util.PMap;

import java.util.*;

public class RailFlagEncoder extends AbstractFlagEncoder {
    protected final Map<String, Integer> trackTypeSpeedMap = new HashMap<String, Integer>();

    public RailFlagEncoder() {
        this(5, 5, 0);

    public RailFlagEncoder(PMap properties) {
        this((int) properties.getLong("speed_bits", 5),
                properties.getDouble("speed_factor", 5),
                properties.getBool("turn_costs", false) ? 1 : 0);
        this.properties = properties;

    public RailFlagEncoder(String propertiesStr) {
        this(new PMap(propertiesStr));

    public RailFlagEncoder(int speedBits, double speedFactor, int maxTurnCosts) {
        super(speedBits, speedFactor, maxTurnCosts);
        maxPossibleSpeed = 140;

    public int getVersion() {
        return 1;

     * Define the place of the speedBits in the edge flags for car.
    public int defineWayBits(int index, int shift) {
        shift = super.defineWayBits(index, shift);
		speedEncoder = new EncodedDoubleValue("Speed", shift, speedBits, speedFactor, 60, maxPossibleSpeed);
        return shift + speedEncoder.getBits();

    protected double getSpeed(ReaderWay way) {
        return 60;

    public long acceptWay(ReaderWay way) {
        String railwayValue = way.getTag("railway");
		if ("rail".equals(railwayValue)) {
			return acceptBit;
		return 0;

    public long handleRelationTags(ReaderRelation relation, long oldRelationFlags) {
        return oldRelationFlags;

    public long handleWayTags(ReaderWay way, long allowed, long relationFlags) {
		return 1;

    public String toString() {
        return "rail";


The subnetwork preparation removes them. You can avoid this via


But this will highly likely not fix the issue that the train graph you trying to build seems to consists of many separate networks again leading to problems like ‘connection not found’ or similar

Thanks! I did that but as you already mentioned I get a “Connection between locations not found” error message. But there is clearly a connection between the 2 points. For the map I’m using Switzerland which should not have to many seperate networks I assume. What can I do to still route on railway?

Maybe you made some mistakes for the import and it forgets a few rails => subnetworks can be the result. You can visualize the road network via the MiniGraphUI in the tools module to verify this. Check acceptWay which ways are rejected

I run MiniGraphUI and to me the result looks good! (Screenshot below). Then I took two points very close to each other and I still get the message “Connection between locations not found” even though they are on the same line literally just a few kilometers apart.

Make sure you initialize every edge with forward and backward access and a speed > 0

Thank you very much. It worked now!!!

1 Like

is it than possible to have one graph-cache for car and rail at the same time? railway and highway in the same graph-cache? (graph.flag_encoders=rail,car).

Avoid hijacking other threads and just create a new one.

I wrote a new thread for my problem, excuse me for that.