forked from osm-fr/osmose-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTagFix_Access.py
304 lines (282 loc) · 12 KB
/
TagFix_Access.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
# -*- coding: utf-8 -*-
###########################################################################
# ##
# Copyrights osmose project 2022 ##
# ##
# 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 modules.Stablehash import stablehash64
from plugins.Plugin import Plugin
class TagFix_Access(Plugin):
def init(self, logger):
Plugin.init(self, logger)
self.suffixesNode = ["", ":conditional"]
self.suffixesWay = []
for d in ["", ":forward", ":backward", ":both_ways"]:
self.suffixesWay.append(d)
self.suffixesWay.append(d + ":conditional")
# Note: emergency is excluded as it's also for hospital facilities
self.accessKeys = [
"4wd_only",
"access",
"agricultural",
"atv",
"bdouble",
"bicycle",
"boat",
"bus",
"canoe",
"caravan",
"carriage",
"coach",
"disabled",
"dog",
"foot",
"golf_cart",
"goods",
"hazmat",
"hazmat:water",
"hgv",
"horse",
"hov",
"inline_skates",
"light_rail",
"minibus",
"mofa",
"moped",
"motor_vehicle",
"motorboat",
"motorcar",
"motorcycle",
"motorhome",
"psv",
"share_taxi",
"ship",
"ski:nordic",
"ski",
"small_electric_vehicle",
"snowmobile",
"speed_pedelec",
"subway",
"swimming",
"tank",
"taxi",
"tourist_bus",
"trailer",
"train",
"tram",
"vehicle",
]
self.accessValuesGeneral = [
"yes",
"no",
"private",
"permissive",
"permit",
"destination",
"delivery",
"customers",
"designated",
"use_sidepath",
"agricultural",
"forestry",
"discouraged",
]
self.accessValuesSpecial = {
"bicycle": ["optional_sidepath", "dismount"],
"canoe": ["put_in", "portage"],
"dog": ["leashed", "unleashed", "outside"],
"horse": ["dismount"],
"mofa": ["dismount"],
"moped": ["dismount"],
"motorcycle": ["dismount"],
"speed_pedelec": ["dismount"],
}
self.errors[30404] = self.def_class(
item=3040,
level=3,
tags=["highway", "fix:chair"],
title=T_("Uncommon access value"),
detail=T_(
"""The value of the access tag is not one of the common access values: `{0}`.""",
", ".join(self.accessValuesGeneral),
),
resource="https://wiki.openstreetmap.org/wiki/Key:access",
trap=T_(
"""If there is no other tag (or combination of tags) that properly describes the access permissions, custom tags may be used."""
),
)
self.errors[30405] = self.def_class(
item=3040,
level=3,
tags=["highway", "fix:chair"],
title=T_("Transport mode in access value"),
detail=T_(
"""The value of the access tag is a transport mode (such as `access=foot`). Consider replacing it with a more specific tag listing the transport mode first, for example `access=no` + `foot=yes`."""
),
trap=T_(
"""Ensure that the access remains the same and does not conflict with other tags. This is especially likely if access tags are combined with directional and/or conditional access tags, or when transport modes are mixed with regular access values."""
),
resource="https://wiki.openstreetmap.org/wiki/Key:access",
)
def checkAccessKeys(self, tags, suffixes):
err = []
accessTags = {}
for accesskey in self.accessKeys:
for suffix in suffixes:
if accesskey + suffix in tags:
accessTags[accesskey + suffix] = {
"transportMode": accesskey,
"value": tags[accesskey + suffix],
"suffix": suffix,
}
for tag in accessTags:
values = accessTags[tag]["value"].split(";")
isConditional = ":conditional" in tag
for accessVal in set(values):
accessValue = accessVal
if isConditional:
if "@" in accessVal:
accessValue = accessValue.split("@")[0]
else:
continue # value was split on a ";" in the condition
accessValue = accessValue.strip()
transportMode = accessTags[tag]["transportMode"]
if (
transportMode in self.accessValuesSpecial
and accessValue in self.accessValuesSpecial[transportMode]
):
continue
if accessValue not in self.accessValuesGeneral:
if (
accessValue in self.accessKeys or accessValue == "emergency"
) and accessValue != transportMode:
propose = (
tag
+ " = ## + "
+ accessValue
+ accessTags[tag]["suffix"]
+ " = yes"
)
if len(values) > 1 or isConditional:
propose = propose.replace(
"###", "..."
) # i.e. access=bus;destination should become access=destination + bus=yes instead of access=no + bus=yes
else:
propose = propose.replace(
"###", "no"
) # assume 'no' holds for all other transport modes
if isConditional:
propose = (
propose + " @ (...)"
) # conditional may need to change
err.append(
{
"class": 30405,
"subclass": 0 + stablehash64(tag + "|" + accessVal),
"text": T_(
'Access value "{0}" for key "{1}" is a transport mode. Consider using "{2}" instead',
accessValue,
tag,
propose,
),
}
)
else:
err.append(
{
"class": 30404,
"subclass": 0 + stablehash64(tag + "|" + accessVal),
"text": T_(
'Unknown access value "{0}" for key "{1}"',
accessValue,
tag,
),
}
)
if err != []:
return err
def way(self, data, tags, nds):
return self.checkAccessKeys(tags, self.suffixesWay)
def node(self, data, tags):
return self.checkAccessKeys(tags, self.suffixesNode)
def relation(self, data, tags, members):
pass
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
a = TagFix_Access(None)
a.init(None)
# Valid nodes and ways
for t in [
{"amenity": "parking", "vehicle": "no"},
{"amenity": "parking", "vehicle:conditional": "no @ wet"},
{"access": "agricultural", "agricultural": "designated"},
{"agricultural": "agricultural"},
{
"highway": "residential",
"hgv:conditional": "no @ (Mo-Fr 00:00-12:00;Sa 0:00-19:00); yes @ (Mo-Fr 12:00-24:00;Sa 19:00-24:00)",
},
{"dog": "leashed", "bicycle": "dismount"},
]:
assert not a.way(None, t, None), a.way(None, t, None)
assert not a.node(None, t), a.node(None, t)
# Valid ways with directions
for t in [
{"highway": "residential", "vehicle:forward": "customers"},
{
"highway": "residential",
"vehicle:backward:conditional": "customers @ (wet); destination @ (snow)",
},
{"highway": "residential", "vehicle:both_ways": "customers;destination"},
{"highway": "residential", "vehicle:both_ways": "customers; destination"},
{"highway": "residential", "bicycle:forward:conditional": "dismount@wet"},
]:
assert not a.way(None, t, None), a.way(None, t, None)
# Invalid nodes and ways
for t in [
{"amenity": "parking", "vehicle": "nope"},
{"amenity": "parking", "vehicle:conditional": "nope @ wet"},
{
"highway": "residential",
"canoe:conditional": "no @ (Mo-Fr 06:00-11:00;Sa 03:30-19:00); nope @ (snow)",
},
{
"highway": "residential",
"tank:conditional": "dismount @ (Mo-Fr 06:00-11:00;Sa 03:30-19:00); no @ (snow)",
},
{"bicycle": "leashed"},
]:
assert a.way(None, t, None), a.way(None, t, None)
assert a.node(None, t), a.node(None, t)
# Invalid ways with directions
for t in [
{"highway": "residential", "vehicle:forward": "nope"},
{"highway": "residential", "vehicle:both_ways:conditional": "nope @ wet"},
{"highway": "residential", "horse:backward": "customers;nope"},
{"highway": "residential", "horse:backward": "nope; customers"},
]:
assert a.way(None, t, None), a.way(None, t, None)
# Transport mode as tag value
for t in [
{"highway": "residential", "access": "foot"},
{"highway": "residential", "access:conditional": "foot @ yes"},
{"highway": "residential", "access:forward": "bus;foot"},
{"highway": "residential", "access": "bus; destination"},
{"highway": "residential", "access": "emergency"},
]:
assert a.way(None, t, None), a.way(None, t, None)