How to use custom tag in custom model

I have added my custom tag floor to version 8.0 according to pr. But I didn’t find any documentation or posts explaining how to use it in custom models.

How did you add floor to the engine? With an encoded value named floor? Then, if it is e.g. of type integer, you can use it like:

{ "if": "floor == 0", "multiply_by": "0.5" }

See the custom model documentation: graphhopper/docs/core/ at master · graphhopper/graphhopper · GitHub

There is a floor field in my own shapefile format data, and I wrote a program to convert it to osm format according to the osm specification. Finally, the 8.0 core module in the source code changed. I’m not going to use the webapi module, I’m going to use the low-level code in the core module to implement the above ideas.

EnumEncodedValue<Floor> OSMFloorEnc = hopper.getEncodingManager().getEnumEncodedValue("floor", Floor.class);
//        EnumEncodedValue<Floor> OSMFloorEnc = new EnumEncodedValue<>("floor", Floor.class);
        EncodingManager em = EncodingManager.start().add(accessEnc).add(speedEnc).add(priorityEnc).add(OSMFloorEnc).build();
//        EncodingManager em = hopper.getEncodingManager();
        CustomModel model = new CustomModel();
        for (int i = 0; i < avoidPolygonsLength; i++) {
            String floor = avoidPolygonFloors.get(i);
            if(floor == null){
                model.addToPriority(If("in_custom" + i, MULTIPLY, "0.0"));
                model.addToPriority(If("in_custom" + i + "&& floor == " + floor, MULTIPLY, "0.0"));
        Weighting weighting = CustomModelParser.createWeighting(accessEnc, speedEnc, priorityEnc, em, TurnCostProvider.NO_TURN_COST_PROVIDER, model);
        AStar ASVerify = new AStar(queryGraph, weighting, TraversalMode.NODE_BASED);
        Path pathVerify = ASVerify.calcPath(fromId, toId);

So here’s part of my code, I’m using graphhopper and querygraph, And if I use EnumEncodedValue<Floor> OSMFloorEnc = new EnumEncodedValue<>("floor", floo.class);, all the edges end up being the default values. If I use the EnumEncodedValue < Floor > OSMFloorEnc = hopper. GetEncodingManager () getEnumEncodedValue (" Floor ", the Floor. The class); And finally throw an exception, can not init mutilple times

The error message sounds like you try to create the EncodingManager multiple times. You have to avoid it and create it only once. (Not one for every request!)

And I suggest using our GraphHopper class instead of the low level API. Then have a look into our examples on how to use it:

The low level API (without is only recommended if you know what you do.

I’m actually still using, so I’m not actually using the underlying Api, right? The program no longer reports this error, but eventually every edge will be F1 on the floor of the custom model. But if I use basegraph I can see B1, can you see where I’m wrong

If you are using then there is no need to create the EncodingManager and just get it from the graphhopper object. And to add new encoded values you’ll have to extend the DefaultEncodedValueFactory and potentially also extend the DefaultTagParserFactory before doing the import. (or use the latest master where this is easier by extending only the DefaultImportRegistry)

The program no longer reports this error, but eventually every edge will be F1 on the floor of the custom model. But if I use basegraph I can see B1, can you see where I’m wrong

Not sure what you mean here. If all edges are F1 then this will be in the BaseGraph as well.

Well, I wasn’t clear enough, and you weren’t going to give users the low-level API to do what they wanted, so there wasn’t much documentation. But I still prefer to use the low-level API because I started my work with it, and now the refactoring has affected me so much that I’m not sure how long it will take. I’m going to take another look at the source code in GHResponse res = Hoper.route (req) to see how it implements the functionality I mentioned above. Sincerely, thank you.