jpmens / revgeod

A reverse Geo lookup service written in C, accessible via HTTP and backed by OpenCage and LMDB
Other
13 stars 1 forks source link

Add roadinfo=1 as default to queries? #7

Open jpmens opened 5 months ago

jpmens commented 5 months ago

As suggested by Ed.F in an email, it might be worth while for us to add roadinfo=1 to reverse geo queries to OpenCage; as we use revgeod mainly for vehicles, we'd profit from this additional data

  "roadinfo": {
    "drive_on": "right",
    "lanes": 3,
    "maxheight": "default",
    "maxspeed": 90,
    "oneway": "yes",
    "road": "Autoroute du Soleil",
    "road_reference": "A 7",
    "road_reference_intl": "E 15",
    "road_type": "motorway",
    "speed_in": "km/h",
    "surface": "asphalt",
    "toll": "yes"
  }

Ed writes:

The only issue is that if that if that parameter is set we geocode to the nearest road, not to the house address.

freyfogle commented 5 months ago

Here is some background about roadinfo and here is a detailed documentation of all the possible fields we then return

jpmens commented 5 months ago

I'm seeing toll on some of the French autoroutes, but stabbing around in Poland, for example, doesn't give me a toll value.

The position 52.203636, 21.700764 is indicated by OSM as being toll:bus and toll:hgv

Bildschirmfoto 2024-06-18 um 12 52 40

However, when querying it

curl -sSf 'https://api.opencagedata.com/geocode/v1/json?q=52.203636,21.700764&pretty=1&key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&roadinfo=1'

we're not seeing toll:

            "roadinfo" : {
               "drive_on" : "right",
               "lanes" : 2,
               "maxspeed" : 140,
               "oneway" : "yes",
               "road" : "Autostrada Wolno\u015bci",
               "road_reference" : "A2",
               "road_reference_intl" : "E 30",
               "road_type" : "motorway",
               "speed_in" : "km/h",
               "surface" : "asphalt"
            },

Stabbing around on large roads north and south of Warsaw doesn't show any toll road, which may be a coincidence.

freyfogle commented 5 months ago

great example, thanks. probably we need to adapt how we handle roads that are toll only for some classes of vehicles.

investigating ...

ckrey commented 5 months ago

https://wiki.openstreetmap.org/wiki/Key:toll

freyfogle commented 5 months ago

yes, that is the issue. It seems toll:hgv and a few others, has become much more popular since we launched this feature 5+ years ago. Thanks for making us aware. We are debating the best way to return this data.

jpmens commented 5 months ago

Breaking toll: true/false is likely a bad idea, so maybe an additional string would be useful, populated with the type of vehicle. Somthing like toll_type: hgv comes to mind. Just a thought. We're sure you'll do it properly.

freyfogle commented 5 months ago

hmm, yes, that approach is good. I suppose multiple toll types - like your example - is then toll_type: bus, hgv

edit - not once in my life have I not mistyped "toll" as "tool"

jpmens commented 5 months ago

I personally would prefer an array:

"tool^H^Hll_type": [ "bus", "hgv" ]

but a comma-separated list would be fine if that's easier on your end.

freyfogle commented 5 months ago

The good news is it seems toll status has much better coverage than it did a few years ago. Unfortunately it seems there is quite the range of options to include the case where only some types of vehicles pay a toll, or the total opposite, where all vehicles pay a toll, but certain types are excluded. So we need to do a bit of thinking about how to present this.

freyfogle commented 5 months ago

ok I am now leaning towards something like

               "toll" : "yes",
               "toll_type" : {
                  "included" : [
                     "bus",
                     "hgv"
                  ],
               }

or

               "toll" : "yes",
               "toll_type" : {
                  "excluded" : [
                    "bicycle"
                  ]
               }

thoughts?

jpmens commented 5 months ago

Thinking aloud, that would permit something along these lines (in Python) which looks as though it's all there.

lorry = False
if "included" in toll_type and "hgv" in toll_type["included"]:
    lorry = True
if "excluded" in toll_type and "hgv" not in toll_type["excluded"]:
    lorry = True

So, yes, looks good to me.

freyfogle commented 5 months ago

Well the issue is how to handle ambiguous data.

For example we may simply have toll = yes, and no explicit types. or the opposite, very precise data. We may have toll:N3 = yes (N3 being an EU classification of HGV).

So I think you will need to program more defensively than that I am afraid. Welcome to OpenStreetMap

freyfogle commented 5 months ago

ok, time to write lots of tests. Hopefully we will get this live tomorrow

jpmens commented 5 months ago

you will need to program more defensively than that

yes, of course

freyfogle commented 5 months ago

ok, this is now live with one tweak. We decided to name the field toll_details since we potentially also set other information about the toll (operator)

The relevant docs are updated, post on the OpenCage blog coming in the next hour or so.

jpmens commented 5 months ago

More toll road information

Thank you, @freyfogle

jpmens commented 5 months ago
            "roadinfo" : {
               "drive_on" : "right",
               "lanes" : 2,
               "maxspeed" : 140,
               "oneway" : "yes",
               "road" : "Autostrada Wolno\u015bci",
               "road_reference" : "A2",
               "road_reference_intl" : "E 30",
               "road_type" : "motorway",
               "speed_in" : "km/h",
               "surface" : "asphalt",
               "toll" : "yes",
               "toll_details" : {
                  "included" : [
                     "bus",
                     "hgv"
                  ]
               }
            },

Looks good to me.