itinero / routing

The routing core of itinero.
Apache License 2.0
220 stars 70 forks source link

Use OSM's Surface tag in routing & return with GeoJSON Properites #336

Open Bairdo opened 3 years ago

Bairdo commented 3 years ago

Hi, I am trying to use the 'surface' tag of OSM for a couple of things:

Is there something I need to do to enable it (e.g. An Extension) or is it unsupported? I haven't been able to figure it out yet. Thanks

Snapshot of what my route.GeoJSON(...)

    "type": "FeatureCollection",
    "features": [
        {
            "type": "Feature",
            "geometry": {
                "type": "LineString",
                "coordinates": [ ...
                ]
            },
            "properties": {
                "highway": "primary",
                "profile": "bicycle",
                "distance": "175.51111",
                "time": "42.12266"
            }
Bairdo commented 3 years ago

I think I've answered my own question for the most part. And Lua profiles seem to be the answer.

Basically add the tag you want to the appropriate whitelist (explanation of each is on the above link). Then it can be accessed as a member of the attributes in factor_and_speed - In my case add it to the result.

In particular

...
-- whitelists for profile and meta
profile_whitelist = {
    "highway",
    "surface"
}
meta_whitelist = {
    "name",
    "surface"
}
...
-- the main function turning attributes into a factor_and_speed and a tag whitelist
function factor_and_speed (attributes, result)
...
     result.attributes_to_keep = {}
     result.attributes_to_keep.surface = attributes.surface
...
end

Although the minimal example didn't work (the database kept being empty) so used the default car as the base.