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

Last change on this file since 12493 was 12493, checked in by Klumbumbus, 7 years ago

fix #14989 - allow ranges in direction key

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