Opened 9 years ago

Closed 9 years ago

Last modified 9 years ago

#796 closed defect/bug (fixed)

Speed warner incorrectly reads road speed limits on UK and USA open streetmaps

Reported by: pregp Owned by: KaZeR
Priority: minor Milestone: version 0.5.0
Component: core Version: git master
Severity: Keywords:
Cc:

Description

Because open street maps of UK and USA have road speed limits encoded in miles per hour Navit incorrectly reports these as km/h in metric mode and incorrectly "converts" them as if they were km/h to miles per hour in imperial mode thus incorrectly warning of speeding in both metric and imperial modes.

Change History (4)

comment:1 Changed 9 years ago by korrosa

This is interesting: can you provide us with an OSM link to the road you were travelling on when this happened? (If it happened multiple times, provide multiple links until you get bored....!). This will enable us to rule out errors in the way the tags have been set in OSM.

I'm in the UK, and must admit I haven't noticed this problem - however, I'm not always paying attention either....

comment:2 follow-up: Changed 9 years ago by tegzed

Hello pregp,

According to the openstreetmap wiki ( http://wiki.openstreetmap.org/wiki/Key: ) maxspeed in osm data should be interpreted as km/h unless mph suffix is explicitly set.

This should be handled correctly by navit, I checked this using the demo vehicle with london's osm map. I found the handling of maxspeed mph suffix in the code of map conversion tool of navit also.

922         if (! strcmp(k,"maxspeed")) {
 923                 if (strstr(v, "mph")) {
 924                         maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
 925                 } else {
 926                         maxspeed_attr_value = atoi(v);
 927                 }
 928                 if (maxspeed_attr_value)
 929                         flags[0] |= AF_SPEED_LIMIT;
 930                 level=5;
 931         }

Can you check the problematic maxspeed tags in osm data to see if mph suffix is set correctly?

comment:3 in reply to: ↑ 2 Changed 9 years ago by pregp

  • Resolution set to fixed
  • Status changed from new to closed

Replying to https://wiki.navit-project.org/index.php/user:tegzed:

Hello pregp,

According to the openstreetmap wiki ( http://wiki.openstreetmap.org/wiki/Key: ) maxspeed in osm data should be interpreted as km/h unless mph suffix is explicitly set.

This should be handled correctly by navit, I checked this using the demo vehicle with london's osm map. I found the handling of maxspeed mph suffix in the code of map conversion tool of navit also.

922         if (! strcmp(k,"maxspeed")) {
 923                 if (strstr(v, "mph")) {
 924                         maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
 925                 } else {
 926                         maxspeed_attr_value = atoi(v);
 927                 }
 928                 if (maxspeed_attr_value)
 929                         flags[0] |= AF_SPEED_LIMIT;
 930                 level=5;
 931         }

Can you check the problematic maxspeed tags in osm data to see if mph suffix is set correctly?

I've had a look and it does seem to be a problem with some maxspeed tags in UK osm road data. If tagged as "30mph" it is read as the default 30 km/h. The maxspeed tag needs to be labelled as "30 mph" (with a space between the number and the mph) in order for it to be corrected identified. There seem to be quite a few roads wrongly tagged in this way! Good to know it's not a bug in Navit though....

comment:4 Changed 9 years ago by korrosa

Whilst it's true that the OSM wiki suggests using a space before the "mph" string, many, many people do not use this. As a result the same wiki page suggests parsing the maxspeed string ignoring spaces (see "Parser" on http://wiki.openstreetmap.org/wiki/Key:maxspeed).

As far as I'm aware, Navit also ignores whether there is or there isn't a space in the maxspeed string, and only looks for "mph". Here's the relevant bit of code from osm.c, line 922:

        if (! strcmp(k,"maxspeed")) {
		if (strstr(v, "mph")) {
			maxspeed_attr_value = (int)floor(atof(v) * 1.609344);
		} else {
			maxspeed_attr_value = atoi(v);
		}
		if (maxspeed_attr_value)
			flags[0] |= AF_SPEED_LIMIT;
		level=5;
	}

The function strstr() checks to see if "mph" is included in the maxspeed string. If so it converts the maxspeed string into an integer (i.e. the "mph" is ignored) and then multiplies by 1.609344 to convert to km/h.

In summary, it shouldn't matter if there is or isn't a space between the integer and the "mph" string in the maxspeed tag.

What *might* be happening is that there are some maxspeed tags which don't have the required "mph" suffix at all, so Navit assumes that these are km/h in the first place, giving you the incorrect number when in imperial mode. I've certainly found a few around my area of the UK, so it's possible.

Note: See TracTickets for help on using tickets.