Search code examples
javascalaopenstreetmapgraphhopper

How to create&sample routes using OSM


I wish to use OSM (or an open, OSM based service) in order to "create" routes between aleatory points and then sample those routes an unlimited amount of time. Sample as in get lan+lat and various other info if available (e.g. elevation, points of interest... etc).

I've been struggling to find similar projects, or documentation that might help me. Right now I am quite unsure even on the subject of how to download part of the OSM schema locally so that I don't have to use the API over the web and spam the OSM servers.

Most resources that I've been able to find online are, sadly, enough, sparsely documented and often unmaintained :/

If I were to split what I need to learn into 3 parts those would be:

a) Get the OSM schema for a certain "region" of the world downloaded and running locally and connect to & control it.

b) Figure out how to create an entity around the lines of "route" between two points (say addresses in a city).

c) Figure out how to query said entities for various samples along the route.

This needn't be done in OSM, if there is a product better suited for this, but I have to use something open and OSM seems to be by far the biggest most well maintained project.

(I should note I am building the app in scala, but I'm fine with documentation for other languages/language agnostic, as well as it actually explains stuff and goes into details, instead of just throwing some incomplete lines of code at you)


Solution

  • Re 1: Grab OSM from http://planet.osm.org/ and extract your area via osmcut, osmosis, osmconvert etc. Or use preprocessed extracts e.g. from geofabrik

    Re 2: Street names are simple, everything else is complex. You'll need another preprocessing step which gives you the boundaries or some guesses of every city/village and then feed the routing engine with this.

    Re 3: Once you have this stored in the routing engine this should be rather simple to query and return.

    OSM seems to be by far the biggest most well maintained project.

    Maybe here is a misunderstanding: OpenStreetMap is a database and so it is just data. Now it happens to be an ecosystem for various tools like tools for routing, see the tagged GraphHopper routing engine here and others here