Skip to content

Make OSM import easier customizable #1370

Closed

Description

@Nakaner

I am writing a railway router (on the tracks, not on timetables) and talked about it on FOSSGIS 2018 (video in German, I will give a talk at SotM).

I am currently implementing more features to improve routing results. My router adds custom turn restriction between two edges on all nodes if the angle between them is not soft (only slight left, straight on and slight right are permitted). However, some of these nodes need a special treatment. If an OSM node is tagged with railway=railway_crossing, other limits for the angles should apply (only straight on permitted). I think that the OSMReader class is the right location to populate a set of internal node IDs of OSM nodes with railway=railway_crossing. The turn angle evaluation code would check if a nodes is in that set.

However, both processNode() and writeOsm2Graph() are private. All interesting methods of that class are either private or don't have a visibility modifier at all. I can't just derive my own reader class from OSMReader as I did with GraphHopperOSM class (my derivation is called RailwayHopper). I came to the point now where my only choice seems to be to maintain my own (slightly modified) fork of GraphHopper to avoid reading the input file a third time because the OSMReader class is not extensible by third-party developers.

A simple solution would be to open this class and make more methods protected. This comes at the cost of a larger public API and difficulties to change things later because the API is bound too tightly to the implementation (see comment by @karussell). I also think that this would not be good design.

@karussell mentioned hooks as an alternative. They are an alternative but they come with disadvantages as well. They are less flexible and it has to be thought out where to offer which hooks/callbacks. Hooks added now might serve my needs but slightly different requirements might lead to the need of different hooks. Intensive usage of protected offers more freedom and does not limit users of the library to the possible use cases the developers of the library could imagine. My use cases are quite strange and the number of users of such a broad API is very small. That's why I think that we should make more methods protected and mark such methods as "no stability guaranteed", i.e. they might change without prior notice or deprecation.

What do the maintainers of GraphHopper prefer?

Activity

  1. easbar commented on May 14, 2018

    @easbar
    Member

    From a puristic point of view I think it is always desirable that you do not need to override any method, but rather that it does not take much effort to re-use some parts of the class you feel like you want to inherit from and compose them in a new way to achieve what you would like to do. Not sure if you tried this but I fear when you do this with OSMReader you quickly come to the conclusion that there are not enough or even no separate parts of it that you can re-use and you end up copy-and-pasting huge parts of the code, which would be a sign that it 'does too much'. In the long term I think therefore refactoring it into smaller parts should be part of the solution, but probably not a quick one.

    I'm also interested in the question how to define what belongs to the 'public/stable' API. For example considering every public method to be 'stable' seems problematic to me (for instance every interface method is public), but it would definitely be helpful for users (and developers) to be able to see which parts might change any time and which are supposed to be stable ? Does graphhopper make any promises with regards to backwards compatibility so far ?

  2. karussell commented on May 14, 2018

    @karussell
    Member

    We should act like "make most things easy and the rest possible". But the OSMReader class was never designed for extendibility and needs a new design before we should open it up.

    Due to this I do not expect complicated changes in this class and so it is viable (e.g. to avoid a fork) to copy and paste the OSMReader and not using GraphHopperOSM but using your own GraphHopper subclass.

    For example considering every public method to be 'stable' seems problematic to me (for instance every interface method is public), but it would definitely be helpful for users (and developers) to be able to see which parts might change any time and which are supposed to be stable ?

    We can have a look into other projects like Lucene how they do this.

    Does graphhopper make any promises with regards to backwards compatibility so far ?

    No, we are still on 0.x ;)

    If an OSM node is tagged with railway=railway_crossing, other limits for the angles should apply (only straight on permitted)

    The idea for a later design is: make it possible to store any tags for nodes, edges and relations and do things like custom turn costs in a post processing step.

    That's why I think that we should make more methods protected and mark such methods as "no stability guaranteed", i.e. they might change without prior notice or deprecation

    Don't think that this will work. People will use it if accessible. See e.g. the unsafe class in the JDK :)

  3. boldtrn commented on May 15, 2018

    @boldtrn
    Member

    Another possibility would be also to add the functionality in a more generic form to the GraphHopper core as a PR. In a second step you could develop your refinement on top of this.

    My router adds custom turn restriction between two edges on all nodes if the angle between them is not soft (only slight left, straight on and slight right are permitted).

    For example I think that this is an interesting function for different scenarios, like adding a turn penalty (not necessarily restriction) to sharper turns, because they involve a slow down and also might add some danger to the turn as well. When adding this as a generic functionality you could include the hooks you need to customize it to your needs. If these hooks are enough for you, then they might be enough for many other scenarios as well.

    The biggest benefit for you is, that once it's part of the GraphHopper core, it will be maintained, tested, and extended by the community and you will receive improvements for your function over the time as well.

  4. michaz commented on Jun 2, 2018

    @michaz
    Member

    @Nakaner Are you at SOTM this year? Would be happy to talk about this for a minute and see what's missing. I agree with all of you a bit, a) we can't currently do a lot of custom things with the import, but b) inheritance/overridable methods as a fully general way of customizing things is eeevil even though everybody including us does it a lot, but c) finding the right extension points is hard.

  5. Nakaner commented on Jun 2, 2018

    @Nakaner
    ContributorAuthor

    I will be at SotM and give a talk about my railway router (not just a translation of the German version at FOSSGIS).

  6. changed the title [-]Extensibility and flexiblity of GraphHopper (as a library) – general design question[/-] [+]Make OSM import easier customizable[/+] on Sep 10, 2018
  7. karussell commented on Jul 22, 2021

    @karussell
    Member

    Duplicate of #220

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions