Skip to content

Commit 9685fd7

Browse files
committed
Generate mapcss python code
1 parent 7f54e07 commit 9685fd7

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

plugins/Structural.py

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
#-*- coding: utf-8 -*-
2+
import modules.mapcss_lib as mapcss
3+
import regex as re # noqa
4+
5+
from plugins.Plugin import with_options # noqa
6+
from plugins.PluginMapCSS import PluginMapCSS
7+
8+
9+
class Structural(PluginMapCSS):
10+
# ------------------------------- IMPORTANT -------------------------------
11+
# This file is generated automatically and should not be modified directly.
12+
# Instead, modify the source mapcss file and regenerate this Python script.
13+
# -------------------------------------------------------------------------
14+
15+
16+
17+
def init(self, logger):
18+
super().init(logger)
19+
tags = capture_tags = {} # noqa
20+
self.errors[4] = self.def_class(item = 1170, level = 1, tags = mapcss.list_('geom', 'fix:imagery', 'fix:chair'), title = mapcss.tr('Should be polygon, part of multipolygon or not having area tag'), detail = mapcss.tr('A way has a tag that suggests it is an area, but the way is not closed.'), fix = mapcss.tr('Make sure the first and last node of the way are connected, such that it forms a closed way. If the way is not an area, add `area=no` or correct the tags.'), trap = mapcss.tr('Use a multipolygon relation instead of a way if a closed way cannot be formed to represent the area. In this case, remove the area-related tags from the way.'), example = {"en": '![](https://wiki.openstreetmap.org/w/images/c/cc/Osmose-eg-error-1100.png)'})
21+
22+
self.re_2d687399 = re.compile(r'^(barefoot|bathing_place|slipway|track)$')
23+
self.re_342e1a01 = re.compile(r'^(yes|designated|permissive)$')
24+
self.re_3977796a = re.compile(r'^(bench|bicycle_parking|hitching_post|ticket_validator|weighbridge)$')
25+
self.re_3ad8d56a = re.compile(r'^(bare_rock|bay|beach|fell|glacier|grassland|heath|hot_spring|moor|mud|rock|sand|scree|scrub|shingle|sinkhole|stone|water|wetland|wood)$')
26+
self.re_3dd10aca = re.compile(r'^(obstacle_course|road|trench)$')
27+
self.re_50f04966 = re.compile(r'^(artwork|attraction|yes)$')
28+
self.re_7d3259ea = re.compile(r'^(boatyard|dock|fuel|riverbank)$')
29+
30+
31+
def way(self, data, tags, nds):
32+
capture_tags = {}
33+
keys = tags.keys()
34+
err = []
35+
36+
37+
# way[amenity]!:closed[!area][amenity!~/^(bench|bicycle_parking|hitching_post|ticket_validator|weighbridge)$/]
38+
# way[area]!:closed[area!=no]
39+
# way[area:highway]!:closed
40+
# way[building:part]!:closed[!area]
41+
# way[building]!:closed
42+
# way[club]!:closed[!area]
43+
# way[craft]!:closed[!area]
44+
# way[emergency]!:closed[!area][emergency!~/^(yes|designated|permissive)$/][!highway]
45+
# way[healthcare]!:closed[!area]
46+
# way[landcover]!:closed
47+
# way[landuse]!:closed
48+
# way[leisure]!:closed[!area][leisure!~/^(barefoot|bathing_place|slipway|track)$/]
49+
# way[military]!:closed[!area][military!~/^(obstacle_course|road|trench)$/][!highway]
50+
# way[natural]!:closed[!area][natural=~/^(bare_rock|bay|beach|fell|glacier|grassland|heath|hot_spring|moor|mud|rock|sand|scree|scrub|shingle|sinkhole|stone|water|wetland|wood)$/][bay!=fjord]
51+
# way[office]!:closed[!area]
52+
# way[place]!:closed
53+
# way[shop]!:closed[!area]
54+
# way[tourism]!:closed[!area][tourism!~/^(artwork|attraction|yes)$/]
55+
# way[waterway]!:closed[!area][waterway=~/^(boatyard|dock|fuel|riverbank)$/]
56+
if ('amenity' in keys) or ('area' in keys) or ('area:highway' in keys) or ('building' in keys) or ('building:part' in keys) or ('club' in keys) or ('craft' in keys) or ('emergency' in keys) or ('healthcare' in keys) or ('landcover' in keys) or ('landuse' in keys) or ('leisure' in keys) or ('military' in keys) or ('natural' in keys) or ('office' in keys) or ('place' in keys) or ('shop' in keys) or ('tourism' in keys) or ('waterway' in keys):
57+
match = False
58+
if not match:
59+
capture_tags = {}
60+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'amenity')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 3, self.re_3977796a, '^(bench|bicycle_parking|hitching_post|ticket_validator|weighbridge)$'), mapcss._tag_capture(capture_tags, 3, tags, 'amenity'))) and (nds[0] != nds[-1]))
61+
except mapcss.RuleAbort: pass
62+
if not match:
63+
capture_tags = {}
64+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'area')) and (mapcss._tag_capture(capture_tags, 2, tags, 'area') != mapcss._value_const_capture(capture_tags, 2, 'no', 'no')) and (nds[0] != nds[-1]))
65+
except mapcss.RuleAbort: pass
66+
if not match:
67+
capture_tags = {}
68+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'area:highway')) and (nds[0] != nds[-1]))
69+
except mapcss.RuleAbort: pass
70+
if not match:
71+
capture_tags = {}
72+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'building:part')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
73+
except mapcss.RuleAbort: pass
74+
if not match:
75+
capture_tags = {}
76+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'building')) and (nds[0] != nds[-1]))
77+
except mapcss.RuleAbort: pass
78+
if not match:
79+
capture_tags = {}
80+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'club')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
81+
except mapcss.RuleAbort: pass
82+
if not match:
83+
capture_tags = {}
84+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'craft')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
85+
except mapcss.RuleAbort: pass
86+
if not match:
87+
capture_tags = {}
88+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'emergency')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 3, self.re_342e1a01, '^(yes|designated|permissive)$'), mapcss._tag_capture(capture_tags, 3, tags, 'emergency'))) and (not mapcss._tag_capture(capture_tags, 4, tags, 'highway')) and (nds[0] != nds[-1]))
89+
except mapcss.RuleAbort: pass
90+
if not match:
91+
capture_tags = {}
92+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'healthcare')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
93+
except mapcss.RuleAbort: pass
94+
if not match:
95+
capture_tags = {}
96+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'landcover')) and (nds[0] != nds[-1]))
97+
except mapcss.RuleAbort: pass
98+
if not match:
99+
capture_tags = {}
100+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'landuse')) and (nds[0] != nds[-1]))
101+
except mapcss.RuleAbort: pass
102+
if not match:
103+
capture_tags = {}
104+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'leisure')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 3, self.re_2d687399, '^(barefoot|bathing_place|slipway|track)$'), mapcss._tag_capture(capture_tags, 3, tags, 'leisure'))) and (nds[0] != nds[-1]))
105+
except mapcss.RuleAbort: pass
106+
if not match:
107+
capture_tags = {}
108+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'military')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 3, self.re_3dd10aca, '^(obstacle_course|road|trench)$'), mapcss._tag_capture(capture_tags, 3, tags, 'military'))) and (not mapcss._tag_capture(capture_tags, 4, tags, 'highway')) and (nds[0] != nds[-1]))
109+
except mapcss.RuleAbort: pass
110+
if not match:
111+
capture_tags = {}
112+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'natural')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (mapcss.regexp_test(mapcss._value_capture(capture_tags, 3, self.re_3ad8d56a), mapcss._tag_capture(capture_tags, 3, tags, 'natural'))) and (mapcss._tag_capture(capture_tags, 4, tags, 'bay') != mapcss._value_const_capture(capture_tags, 4, 'fjord', 'fjord')) and (nds[0] != nds[-1]))
113+
except mapcss.RuleAbort: pass
114+
if not match:
115+
capture_tags = {}
116+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'office')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
117+
except mapcss.RuleAbort: pass
118+
if not match:
119+
capture_tags = {}
120+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'place')) and (nds[0] != nds[-1]))
121+
except mapcss.RuleAbort: pass
122+
if not match:
123+
capture_tags = {}
124+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'shop')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (nds[0] != nds[-1]))
125+
except mapcss.RuleAbort: pass
126+
if not match:
127+
capture_tags = {}
128+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'tourism')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (not mapcss.regexp_test(mapcss._value_const_capture(capture_tags, 3, self.re_50f04966, '^(artwork|attraction|yes)$'), mapcss._tag_capture(capture_tags, 3, tags, 'tourism'))) and (nds[0] != nds[-1]))
129+
except mapcss.RuleAbort: pass
130+
if not match:
131+
capture_tags = {}
132+
try: match = ((mapcss._tag_capture(capture_tags, 0, tags, 'waterway')) and (not mapcss._tag_capture(capture_tags, 2, tags, 'area')) and (mapcss.regexp_test(mapcss._value_capture(capture_tags, 3, self.re_7d3259ea), mapcss._tag_capture(capture_tags, 3, tags, 'waterway'))) and (nds[0] != nds[-1]))
133+
except mapcss.RuleAbort: pass
134+
if match:
135+
# group:tr("Should be polygon, part of multipolygon or not having area tag")
136+
# -osmoseTags:list("geom","fix:imagery","fix:chair")
137+
# -osmoseDetail:tr("A way has a tag that suggests it is an area, but the way is not closed.")
138+
# -osmoseFix:tr("Make sure the first and last node of the way are connected, such that it forms a closed way. If the way is not an area, add `area=no` or correct the tags.")
139+
# -osmoseTrap:tr("Use a multipolygon relation instead of a way if a closed way cannot be formed to represent the area. In this case, remove the area-related tags from the way.")
140+
# -osmoseExample:"![](https://wiki.openstreetmap.org/w/images/c/cc/Osmose-eg-error-1100.png)"
141+
# -osmoseItemClassLevel:"1170/4/1"
142+
# throwError:tr("Unclosed way with {0}","{0.tag}")
143+
# assertNoMatch:"way emergency=designated"
144+
# assertNoMatch:"way oneway=no"
145+
# assertNoMatch:"way tourism=xyz area=no"
146+
err.append({'class': 4, 'subclass': 0, 'text': mapcss.tr('Unclosed way with {0}', mapcss._tag_uncapture(capture_tags, '{0.tag}'))})
147+
148+
return err
149+
150+
151+
from plugins.PluginMapCSS import TestPluginMapcss
152+
153+
154+
class Test(TestPluginMapcss):
155+
def test(self):
156+
n = Structural(None)
157+
class _config:
158+
options = {"country": None, "language": None}
159+
class father:
160+
config = _config()
161+
n.father = father()
162+
n.init(None)
163+
data = {'id': 0, 'lat': 0, 'lon': 0}
164+
165+
self.check_not_err(n.way(data, {'emergency': 'designated'}, [0]), expected={'class': 4, 'subclass': 0})
166+
self.check_not_err(n.way(data, {'oneway': 'no'}, [0]), expected={'class': 4, 'subclass': 0})
167+
self.check_not_err(n.way(data, {'area': 'no', 'tourism': 'xyz'}, [0]), expected={'class': 4, 'subclass': 0})

0 commit comments

Comments
 (0)