How can I create my own Weighting based on Edge Geometry

Hi ORS-Team and -Community,

I’ve recently tried some vibe coding with ChatGPT as my Co-Pilot with the goal of extending ORS so that I can add my own geometry-based weighting functionality. The idea is to have yet another preference option along “fastest”, “shortest” and “recommended”. For the sake of this example, let’s say I want to optimize my route to include the “straightest” roads and therefore add a StraightWeighting to each edge.

First, I created my own Weighting class like so

public class StraightnessWeighting extends AbstractWeighting { // is this inheritance correct in the first place?
    public StraightnessWeighting (FlagEncoder encoder, TurnCostProvider tcp) {
        super(encoder, tcp);
    }

    @Override
    public double getMinWeight(double v) {
        return 0;
    }

    @Override 
    public double calcEdgeWeight(EdgeIteratorState edge, boolean reverse) {
        return 1; // TODO
    }

    @Override 
    public long calcEdgeMillis(EdgeIteratorState edge, boolean reverse) {
        return (long) (1000);
    }

    @Override 
    public String getName() { return "straightness"; }
}

Next I register StraightnessWeighting with the ORSWeightingFactory:

public class ORSWeightingFactory implements WeightingFactory {
    // ...

    @Override
    public Weighting createWeighting(Profile profile, PMap requestHints, boolean disableTurnCosts) {
        // ...
        Weighting weighting;
        if (VAL_CUSTOM.equalsIgnoreCase(weightingStr) || profile instanceof CustomProfile) {
            // ...
        } else if ("shortest".equalsIgnoreCase(weightingStr)) {
            weighting = new ShortestWeighting(encoder, turnCostProvider);
        } else if ("straightness".equalsIgnoreCase(weightingStr)) {
            weighting = new StraightnessWeighting(encoder, turnCostProvider);
        } else {
            weighting = new ORSFastestWeighting(encoder, hints, turnCostProvider);
        }

        if ("recommended".equalsIgnoreCase(weightingStr) && encoder.supports(PriorityWeighting.class)) {
            weighting = new ORSPriorityWeighting(encoder, turnCostProvider, weighting);
        }

Finally, I created my config:

ors:
  engine:
    profiles:
      drive-straight:
        enabled: true
        encoder_name: driving-car
        build:
          preparation:
            min_network_size: 200
            methods:
              ch:
                enabled: true
                weightings: straightness
              lm:
                enabled: false
                weightings: straightness
              core:
                enabled: true
                weightings: straightness
                lmsets: highways;allow_all

On ORS startup I now get errors like:

ors-app | 2025-08-21 15:53:40 ERROR ORS-Init [ o.h.o.r.RoutingProfileManager ] ExecutionException while initializing RoutingProfileManager: java.lang.IllegalArgumentException: Could not create weighting for profile: 'car_ors_straightness'.

and I am wondering: What am I doing wrong and what am I missing. I am pretty sure that I am doing something fundamentally wrong. Also, it seems that the error does not stem from ORS itself, but most likely from the underlying graphhopper instance, so maybe my approach is completely wrong and I am trying something that is not supposed to work by design!?

Could enyone please point me in the right direction and explain what is wrong and how to do this the right way?