-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathTagFix_Area.py
81 lines (69 loc) · 4.35 KB
/
TagFix_Area.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
#-*- coding: utf-8 -*-
###########################################################################
## ##
## Copyrights Frédéric Rodrigo 2014 ##
## ##
## 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
class TagFix_Area(Plugin):
def init(self, logger):
Plugin.init(self, logger)
self.area_yes_good = set(('aerialway', 'aeroway', 'amenity', 'barrier', 'highway', 'historic', 'leisure', 'man_made', 'military', 'piste:type', 'playground', 'power', 'public_transport', 'sport', 'tourism', 'traffic_calming', 'waterway'))
self.area_yes_default = set(('area:highway', 'boundary', 'building', 'building:part', 'cemetery', 'club', 'craft', 'geological', 'healthcare', 'health_facility:type', 'indoor', 'landuse', 'natural', 'office', 'place', 'shop'))
self.errors[32002] = self.def_class(item = 3200, level = 3, tags = ['tag', 'fix:chair'],
title = T_('Untagged area object'),
detail = T_('The object is missing any tag which defines what kind of feature it is. This is unexpected for something tagged with `area=yes`.'),
fix = self.merge_doc(
T_('Add a top level tag to state what this feature is. Considered acceptable `area=yes` features are:'),
{'en': ', '.join(map(lambda x: '`{}`'.format(x), sorted(self.area_yes_good)))} ),
trap = T_('It may be more appropriate to remove the object completely if it isn\'t useful.')
)
self.errors[32003] = self.def_class(item = 3200, level = 3, tags = ['tag', 'fix:chair'],
title = T_('Redundant area negation'),
detail = T_('This feature is already implicitly not an area.'),
fix = T_('Remove the `{0}` tag.', 'area=no')
)
def way(self, data, tags, nds):
err = []
if not "area" in tags:
return err
key_set = set(tags.keys())
if tags.get("area") == "yes":
if len(key_set & self.area_yes_default) == 0 and len(key_set & self.area_yes_good) == 0 and tags.get("railway") != "platform":
err.append({"class": 32002, "subclass": 1})
elif tags.get("area") == "no" and not "aeroway" in tags and not "building" in tags and not "landuse" in tags and not "leisure" in tags and not "natural" in tags:
err.append({"class": 32003, "subclass": 1})
return err
###########################################################################
from plugins.Plugin import TestPluginCommon
class Test(TestPluginCommon):
def test(self):
a = TagFix_Area(None)
a.init(None)
for t in [{"area":"yes", "railway": "rail"},
{"area":"no", "amenity": "bakery"},
]:
self.check_err(a.way(None, t, None), t)
for t in [{"area":"yes", "railway": "platform"},
{"area":"yes", "amenity": "bakery"},
{"area":"no", "building": "yes"},
]:
assert not a.way(None, t, None), t
# Unnecessary area=yes, dealt with by JOSM mapcss rules instead
for t in [{"area":"yes", "building": "yes"},
]:
assert not a.way(None, t, None), t