forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagFix_MultipleTag_FR.py
185 lines (162 loc) · 10.1 KB
/
TagFix_MultipleTag_FR.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2011 ##
## ##
## 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 modules.OsmoseTranslation import T_
from plugins.Plugin import Plugin
import re
class TagFix_MultipleTag_FR(Plugin):
only_for = ["FR", "NC"]
def init(self, logger):
Plugin.init(self, logger)
self.errors[30321] = self.def_class(item = 3032, level = 1, tags = ['tag', 'fix:chair'],
title = T_('Watch multiple tags'))
self.errors[50201] = self.def_class(item = 5020, level = 2, tags = ['tag', 'name', 'fix:chair'],
title = T_('Improve name from the land registry'),
detail = T_(
'''The name was copied from the land register (cadastre), but it is not
written in a form actually used.'''),
fix = T_(
'''Eg. replace "Chemin Rural dit des Vignes" by "Chemin des Vignes".'''))
self.errors[30324] = self.def_class(item = 3032, level = 2, tags = ['highway', 'maxspeed', 'fix:survey'],
title = T_('incoherent maxspeed'))
self.errors[30325] = self.def_class(item = 3032, level = 2, tags = ['highway', 'ref', 'fix:chair'],
title = T_('Invalid reference'))
self.errors[206013] = self.def_class(item = 2060, level = 3, tags = ['addr', 'fix:chair'],
title = T_('FANTOIR object type not match OSM feature'))
self.school = {
u"elementaire": u"élémentaire",
u"maternelle": u"maternelle",
u"primaire": u"primaire",
u"college": u"collège",
u"lycee": u"lycée",
u"secondaire": u"secondaire",
}
country = self.father.config.options.get("country")
if country and country.startswith("NC"):
self.Ref = re.compile(r"^(RT|RP|VU|VE|VDE|RPN|RM|CR)[-\s]?[0-9]?", re.IGNORECASE)
else: # "FR"
self.Ref = re.compile(r"^([ANDMCVR]|RN|RD|VC|CR|CE|EV|V)[-\s]?[0-9]?", re.IGNORECASE)
def node(self, data, tags, is_node = True):
err = []
if "school:FR" in tags and "amenity" not in tags:
err.append({"class": 30321, "subclass": 5, "text": T_(u"Need tag amenity=nursery|kindergarten|school besides on school:FR")})
if "name" in tags and tags.get("amenity") == "school" and "school:FR" not in tags:
canonicalSchool = self.ToolsStripAccents(tags['name']).lower()
matches = list(filter(lambda kv: kv[0] in canonicalSchool, self.school.keys()))
if len(matches) == 1:
err.append({"class": 30321, "subclass": 6, "text": T_(u"Add school:FR tag"), "fix": {"+": {"school:FR": self.school[matches[0]]}} })
elif len(matches) > 1:
err.append({"class": 30321, "subclass": 6, "text": T_(u"Add school:FR tag") })
if not "addr:housenumber" in tags and "ref:FR:FANTOIR" in tags and len(tags["ref:FR:FANTOIR"]) == 10:
fantoir_key = tags["ref:FR:FANTOIR"][5]
if fantoir_key.isdigit():
if is_node and "highway" not in tags:
err.append({"class": 206013, "subclass": 1, "text": T_(u"FANTOIR numeric type is for ways")})
#elif fantoir_key == "A":
elif fantoir_key >= "B" and fantoir_key <= "W":
if tags.get("place") not in ("locality", "hamlet", "isolated_dwelling", "neighbourhood", "islet") and tags.get("railway") != "station" and tags.get("leisure") not in ("park", "garden"):
err.append({"class": 206013, "subclass": 1, "text": T_(u"FANTOIR B to W type is for locality, hamlet, isolated_dwelling, islet or neighbourhood")})
return err
def way(self, data, tags, nds):
err = self.node(data, tags, is_node = False)
if "name" in tags and tags["name"].startswith("Chemin Rural dit "):
err.append({"class": 50201, "subclass": 0, "fix": {"~": {"name": tags["name"].replace("Chemin Rural dit ", "Chemin ")}}})
if "highway" in tags:
if tags["highway"] == "living_street" and tags.get("zone:maxspeed") not in (None, "FR:20"):
err.append({"class": 30324, "subclass": 0, "text": T_(u"A living_street in France is a Zone 20")})
elif tags.get("zone:maxspeed") == "FR:20" and tags["highway"] != "living_street":
err.append({"class": 30324, "subclass": 1, "text": T_(u"A Zone 20 in France is a living_street")})
elif "zone:maxspeed" in tags and "maxspeed" in tags:
if tags["zone:maxspeed"] == "FR:20" and tags["maxspeed"] != "20":
err.append({"class": 30324, "subclass": 3, "text": T_(u"A Zone 20 is limited to 20 km/h")})
elif tags["zone:maxspeed"] == "FR:30" and tags["maxspeed"] != "30":
err.append({"class": 30324, "subclass": 4, "text": T_(u"A zone 30 is limited to 30 km/h")})
if (tags.get("highway") in ("motorway", "trunk", "primary", "secondary", "tertiary", "unclassified", "residential", "living_street", "path", "track", "service", "footway", "pedestrian", "cycleway", "road", "bridleway") and
"ref" in tags and not self.Ref.match(tags["ref"])):
err.append({"class": 30325, "subclass": 4, "text": {"en": tags["ref"]}})
return err
def relation(self, data, tags, members):
return self.way(data, tags, None)
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test_FR(self):
a = TagFix_MultipleTag_FR(None)
class _config:
options = {"country": "FR"}
class father:
config = _config()
a.father = father()
a.init(None)
for t in [{"amenity":"school", "name":u"École maternelle Clos Montesquieu"},
{"amenity":"school", "name":u"École élémentaire"},
{"name":u"Chemin Rural dit de la Borne Trouée"},
{"highway":"living_street", "zone:maxspeed": "30"},
{"highway":"primary", "zone:maxspeed": "FR:20"},
{"highway":"primary", "zone:maxspeed": "FR:30", "maxspeed": "70"},
{"highway":"living_street", "zone:maxspeed": "FR:20", "maxspeed": "30"},
{"highway":"trunk", "ref": "3"},
{"ref:FR:FANTOIR":"90123D123D", "highway": "residential"},
]:
self.check_err(a.way(None, t, None), t)
self.check_err(a.relation(None, t, None), t)
for t in [{"highway":"trunk", "ref": u"D\u20073"},
{"highway":"primary", "zone:maxspeed": "FR:50"},
{"highway":"primary", "zone:maxspeed": "FR:30", "maxspeed": "30"},
{"highway":"living_street"},
{"highway":"living_street", "zone:maxspeed": "FR:20", "maxspeed": "20"},
{"ref:FR:FANTOIR":"901230123D", "highway": "residential"},
{"ref:FR:FANTOIR":"90123D123D", "place": "hamlet"},
{"ref:FR:FANTOIR":"330633955T", "type": "associatedStreet"},
{"ref:FR:FANTOIR":"75116S566F", "railway": "station"},
{"ref:FR:FANTOIR":"75116S566F", "leisure": "park"},
{"ref:FR:FANTOIR":"75116S566F", "leisure": "garden"},
{"ref:FR:FANTOIR":"751084356J", "leisure": "garden"},
]:
assert not a.way(None, t, None), t
def test_NC(self):
a = TagFix_MultipleTag_FR(None)
class _config:
options = {"country": "NC"}
class father:
config = _config()
a.father = father()
a.init(None)
for t in [{"amenity":"school", "name":u"École maternelle Clos Montesquieu"},
{"amenity":"school", "name":u"École élémentaire"},
{"name":u"Chemin Rural dit de la Borne Trouée"},
{"highway":"living_street", "zone:maxspeed": "30"},
{"highway":"primary", "zone:maxspeed": "FR:20"},
{"highway":"primary", "zone:maxspeed": "FR:30", "maxspeed": "70"},
{"highway":"living_street", "zone:maxspeed": "FR:20", "maxspeed": "30"},
{"highway":"trunk", "ref": "3"},
{"ref:FR:FANTOIR":"90123D123D", "highway": "residential"},
{"highway":"trunk", "ref": u"D\u20073"},
{"school:FR":"maternelle", "ref": u"1989898"},
]:
self.check_err(a.way(None, t, None), t)
for t in [{"highway":"trunk", "ref": u"RPN 73"},
{"highway":"primary", "zone:maxspeed": "FR:50"},
{"highway":"primary", "zone:maxspeed": "FR:30", "maxspeed": "30"},
{"highway":"living_street"},
{"highway":"living_street", "zone:maxspeed": "FR:20", "maxspeed": "20"},
{"ref:FR:FANTOIR":"90123D123D", "place": "hamlet"},
{"ref:FR:FANTOIR":"330633955T", "type": "associatedStreet"},
]:
assert not a.way(None, t, None), t