forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagFix_Maxspeed.py
104 lines (87 loc) · 4.14 KB
/
TagFix_Maxspeed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2017 ##
## ##
## This program is free software: you can redistribute it and/or modify ##
## it under the terms of the GNU General Public License as published by ##
## the Free Software Foundation, either version 3 of the License, or ##
## (at your option) any later version. ##
## ##
## This program is distributed in the hope that it will be useful, ##
## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
## GNU General Public License for more details. ##
## ##
## You should have received a copy of the GNU General Public License ##
## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
## ##
###########################################################################
from plugins.Plugin import Plugin
class TagFix_Maxspeed(Plugin):
maxspeed_table_default = {
'urban': ['50'],
'rural': ['90'],
'trunk': ['110'],
'motorway': ['130'],
}
# List only exceptions
maxspeed_table = {
'at:rural': ['100'],
'at:trunk': ['100'],
'be:motorway': ['120'],
'be-vlg:rural': ['70'],
'by:urban': ['60'],
'by:motorway': ['110'],
'ch:rural': ['80'],
'ch:trunk': ['100'],
'ch:motorway': ['120'],
'cz:trunk': ['80', '130'],
'cz:motorway': ['80', '130'],
'de:living_street': ['walk'],
'de:rural': ['100'],
'de:motorway': [],
'dk:rural': ['80'],
'fr:rural': ['80', '90'],
'gb:nsl_single': ['60 mph'],
'gb:nsl_dual': ['70 mph'],
'gb:motorway': ['70 mph'],
'nl:rural': ['80'],
'nl:trunk': ['100'],
'no:rural': ['80'],
'no:motorway': ['110'],
'pl:rural': ['90', '100'],
'pl:trunk': ['100', '120'],
'pl:motorway': ['140'],
'ro:trunk': ['100'],
'ru:living_street': ['20'],
'ru:urban': ['60'],
'ru:motorway': ['110'],
'uk:nsl_single': ['60 mph'],
'uk:nsl_dual': ['70 mph'],
'uk:motorway': ['70 mph'],
'za:urban': ['60'],
'za:rural': ['100'],
}
def init(self, logger):
Plugin.init(self, logger)
self.errors[303241] = self.def_class(item = 3032, level = 1, tags = ['tag', 'highway'],
title = T_('Discordant maxspeed and source:maxspeed'))
def way(self, data, tags, nds):
if not tags.get('highway') or not tags.get('maxspeed') or not tags['maxspeed'][0] in "0123456789" or not tags.get('source:maxspeed') or not ':' in tags['source:maxspeed']:
return
source_maxspeed = self.maxspeed_table.get(tags['source:maxspeed'].lower()) or self.maxspeed_table_default.get(tags['source:maxspeed'].split(':')[1])
if not source_maxspeed or len(source_maxspeed) == 0:
return
if tags['maxspeed'] not in source_maxspeed:
return [{'class': 303241, 'subclass': 0, 'text': T_f(u'Discordant {0} and {1}', tags['maxspeed'], tags['source:maxspeed'])}]
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
a = TagFix_Maxspeed(None)
a.init(None)
assert not a.way(None, {'name': 'foo'}, None)
assert not a.way(None, {'highway': 'primary'}, None)
assert not a.way(None, {'highway': 'primary', 'maxspeed': '50', 'source:maxspeed': 'FR:urban'}, None)
self.check_err(a.way(None, {'highway': 'primary', 'maxspeed': '30', 'source:maxspeed': 'FR:urban'}, None))