source: josm/trunk/data/validator/numeric.mapcss@ 13102

Last change on this file since 13102 was 13035, checked in by Klumbumbus, 6 years ago

fix #15479 - Include meters as a valid unit for distance (patch by naoliv)

  • Property svn:eol-style set to native
File size: 11.4 KB
Line 
1/* measurement values and units warnings (ticket #8687) */
2
3*[/^[0-9]+$/] {
4 throwWarning: tr("numerical key");
5 assertMatch: "way 123=foo";
6 assertNoMatch: "way ref.1=foo";
7}
8
9*[layer =~ /^\+\d/] {
10 throwWarning: tr("{0} value with + sign", "{0.key}");
11 fixAdd: concat("layer=", replace(tag("layer"), "+", ""));
12 assertMatch: "node layer=+1";
13 assertNoMatch: "node layer=1";
14 assertNoMatch: "node layer=-1";
15 assertNoMatch: "node layer=+foo";
16}
17
18*[layer][layer !~ /^0$|^(-|\+)?[1-5]$/] {
19 throwWarning: tr("{0} should be an integer value between -5 and 5", "{0.key}");
20 assertMatch: "node layer=-50";
21 assertMatch: "node layer=6";
22 assertMatch: "node layer=+10";
23 assertMatch: "node layer=0.5";
24 assertMatch: "node layer=0;1";
25 assertNoMatch: "node layer=-5";
26 assertNoMatch: "node layer=0";
27 assertNoMatch: "node layer=2";
28 assertNoMatch: "node layer=+5"; /* this is an invalid value, but this case is already covered by the previous rule */
29}
30
31*[building:levels][building:levels !~ /^(([0-9]|[1-9][0-9]*)(\.5)?)$/],
32*[level][level !~ /^((((-*[1-9]|[0-9])|-*[1-9][0-9]*)(\.5)?)|-0\.5)(;((((-*[1-9]|[0-9])|-*[1-9][0-9]*)(\.5)?)|-0\.5))*$/] { /* all numbers from -∞ to ∞ in 0.5 steps, optional multiple values seperated by a ; */
33 throwWarning: tr("{0} should have numbers only with optional .5 increments", "{0.key}");
34 assertMatch: "node level=one";
35 assertMatch: "node level=01";
36 assertMatch: "node level=-03";
37 assertMatch: "node level=-01.5";
38 assertMatch: "node level=2.3";
39 assertMatch: "node level=-0";
40 assertNoMatch: "node level=0";
41 assertNoMatch: "node level=1";
42 assertNoMatch: "node level=-1";
43 assertNoMatch: "node level=-0.5";
44 assertNoMatch: "node level=1.5";
45 assertNoMatch: "node level=12";
46 assertNoMatch: "node level=0;1";
47 assertNoMatch: "node level=1;1.5";
48 assertNoMatch: "node level=1;0.5";
49 assertNoMatch: "node level=0;-0.5";
50 assertNoMatch: "node level=-0.5;0";
51 assertNoMatch: "node level=-1;-0.5";
52 assertNoMatch: "node building:levels=1.5";
53 assertMatch: "node building:levels=-1";
54 assertNoMatch: "node building:levels=0"; /* valid because there can be building:levels:underground > 0 or roof:levels > 0 */
55}
56
57*[height][height !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([1-9][0-9]*\'((10|11|[0-9])((\.[0-9]+)?)\")?))$/] {
58 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "height");
59 assertMatch: "node height=medium";
60 assertMatch: "node height=-5";
61 assertNoMatch: "node height=2 m";
62 assertNoMatch: "node height=5";
63 assertNoMatch: "node height=7.8";
64 assertNoMatch: "node height=20 ft";
65 assertNoMatch: "node height=22'";
66}
67
68*[maxheight][maxheight !~ /^(([1-9][0-9]*(\.[0-9]+)?( (m|ft))?)|([0-9]+\'(([0-9]|10|11)(\.[0-9]*)?\")?)|none|default)$/] {
69 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "maxheight");
70 assertMatch: "node maxheight=something";
71 assertMatch: "node maxheight=-5";
72 assertMatch: "node maxheight=0";
73 assertNoMatch: "node maxheight=4";
74 assertNoMatch: "node maxheight=3.5";
75 assertNoMatch: "node maxheight=2 m";
76 assertNoMatch: "node maxheight=14 ft";
77 assertNoMatch: "node maxheight=10'";
78 assertNoMatch: "node maxheight=16'3\"";
79}
80
81way[width][width !~ /^(([0-9]+\.?[0-9]*( [a-z]+)?)|([0-9]+\'([0-9]+\.?[0-9]*\")?))$/] {
82 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "width");
83 assertMatch: "way width=something";
84 assertMatch: "way width=-5";
85 assertNoMatch: "way width=3";
86 assertNoMatch: "way width=0.5";
87 assertNoMatch: "way width=1 m";
88 assertNoMatch: "way width=10 ft";
89 assertNoMatch: "way width=1'";
90 assertNoMatch: "way width=10'5\"";
91}
92
93*[maxwidth][maxwidth !~ /^(([0-9]+\.?[0-9]*( (m|ft))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
94 throwWarning: tr("{0}: meters is default; period is separator; if units, put space then unit", "maxwidth");
95 assertMatch: "way maxwidth=something";
96 assertMatch: "way maxwidth=-5";
97 assertNoMatch: "way maxwidth=2";
98 assertNoMatch: "way maxwidth=6'6\"";
99 assertNoMatch: "way maxwidth=2.5";
100 assertNoMatch: "way maxwidth=7 ft";
101}
102*[maxweight][maxweight !~ /^(([0-9]+\.?[0-9]*( (t|kg|lbs))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
103 throwWarning: tr("{0}: tonne is default; period is separator; if units, put space then unit", "maxweight");
104 assertMatch: "way maxweight=something";
105 assertMatch: "way maxweight=-5";
106 assertNoMatch: "way maxweight=2";
107 assertNoMatch: "way maxweight=6'6\"";
108 assertNoMatch: "way maxweight=2.5";
109 assertNoMatch: "way maxweight=7 kg";
110}
111way[maxspeed][maxspeed !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
112way[maxspeed:forward][maxspeed:forward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/],
113way[maxspeed:backward][maxspeed:backward !~ /^(signals|none|unposted|variable|walk|[1-9][0-9]*( [a-z]+)?|[A-Z][A-Z]:(urban|rural|living_street|motorway))$/] {
114 throwWarning: tr("unusual {0} format", "maxspeed");
115 assertMatch: "way maxspeed=something";
116 assertMatch: "way maxspeed=-50";
117 assertMatch: "way maxspeed=0";
118 assertNoMatch: "way maxspeed=50";
119 assertNoMatch: "way maxspeed=30 mph";
120 assertNoMatch: "way maxspeed=RO:urban";
121 assertNoMatch: "way maxspeed=RU:rural";
122 assertNoMatch: "way maxspeed=RU:living_street";
123 assertNoMatch: "way maxspeed=DE:motorway";
124 assertNoMatch: "way maxspeed=signals";
125 assertNoMatch: "way maxspeed=none";
126 assertNoMatch: "way maxspeed=variable";
127}
128
129*[distance][distance !~ /^(([0-9]+\.?[0-9]*( (m|km|mi|nmi))?)|([0-9]+\'[0-9]+\.?[0-9]*\"))$/] {
130 throwWarning: tr("{0}: kilometers is default; period is separator; if units, put space then unit", "distance");
131 assertMatch: "way distance=something";
132 assertMatch: "way distance=-5";
133 assertNoMatch: "way distance=2";
134 assertNoMatch: "way distance=2.5";
135 assertNoMatch: "way distance=7 mi";
136}
137
138way[voltage][voltage =~ /(.*[A-Za-z].*)|.*,.*|.*( ).*/] {
139 throwWarning: tr("voltage should be in volts with no units/delimiter/spaces");
140 assertMatch: "way voltage=medium";
141 assertNoMatch: "way voltage=15000";
142}
143
144/* some users are using frequency for other purposes (not electromagnetic)
145 with the values 'perennial' and 'intermittent'; the vast majority are 0, 16.7, 50 and 60 */
146way[frequency][frequency !~ /^(0|[1-9][0-9]*(\.[0-9]+)?)( (kHz|MHz|GHz|THz))?$/] {
147 throwWarning: tr("unusual {0} specification", "frequency");
148 assertMatch: "way frequency=something";
149 assertNoMatch: "way frequency=0"; /* DC */
150 assertNoMatch: "way frequency=16.7";
151 assertNoMatch: "way frequency=50";
152 assertNoMatch: "way frequency=680 kHz";
153 assertNoMatch: "way frequency=123.5 MHz";
154}
155
156way[gauge][gauge !~ /^([1-9][0-9]{1,3}(;[1-9][0-9]{1,3})*|broad|standard|narrow)$/] {
157 throwWarning: tr("unusual train track gauge; use mm with no separator");
158 assertMatch: "way gauge=something";
159 assertNoMatch: "way gauge=1435";
160 assertNoMatch: "way gauge=1000;1435";
161 assertNoMatch: "way gauge=standard";
162 assertNoMatch: "way gauge=narrow";
163}
164
165/* the numbers for percentage and degrees include could probably be bracketed a bit more precisely */
166way[incline][incline !~ /^(up|down|-?([0-9]+?(\.[1-9]%)?|100)[%°]?)$/] {
167 throwWarning: tr("unusual incline; use percentages/degrees or up/down");
168 assertMatch: "way incline=extreme";
169 assertNoMatch: "way incline=up";
170 assertNoMatch: "way incline=down";
171 assertNoMatch: "way incline=10%";
172 assertNoMatch: "way incline=-5%";
173 assertNoMatch: "way incline=10°";
174}
175
176/* see ticket #9631 */
177*[population][population !~ /^[0-9]+$/ ] {
178 throwWarning: tr("{0} must be a numeric value", "{0.key}");
179}
180
181/* must be an integer positive number only and not 0, see #10837 (lanes), #11055 (screen) */
182way[lanes][lanes !~ /^[1-9]([0-9]*)$/][highway],
183way["lanes:backward"]["lanes:backward" !~ /^[1-9]([0-9]*)$/][highway],
184way["lanes:forward"]["lanes:forward" !~ /^[1-9]([0-9]*)$/][highway],
185*[screen][screen !~ /^[1-9]([0-9]*)$/][amenity=cinema] {
186 throwError: tr("{0} must be a positive integer number", "{0.key}");
187 assertMatch: "way highway=residential lanes=-1";
188 assertMatch: "way highway=residential lanes=5.5";
189 assertMatch: "way highway=residential lanes=1;2";
190 assertMatch: "way highway=residential lanes:forward=-1";
191 assertMatch: "way highway=residential lanes:backward=-1";
192 assertNoMatch: "way highway=residential lanes=1";
193 assertMatch: "node amenity=cinema screen=led";
194 assertNoMatch: "node amenity=cinema screen=8";
195}
196*[admin_level][admin_level !~ /^(1|2|3|4|5|6|7|8|9|10|11|12)$/] {
197 throwWarning: tr("unusual value of {0}", "{1.key}");
198 assertMatch: "node admin_level=0";
199 assertMatch: "node admin_level=-1";
200 assertMatch: "node admin_level=13";
201 assertNoMatch: "node admin_level=5";
202}
203
204/* #14989 */
205*[direction][direction<0],
206*[direction][direction>=360] {
207 throwWarning: tr("unusual value of {0}", "{1.key}");
208 assertMatch: "node direction=-10";
209 assertMatch: "node direction=360";
210 assertNoMatch: "node direction=0";
211}
212*[direction][direction !~ /^([0-9][0-9]?[0-9]?|north|east|south|west|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW|forward|backward|both|clockwise|anti-clockwise|anticlockwise|up|down)(-([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW))?(;([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW)-([0-9][0-9]?[0-9]?|N|E|S|W|NE|SE|SW|NW|NNE|ENE|ESE|SSE|SSW|WSW|WNW|NNW))*$/] {
213 throwWarning: tr("unusual value of {0}", "{1.key}");
214 assertMatch: "node direction=north-down";
215 assertMatch: "node direction=rome";
216 assertMatch: "node direction=C";
217 assertMatch: "node direction=NNNE";
218 assertMatch: "node direction=1360";
219 assertNoMatch: "node direction=NE-S"; /* ranges are used at tourism=viewpoint*/
220 assertMatch: "node direction=north-south"; /* ranges only in numbers or short NESW form */
221 assertMatch: "node direction=north-east"; /* if range use N-E, if single direcion use NE */
222 assertNoMatch: "node direction=0-360"; /* complete panorama view */
223 assertNoMatch: "node direction=45-100;190-250;300-360";
224 assertMatch: "node direction=45-100;190-250;300";
225 assertNoMatch: "node direction=up";
226 assertNoMatch: "node direction=down"; /* up/down are replaced by incline tag, has separate warning */
227 assertNoMatch: "node direction=0";
228 assertNoMatch: "node direction=45";
229 assertNoMatch: "node direction=360";
230 assertNoMatch: "node direction=N";
231 assertNoMatch: "node direction=NNE";
232 assertNoMatch: "node direction=west";
233 assertNoMatch: "node direction=forward";
234 assertNoMatch: "node direction=anti-clockwise";
235 assertNoMatch: "node direction=anticlockwise"; /* both spellings are in use and even wiki uses both */
236}
237
238/* #14786 (should be safe to just remove the meters unit from the value) */
239*[ele][ele =~ /^-?[0-9]+(\.[0-9]+)? ?m$/] {
240 throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
241 fixAdd: concat("ele=", trim(replace(tag("ele"), "m", "")));
242 set .ele_is_fixable;
243 assertMatch: "node ele=12m";
244 assertMatch: "node ele=12 m";
245 assertNoMatch: "node ele=12km";
246 assertMatch: "node ele=12.1m";
247 assertMatch: "node ele=-12.1 m";
248 assertNoMatch: "node ele=12";
249 assertNoMatch: "node ele=high";
250}
251*[ele][ele !~ /^-?[0-9]+(\.[0-9]+)?$/]!.ele_is_fixable{
252 throwWarning: tr("{0} must be a numeric value, in meters and without units", "{0.key}");
253 assertNoMatch: "node ele=12m";
254 assertNoMatch: "node ele=12 m";
255 assertMatch: "node ele=12km";
256 assertNoMatch: "node ele=12.1m";
257 assertNoMatch: "node ele=-12.1 m";
258 assertNoMatch: "node ele=12";
259 assertMatch: "node ele=high";
260}
Note: See TracBrowser for help on using the repository browser.