Debian Codegraph @

doc/styles/rules.txt

raw
1 // Set default source language
2 :language: mkgmap
3
4 [[RULES]]
5 = Style rules =
6
7 Rules allow you to take a map feature in the OSM format, which uses a set of tags to describe the feature into the format required by Garmin maps, where features are identified by a number.
8
9 The rules for converting points, lines and polygons are held in
10 correspondingly named files, as described in <<FILES,the structure of a style>>.
11
12 Each file contains a number of rules. Rules test the values of the tags of an OSM node, way or relation.
13 They also select a specific Garmin type based on the result of those tests and set mkgmap internal tags (+mkgmap:*+) to assign specific attributes to a map element.
14
15 == Introduction ==
16 Each rule starts off with an expression to test the value of one or more
17 tags.
18
19 A rule is made up of two or three parts.
20 The three possible parts are:
21
22 * The first part is *required*: this is a set of <<Tag_tests,tests>> that are performed on the tags of the item to be converted.
23 * The second part is the <<Action_block,action block>> that can be used to do things with the tags of objects that match the tests and is contained in curly braces `{...}`.
24 * The third part is the <<Element_type,element type definition>> and sets
25 the Garmin type and sometimes other parameters that will be used if the tests match. This part is contained
26 in square brackets `[...]`.
27
28 If you want to add two or more different map elements you can do this with repeated square brackets following one expression `[...]`
29
30 Here is an example of a rule containing all three sections:
31
32 [source]
33 ----
34 natural=cliff { name '${name} cliff' | 'cliff' } [0x10501 resolution 22]
35 ----
36
37 * The tests section is +natural=cliff+
38 * The action block is `{ name '${name} cliff' | 'cliff' }`
39 * The element type definition is +[0x10501 resolution 22]+
40
41 As a general point, space and newlines don't matter. There is no need to
42 have rules all on the same line, and you can spread them out over several
43 lines and add extra spaces wherever you like if it helps to make them
44 easier to read.
45
46 .Example with lots of extra space and newlines
47 [source]
48 ----
49 natural=cliff
50 {
51 name '${name} cliff'
52 | 'cliff'
53 }
54
55 [
56 0x10501
57 resolution 22
58 ]
59 ----
60
61 .Example with all unneeded spaces removed
62 [source]
63 natural=cliff{name'${name} cliff'|"cliff"}[0x10501 resolution 22]
64
65 === Tag and text values ===
66 Tag names and vales are often single words consisting of letters and
67 perhaps digits.
68 If however a value (or tag, although that is less common) contains a
69 space or punctuation character then the whole value must be enclosed in
70 quotation marks. You can use either single quotes (+'+) or
71 double quotes (+"+).
72
73 If your text contains a quote then you must use the other kind
74 of quote around the value.
75
76 [source]
77 ----
78 highway=primary
79 "highway"="primary" # quotes not needed, but do no harm
80 name='Main Street' # quotes needed to keep 'Main Street' as one thing
81 name="Ten O'Clock Tavern" # Double quotes used because text contains single quotes
82 ----
83
84 [[Tag_tests]]
85 == Tag tests ==
86 The most common test is that a particular OSM tag has a given value.
87 So for example if we have
88
89 [source]
90 highway=motorway
91
92 This means that we look up the highway tag in the OSM input file and if it exists and has the value
93 'motorway' then this test has matched.
94
95 You can also compare numeric quantities:
96 [source]
97 ----
98 population > 10000
99 lanes >= 2
100 population < 10000000
101 ----
102
103 Respectively, these mean: a population greater than ten thousand, a road with at least two lanes
104 and a population less than one million.
105
106 You may also use regular expressions:
107 [source]
108 ele ~ '\d*00'
109
110 This checks whether ele is a multiple of 100.
111
112 === Allowed operations
113 The following table describes the operations that may be used.
114
115 .Full list of operations
116 [width="80%",cols="1,4",frame="topbot",grid="rows",options="header"]
117 |====
118 |Operation | description and examples
119
120 | tag=value | This matches when a tag has the given value.
121
122 | tag!=value | This is true when the tag does not have the given value,
123 or the tag is not present at all.
124
125 |tag=* | Matches when the tag exists, regardless of its value.
126
127 |tag!=* | Matches when the tag does _not_ exist.
128
129 |tag < value |
130 Matches when the tag when converted as a number is less than the given value.
131 If the value is not numeric then this is always false. This is also the case if
132 value contains a unit. Conversion for the maxspeed tag can be done with
133 the maxspeedkmh() and maxspeedmph() function (see <<Functions,Functions>>).
134
135 |tag \<= value,
136 tag > value,
137 tag >= value |
138 As above, for less than or equal, greater than and greater than or equal.
139
140 |tag ~ REGEX| This is true when the value of the tag matches the given
141 regular expression.
142 The http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html[Java regular expression]
143 syntax is recognised.
144 For example `name ~ '.*[Ll]ane'` would match every name that ended in
145 'Lane' or 'lane'.
146
147 | ! (expr) |
148 The 'not' operator ('!') reverses the truth of the expression following.
149 That expression must be in parentheses.
150
151 |====
152
153
154 === Combining tag tests ===
155 Although it is possible to convert many OSM nodes and ways just using one
156 tag, it is also often necessary to use more than one.
157
158 For example, say you want to take roads that are tagged both as
159 +highway=unclassified+ and +lanes>2+ differently to roads that are
160 just +highway=unclassified+. In this type of case, you might create two
161 separate rules as follows:
162
163 [source]
164 ----
165 highway=unclassified & lanes>2 [0x06]
166 highway=unclassified [0x05]
167 ----
168
169 This means that roads that are unclassified and have more than two lanes
170 would use Garmin element type 0x06, whereas unclassified
171 roads without a lanes tag, or where it is less or equal than 2
172 would use type 0x05.
173
174 It is important to note that the order of the rules is important here. The rules are
175 matched in the order that they occur in the style file and mkgmap stops trying to apply them after
176 the first one that matches.
177 If you had the rules above in the reverse order, then the
178 +highway=unclassified+ rule would match first to any OSM way with that tag/key pair,
179 and the second rule would never get applied.
180 Therefore, in general you want the most specific rules first and simpler, more
181 general rules later on to catch the cases that are not caught by the more
182 complex rules.
183
184 You can also combine alternatives into the one rule using a logical or, represented
185 with a pipe (|) symbol. For example
186 [source]
187 highway=footway | highway=path [0x07]
188
189 This means if the road has either the *highway=footway* tag or the
190 *highway=path* tags (or both), then the condition matches and mkgmap would
191 use type 0x07 for the map. This works exactly the same as if you had written
192 two separate rules - one for footway and one for path - and indeed is converted
193 to two separate rules internally when mkgmap runs.
194
195 You are not limited to two tests for a given rule... you can combine and group tests
196 in almost whatever way you like.
197 So for a slightly forced example the following would be possible:
198 [source]
199 place=town & (population > 1000000 | capital=true) | place=city
200
201 This would match if there was a +place+ tag which had the value +town+
202 and either the population was over a million or it was tagged a capital,
203 or there was a +place+ tag with the value +city+.
204
205 [NOTE]
206 There used to be some restrictions on the kind of expression you could
207 use. Now the only restriction is you must have at least one test that
208 depends on a tag existing. So you cannot match on everything, regardless
209 of tags, or test for an object that does _not_ have a tag.
210
211 === Comparing the values of two tags ===
212 Sometimes you may want to compare the values of two tags, rather than
213 the value of one tag with a fixed value.
214 Use a dollar sign to indicate that you want the tag value.
215
216 [source]
217 ----
218 # If you had the following tags:
219 # name=Fford-y-Mor
220 # name:en=Terrace Road
221 # name:cy=Fford-y-Mor
222
223 name = $name:cy { } # this would match
224 name = $name:en { } # and this would not
225 ----
226
227 This tests if the value of the +name+ tag is the same as the welsh name
228 tag (+name:cy+)
229
230 It is worth noting that the normal case
231 [source]
232 ----
233 highway=primary
234 ----
235 is exactly the same as
236 [source]
237 ----
238 $highway=primary
239 ----
240
241
242 [[Functions]]
243 === Functions ===
244 Functions calculate a specific property of an OSM element.
245
246 .Style functions
247 [width="100%",cols="5,1,1,1,11",options="header"]
248 |=====
249 |Function |Node |Way |Rel. |Description
250 |length() | | x | x |
251 Calculates the length in m. For relations its the sum of all member length (including sub relations).
252
253 |area_size() | | x | |
254 Calculates area size in (garmin units)^2^. A non closed way has an area_size() of 0. In case a polygon is an outer part
255 of a multipolygon the whole area size of all outer multipolygon parts is returned.
256
257 The size of one (garmin unit)^2^ in m^2^ varies depending on the latitude. Sample values:
258
259 5.71 m^2^ at latitude 0°
260
261 4.03 m^2^ at (\+-)45°
262
263 2.85 m^2^ at (\+-)60°
264
265 0.5 m^2^ at (+-)85°
266 |is_complete() | | x | |
267 +true+ if all nodes of a way are contained in the tile. +false+ if some nodes of the way are missing in the tile.
268
269 |is_closed() | | x | |
270 +true+ the way is closed (start and end point are the same). +false+ the way is not closed and cannot be processed as polygon.
271
272 |maxspeedkmh() | | x | |
273 Retrieves the value of the 'maxspeed' tag converted to km/h.
274
275 |maxspeedmph() | | x | |
276 Retrieves the value of the 'maxspeed' tag converted to mph.
277
278 |type() | x | x | x |
279 Retrieves the type of the OSM element: 'node', 'way', 'relation'.
280
281 |osmid() | x | x | x |
282 Retrieves the id of the OSM element. This can be useful for style debugging purposes. Note that due to internal changes like merging, cutting etc.
283 some element ids are changed and some have a faked id > 4611686018427387904.
284
285 |is_in(*tag*,*value*,*method*) | x | x | |
286 +true+ if the element is in polygon(s) having the specified *tag*=*value* according to the *method*, +false+ otherwise.
287 *value* can be \'\*' which matches any polgon having *tag*.
288 The methods available depend on the Style section:
289
290 polygons:
291 *all* - all of the closed 'way' is within the polygon(s).
292 *any* - some is within.
293
294 points:
295 *in* - the 'node' is within a polygon.
296 *in_or_on* - it is within or on the edge.
297 *on* - it is on the edge.
298
299 lines:
300 *all* - part of the 'way' is within the polygon(s), none is outside; it might touch an edge.
301 *all_in_or_on* - none is outside.
302 *on* - it runs along the edge.
303 *any* - part is within.
304 *none* - part is outside, none is inside.
305
306 A common case is a line outside the polygon that runs to the edge, joining a line that is inside.
307 The method to match an outside line (*none*) allows part to be on the edge,
308 likewise, the method to match an inside line (*all*) allows part to be on the edge.
309 Compared to *all*, the method *all_in_or_on* additionally matches lines which are only on the edge of the polygon.
310
311 |is_drive_on_left() | | x | |
312 +true+ the element is in a drive_on_left country. +false+ the element is not a drive_on_left country or the information given
313 in the tags mkgmap:admin_level2 and mkgmap:country could not be used to retrieve the information.
314
315 |====
316
317 The following rule matches for all service ways longer than 50m.
318 [source]
319 highway=service & length()>50
320
321 [[Action_block]]
322 == Action block ==
323 An action block is enclosed in braces +{ ... }+ and contains one or more
324 statements that can alter the element being displayed; multiple
325 statements are separated by `;' symbol. When there is an action block, the
326 <<Element_type,element type definition>> is optional, but if used it must
327 come after the action block.
328
329 A list of all the command that can be used in the action block follows.
330 In the examples you will see notation of the form `${name}`, this is how
331 tag values can be substituted into strings, in a similar way to many
332 computer languages. For full details see
333 the section on <<VARS,variable substitution>>.
334
335 === add ===
336 The add command adds a tag if it does not already exist.
337 This is often used if you want to set the value of a tag as a default but
338 do not want to overwrite any existing tag.
339
340 For example, motorways are one way by default so we need to add the
341 +oneway=yes+ tag in the style so that is treated as one way by the
342 device. But there are some stretches of motorway that are one-way and
343 these will be tagged as +oneway=no+. If we used +set+ then that tagging
344 would be lost, so we use +add+.
345 [source]
346 highway=motorway { add oneway=yes }
347
348 The other use is in in relations with the 'apply' command.
349
350 All the same you can set any tag you want, it might be useful so you can match
351 on it elsewhere in the rules.
352
353 You can also use substitutions.
354 [source]
355 {add name='${ele}'; add name='${ref}';}
356
357 These two commands would set the 'name' tag to the value of the 'ele' tag if it exists, or to the value of the 'ref' tag if that exists.
358
359 You can also give a list of alternative expressions separated with a
360 vertical bar in the same way as on the name command. The first
361 one that is fully defined will be used.
362
363 [source]
364 {add key123 = '${name:en}' | '${name}'; }
365
366 If 'key123' is not set it will set 'key123' to the value of the 'name:en' tag if it exists and to the 'name' tag if not.
367
368 === set ===
369 The 'set' command is just like the 'add' command, except that it sets the
370 tag, replacing any existing value it had.
371
372 === delete ===
373 The delete command deletes a tag.
374 [source]
375 { delete key123 }
376
377 === deletealltags ===
378 The deletealltags command deletes all tags. Usually this stops all further processing of the element.
379 [source]
380 { deletealltags }
381
382 === addlabel ===
383 Each item in the Garmin map can have up to four labels. Usually only the first label is displayed.
384 On some Garmin units the second label is used for routing instructions. The third
385 and fourth label are known to be used for address search only. The four labels can be assigned
386 by setting the tags +mkgmap:label:n+ where n is a number between 1 and 4.
387
388 The addlabel command assigns the first empty +mkgmap:label:n+ tag with the given value.
389
390 [source]
391 {addlabel '${name} (${ref})' | '${ref}' | '${name}'}
392
393 If both the +name+ and +ref+ tags are are set, then the first alternative would be
394 completed and the resulting label might be _Main St (A1)_.
395 If just +name+ was set, then the first two alternatives can not be fully
396 substituted and so are ignored, leaving the last alternative +'${name}'+
397 and so the final label might in that case be _Main St_.
398
399 Highway shields can be used in the first label only. You can use the notation
400 +${tagname|highway-symbol:box}+.
401 Valid symbols are +interstate+, +shield+, +round+, +hbox+, +box+ and
402 +oval+. The appropriate kind of highway shield will be added to the value
403 of +tagname+. The exact result of the way it looks is dependent on where
404 you view the map.
405
406 === name ===
407 This sets the first label of the element but only if it is not already set.
408 This is a helper action. The same effect can be produced with different notations
409 as it is shown in the following example where all three lines have the same effect.
410 [source]
411 ----
412 {name '${name} (${ref})' | '${ref}' | '${name}'}
413 {add mkgmap:label:1='${name} (${ref})' | '${ref}' | '${name}'}
414 mkgmap:label:1!=* {set mkgmap:label:1='${name} (${ref})' | '${ref}' | '${name}'}
415 ----
416
417 === addaccess ===
418 The "addaccess" action sets all unset mkgmap access restriction tags to the given value.
419 This is a helper action to avoid long action blocks.
420
421 [source]
422 ----
423 { addaccess 'no' }
424 ----
425 is the same as
426 [source]
427 ----
428 {
429 add mkgmap:foot=no;
430 add mkgmap:bicycle=no;
431 add mkgmap:car=no;
432 add mkgmap:taxi=no;
433 add mkgmap:truck=no;
434 add mkgmap:bus=no;
435 add mkgmap:emergency=no;
436 add mkgmap:delivery=no
437 }
438 ----
439
440 === setaccess ===
441 The "setaccess" action sets all mkgmap access restriction tags to the given value no matter if
442 they already have a value or not. This is a helper action to avoid long action blocks.
443
444 [source]
445 ----
446 { setaccess 'no' }
447 ----
448 is the same as
449 [source]
450 ----
451 {
452 set mkgmap:foot=no;
453 set mkgmap:bicycle=no;
454 set mkgmap:car=no;
455 set mkgmap:taxi=no;
456 set mkgmap:truck=no;
457 set mkgmap:bus=no;
458 set mkgmap:emergency=no;
459 set mkgmap:delivery=no
460 }
461 ----
462
463 === apply ===
464 The "apply" action only makes sense in relations. Say you have a
465 relation marking a bus route, but none of the ways that are in the
466 relation have any special tags to indicate that they form part of that
467 bus route, and you want to be able to tell from looking at the map which
468 buses go where. You can write a rule in the *relations file* such as:
469
470 [source]
471 ----
472 type=route & route=bus {
473 apply {
474 set route=bus;
475 set route_ref='${route_ref}';
476 }
477 }
478 ----
479
480
481 Then in the *lines file* you will need to write a rule to match _route=bus_.
482 All the relation rules are run before any others so that this works.
483
484 The substitution `${route_ref}` takes the value of the tag on the *relation* and applies
485 it to each of the ways in the relation.
486
487 The substitution `$(route_ref)` (with parenthesis, rather than curly
488 braces) can be used for accessing the value of the tag on
489 the actually processed *member* of the relation, e.g.
490
491 [source]
492 ----
493 type=route & route=bus {
494 apply {
495 set route=bus;
496 set name='$(name) ${route_ref}';
497 }
498 }
499 ----
500
501 The "apply" action can be limited to members with a special role by adding
502 _role=rolevalue_ after the _apply_ keyword.
503
504 [source]
505 ----
506 type=route & route=bus {
507 apply role=forward {
508 set route=bus;
509 set name='$(name) ${route_ref}';
510 }
511 }
512 ----
513
514 === apply_once ===
515 The apply_once action is like +apply+, but it will apply the action once
516 per relation member. A round-trip route relation may include the same
517 ways multiple times, unless all member ways have been defined as parallel
518 one way streets.
519
520 === apply_first ===
521 The apply_first action is like +apply+, but it will apply the action only to the
522 first relation member as appearing in the input file. In combination with the
523 --add-pois-to-lines option this might be used with route relations to mark the
524 beginning of a route, presuming that the relation is complete and ordered so
525 that the first member is the start of the route.
526
527 === echo ===
528 The echo action prints the element id plus a text to stderr or to where directed by
529 a logging configuration file. This can be used for quality checks and debugging
530 purposes. When using a logging configuration file, the messages are logged
531 with custom level ECHO (1200).
532 [source]
533 highway=motorway_link & oneway!=* { echo "motorway_link without oneway tag" }
534
535 === echotags ===
536 The echotags action prints the element id, all tags and values plus a text to stderr
537 or to where directed by a logging configuration file. This can be used for style
538 debugging purposes. When using a logging configuration file, the messages are
539 logged with custom level ECHO (1200).
540 [source]
541 highway=living_street { echotags "This is a living_street" }
542
543 [[VARS]]
544 == Variables
545 You can substitute the value of tags within strings in an action.
546 A dollar sign (+$+) introduces the substitution followed by the tag name
547 surrounded by curly braces like so `${name}`.
548
549 The most obvious use for variables is in setting the name of the element.
550 You are able to use any combination of tags to make the name from.
551 Here we name a fuel station by its brand and the operator in parentheses following.
552 [source]
553 amenity=fuel { name '${brand} (${operator})' } [ 0x2f01 ]
554
555 If the operator tag was not set, then the name would not be set because *all*
556 substitutions in a string must exist for the result to be valid.
557 This is why the "name" command takes a list of possibilities, if operator
558 was simply replaced with a blank, then you would have an empty pair of parentheses.
559 So you would fix the previous rule by adding another name option.
560
561 [source]
562 ----
563 amenity=fuel
564 { name '${brand} (${operator})' | '${brand}' }
565 [ 0x2f01 ]
566 ----
567
568 If only the brand tag exists, then the first option will be skipped and the second
569 will be used.
570
571 === Variable filters
572 The value of a variable can be modified by 'filters'.
573 The value of the tag can be transformed in various ways before being
574 substituted.
575
576 A filter is added by adding a vertical bar symbol "|" after the tag name, followed
577 by the filter name, then a colon ":" and an argument. If there is more than
578 one argument required then they are usually separated by colons too, but
579 that is not a rule.
580
581 +${tagname|filter:"arg1:arg2"}+
582
583 You can apply as many filter expressions to a substitution as you like.
584
585
586 +${tagname|filter1:"f1Args"|filter2:"f2Args"}+
587
588 For backward compatibility, most argument strings
589 do not actually need to be quoted, however we would recommend that you
590 do for clarity. If you need a pipe symbol or a closing curly backet,
591 then you must use quotes.
592
593 include::rules-filters.txt[]
594
595 include::internal-tags.txt[]
596
597 [[Element_type]]
598 == Element type definition ==
599 As noted above this is contained in square brackets and if used must be the *last part of the rule*.
600
601 The first and only mandatory part of this section is the Garmin type code
602 which must always be written in hexadecimal. Following this the element
603 type definition rule can contain a number of optional keywords and
604 values.
605
606 === level ===
607 This is the highest zoom level that this element should appear at (like
608 EndLevel in the mp format). The lower the level the detailed the view.
609 The most detailed, most zoomed in, level is level 0. A map will usually
610 have between three and five levels. If the level for an object is not
611 given then it defaults to 0 and so the specified feature will only appear
612 at the most detailed level.
613
614 In the following example, we set highways to appear from zoom level 4 down to zoom level 0:
615 [source]
616 -----
617 highway=motorway [0x01 level 4]
618 -----
619
620 [WARNING]
621 --
622 You can use +level+ to place elements into the layers of the map that you
623 want but you can't force the device to actually display them.
624
625 Some pieces of software (such as QLandkarteGT, I believe) will honour
626 your selections, but actual GPS devices have their own ideas about
627 which POI's can be shown at which resolutions.
628 --
629
630 .Level ranges
631 You can also give a range (e.g. 1-3) and the map will then contain the
632 object only between the specified levels.
633
634 [source]
635 ----
636 highway=motorway [0x01 level 3-5]
637 -----
638
639 In this example, motorways will appear at zoom level 5, which is most
640 zoomed out, and continue to be visible until zoom level 3, which is
641 moderately zoomed in, and then will not be shown in zoom levels 2, 1 and
642 0 (most zoomed-in).
643
644 [TIP]
645 Of course you are unlikely to want a feature to disappear as you zoom in,
646 but this can be used for interesting effects where a different
647 representation takes over at the lower zoom levels. For example a
648 building may be a point at high levels and then become a polygon at lower
649 levels.
650
651 === resolution ===
652
653 This is an alternative way of specifying the zoom level at which an
654 object appears. It is specified as a number from 1-24, which corresponds
655 to one of the zoom levels that Garmin hardware recognises. You should
656 not use resolution if you have used level as they achieve the same
657 outcome.
658
659 In either case, the mapping between level and resolution is given in the
660 options style file, where you will see something like this:
661
662 -----
663 # The levels specification for this style
664 #
665 levels = 0:24, 1:23, 2:22, 3:20, 4:18, 5:16
666 -----
667 This sets level zero equal to resolution 24, level 1 to resolution 23 and so on.
668
669 Although the default style uses +resolution+ rather than +level+ it is on
670 the whole much easier to use +level+ as it is immediately clear where the
671 element will end up. If you use a +resolution+ that is `between' two
672 levels for example it will only show up in the lower one.
673
674 .Resolution ranges
675
676 Just as with levels, you can specify a range of resolutions at which an
677 object should appear. Here is an example.
678
679 [source]
680 ----
681 highway=residential [0x06 resolution 16-22 continue]
682 highway=residential [0x07 resolution 23-24]
683 ----
684
685 This example creates roads of type 0x06 between resolutions 16 and
686 22, then roads of type 0x07 between resolutions 23 and 24. This
687 example makes use of the continue statement, which is discussed in more
688 detail below.
689
690 [TIP]
691 Since 24 is the default upper bound for a range, that second range could
692 just have been written as the single number `23'.
693
694 === default_name ===
695 If the element has not already had a name defined elsewhere in the rule,
696 it will be given the name specified by +default_name+. This might be
697 useful for things that usually don't have names and don't have a
698 recognisable separate Garmin symbol. You could give a default name of
699 `bus stop' for example and all bus stops that didn't have their own name
700 would now be labelled as such.
701
702 [TIP]
703 Be careful to use this sparingly and not overwhelm the map or the search.
704
705 === road_class ===
706 Setting this makes the line a "road" and it will be routable and can be
707 part of an address search.
708 It gives the class of the road where class 4 is used for major roads that
709 connect different parts of the country, class 3 is used for roads that
710 connect different regions, down to class 0 which is used for residential
711 streets and other roads that you would only use for local travel.
712
713 It is important for routing to work well that most roads have lower classes and
714 there are fewer and fewer roads in each of the higher classes.
715 Also, the class of connector roads (links, roundabouts, ramps) matches
716 the class of the highest class of roads being connected.
717
718 .Road classes
719 [width="40%",frame="topbot",grid="rows",cols="<1,<4",options="header"]
720 |=====
721 | Class | Used as
722 | 4 | Major HW/Ramp
723 | 3 | Principal HW
724 | 2 | Arterial St / Other HW
725 | 1 | Minor or Service road
726 | 0 | Residential Street / Unpaved road / Trail
727 |=====
728
729 === road_speed ===
730
731 This keyword is used along with +road_class+ to indicate that the line is
732 a "road" that can be used for routing and for address searches.
733 It is an indication of how fast traffic on the road is. 0 is the slowest and 7 the fastest.
734 This is *not* a speed limit and does not activate the maximum speed
735 symbol on the newer Garmin car navigation systems.
736 The speed limits that Garmin knows are shown in the following table:
737
738 .Road Speeds
739 [width="40%",frame="topbot",grid="rows",cols="<1,<2",options="header"]
740 |======
741 | road_speed | highest speed
742 | 7 | No speed limit
743 | 6 | 70 mph / 110 kmh
744 | 5 | 60 mph / 90 kmh
745 | 4 | 50 mph / 80 kmh
746 | 3 | 35 mph / 60 kmh
747 | 2 | 25 mph / 40 kmh
748 | 1 | 15 mph / 20 kmh
749 | 0 | 3 mph / 5 kmh
750 |======
751
752 === continue ===
753
754 As discussed above, style rules are matched in the order that they occur
755 in the style file. By default, for any given OSM object mkgmap will try
756 each rule in turn until one rule wth a _element type definition_ matches;
757 it will then stop trying to match further rules against the current OSM
758 object. If the rule only has an _action block_ mkgmap will continue to
759 find other matches.
760
761 However, if you add a _continue_ statement to the definition block of a
762 rule, mkgmap will not stop processing the object but will instead carry
763 on trying to match subsequent rules until it either runs out of rules or
764 finds a matching rule that does not include a _continue_ statement.
765
766 This feature is used when you want more than one symbol to result from
767 a single OSM element. This could be for clever effects created by
768 stacking two lines on top of each other.
769 For example if you want to mark a bridge in a distinctive way you
770 could match on +bridge=yes+, you would then almost always use +continue+ so
771 that the +highway+ tag could be matched later. If you failed to do this
772 then there might be a break in the road for routing purposes.
773
774 Note that when using the _continue_ statement, the action block
775 of the rule (if there is one) will only be applied _within this rule_ and
776 not during any following rule matches. Use the _continue with_actions_
777 statement if you want to change this behaviour (see next section).
778
779 === continue with_actions ===
780 The with_actions statement modifies the continue behaviour in such a way,
781 that the action block of this rule is also applied, when this element is
782 checked for additional conversions.
783
784 .Example of a full element type definition
785 [source]
786 ----
787 [0x2 road_class=3 road_speed=5 level 2
788 default_name 'example street' continue with_actions]
789 ----
790
791 == Including files ==
792 Its often convenient to split a file into smaller parts or to use the
793 same rules in two different files. In these cases you can include
794 one rule file within another.
795
796 [source]
797 include "inc/common";
798
799 Here some common rules have been included in a rule file from a directory
800 called "inc" within the style. Note that the line ends in a semi-colon
801 which is easy to forget.
802
803 [NOTE]
804 --
805 The included files don't have to be located within the style and can be
806 anywhere else.
807 --
808
809 When you include a file, the effect is exactly as if you had replaced the
810 include line with the contents of the file. An +include+ directive can
811 occur anywhere that a rule could start, and it is possible to include
812 another file from with in the file that is included.
813
814 .Including from another style
815 It is also possible to include a file from another style.
816 To do this you simply add +from stylename+ to the end of the include
817 statement.
818
819 [source]
820 include "points" from default;
821
822 That will include the +points+ file from the default style. This might be
823 useful if you want to only change a few things about the default style.
824
825 == Finalize section ==
826 The points, lines and polygons style files can have a finalize section at the end
827 of the style file. It starts with the line +<finalize>+.
828
829 The finalize section contains actions only and must not have an element type definition.
830 Its rules are executed each time an element type definition in the style file matches.
831 The finalize section is often useful to set the mkgmap internal tags.
832
833 .Finalize section in the lines file with access handling
834 ====
835 Two elements tagged with
836
837 Way 1: highway=motorway, ref=A1
838 Way 2: highway=service, name=Main Road, access=no, foot=yes, bicycle=yes
839
840 using the lines file
841
842 [source]
843 ----
844 highway=motorway [0x01 road_class=4 road_speed=7 resolution 15]
845 highway=service [0x07 road_class=0 road_speed=1 resolution 24]
846
847 <finalize>
848 highway=* { name '${name} (${ref})' | '${name}' | '${ref}' }
849 highway=motorway { add bicycle=no; add foot=no }
850 bicycle=* { add mkgmap:bicycle='${bicycle}' }
851 foot=* { add mkgmap:foot='${foot}' }
852 access=* { addaccess '${access}' }
853 ----
854
855 will result in
856
857 Way 1: highway=motorway, ref=A1, mkgmap:label:1=A1, mkgmap:foot=no,
858 mkgmap:bicycle=no
859 Road 1 in Garmin map: Type 0x01, Name 'A1', no access for bicycle and foot
860 Way 2: highway=service, name=Main Road, access=no, foot=yes, bicycle=yes,
861 mkgmap:label:1=Main Road, mkgmap:foot=yes, mkgmap:bicycle=yes,
862 mkgmap:car=no, mkgmap:truck=no, mkgmap:bus=no, ...
863 Road 2 in Garmin map: Type 0x07, Name 'Main Road', no access for all vehicle
864 types except bicycle and foot
865 ====
866
867 [NOTE]
868 Actions in the finalize section are not persistent in terms of the +continue+ or
869 +continue with_actions+ statement
870
871 == Style syntax extension if then else ==
872
873 To avoid the repetition of expressions you can use the following syntax:
874 if (<<Tag_tests,tests>>) then
875 i-rule(s)
876 end
877
878 or
879
880 if (<<Tag_tests,tests>>) then
881 rule(s)
882 else
883 e-rules(s)
884 end
885
886 [NOTE]
887 Rules within +if+ and +end+ must be written with an expression.
888 The shortest valid expression is a pair of round brackets +()+.
889
890 So, instead of
891 [source]
892 ----
893 boundary=administrative { name '${mkgmap:boundary_name}' }
894 boundary=administrative & admin_level<3 [0x1e resolution 12]
895 boundary=administrative & admin_level<5 [0x1d resolution 19]
896 boundary=administrative & admin_level<7 [0x1c resolution 21]
897 boundary=administrative & admin_level<9 [0x1c resolution 22]
898 boundary=administrative [0x1c resolution 22]
899 ----
900 you may write
901 [source]
902 ----
903 if (boundary=administrative) then
904 () { name '${mkgmap:boundary_name}' }
905 admin_level<3 [0x1e resolution 12]
906 admin_level<5 [0x1d resolution 19]
907 admin_level<7 [0x1c resolution 21]
908 admin_level<9 [0x1c resolution 22]
909 () [0x1c resolution 22]
910 end
911 ----
912
913 If statements may also be nested and you can also use them in combination
914 with the include statement.
915
916 [source]
917 ----
918 if (mkgmap:option:routing=car) then
919 include "inc/car-rules";
920 end
921 if (mkgmap:option:routing=bicycle) then
922 include "inc/cycle-rules";
923 end
924 ----
925
926 == Troubleshooting ==
927
928 For each node/way/relation, mkgmap goes through the tags exactly once in
929 order from the top of the file downward.
930 For each rule that matches, any action block will be run.
931 As soon as a rule that ends with a type definition is found then
932 processing stops and that is the Garmin symbol that is produced.
933
934 The only exception is if the Type Definition contains the
935 +continue+ statement. In that case _mkgmap_ will continue
936 looking for further matches.
937
938 * Where possible always have the same tag on the left. This will make things more predictable.
939 * Always set made-up tag names if you want to also match on them later, rather than setting tags that might be used already.
940 * Use the +echo+ and +echotags+ actions to understand what's going on during style processing.
941
942 == Some examples ==
943 The following are some examples of style rules, with explanations of what they do.
944
945 === Simple examples ===
946 In the majority of cases everything is very simple. Say you want roads that are tagged as *highway=motorway* to have the Garmin type 0x01 ("motorway") and for it to appear up until the zoom level 3.
947
948 Then you would write the following rule.
949 [source]
950 ----
951 highway=motorway [0x01 level 3]
952 ----
953
954 Nodes that have an id and a subid are referenced by concatenating both ids.
955 [source]
956 ----
957 amenity=bank [0x2f06 level 3]
958 ----
959
960 This will be explained in more detail in the following sections along
961 with how to use more than one tag to make the choice.
962
963 For a roundabout you may want to use the special Garmin type 0xc in combination with an overlaying way
964 that shows the road importance. You can do this with two rules like this
965 [source]
966 ----
967 junction=roundabout & (highway=tertiary | highway=tertiary_link)
968 [0x0c road_class=1 road_speed=1 resolution 24 continue]
969 junction=roundabout & (highway=tertiary | highway=tertiary_link)
970 [0x10804 resolution 21]
971 ----
972
973 or shorter with one rule that has two type definitions
974 [source]
975 ----
976 junction=roundabout & (highway=tertiary | highway=tertiary_link)
977 [0x0c road_class=1 road_speed=1 resolution 24] [0x10804 resolution 21]
978 ----
979
980 === More involved examples ===
981 A few tips and tricks showing how the rules can be used to
982 create almost any effect.
983
984 .Internet cafes
985 ====
986 [source]
987 amenity=cafe & internet_access=wlan {name '${name} (wifi)'} [0x2a14 resolution 23]
988 ====
989 Checks to see if an OSM object has both the amenity=cafe and internet_access=wlan key/tag pairs.
990 If name=Joe's Coffee Shop, then the Garmin object will be named _Joe's Coffee Shop (wifi)_.
991 The Garmin object used will be 0x2a14 and the object will only appear at resolutions 23 and 24
992
993 .Guideposts
994 ====
995 [source]
996 information=guidepost
997 { name '${name} - ${operator} - ${description} '
998 | '${name} - ${description}'
999 | '${name}'
1000 | '${description}'
1001 | '${operator}'
1002 | '${ref}'
1003 }
1004 [0x4c02 resolution 23 default_name 'Infopost']
1005
1006 Checks to see if an OSM object has the information=guidepost key/tag pair.
1007 If so then the name will be set depending on the available +name+,
1008 +operator+ and +description+ tags as follows.
1009
1010 1. If for example we have the tags `name="Route 7"`, `operator="Kizomba
1011 National Parks"` and `description="Trail signpost"`, then the Garmin object will be named
1012 _Route 7 - Kizomba National Parks - Trail signpost_.
1013 2. If the OSM object just has the +name+ and +description+ tags set, the Garmin object will be named _Route 7 - Trail signpost_
1014 3. If just the +name+ tag is available, the Garmin object will be named _Route 7_
1015 4. If just the +description+ tag is available, the Garmin object will be named _Trail signpost_;
1016 5. and if just the +operator+ tag is available, the Garmin object will be named _Kizomba National Parks_.
1017
1018 The Garmin object used will be 0x4c02 and will only appear at resolutions 23 and 24
1019 ====
1020
1021 .Car sales rooms
1022 ====
1023 [source]
1024 shop=car {name '${name} (${operator})' | '${name}' |'${operator}'} [0x2f07 resolution 23]
1025
1026 If name="Alice's Car Salesroom" and operator=Nissan, the Garmin object
1027 will be named _Alice's Car Salesroom (Nissan)_
1028 ====
1029
1030 .Opening hours in postcode field
1031 ====
1032 This is a trick to get opening hours to show up in the postcode field of
1033 a POI. Tricks like this can enhance the map for certain uses, but of
1034 course may prevent the proper use of the postcode field.
1035
1036 [source]
1037 opening_hours=* {set addr:postcode = '${addr:postcode} open ${opening_hours}'
1038 | 'open ${opening_hours}'}
1039
1040 For _any_ OSM object which has the opening_hours key set to a value, this
1041 sets the postcode to include the opening hours. For example, if
1042 addr:postcode=90210, addr:street=Alya Street, addr:city=Lagos and
1043 addr:housenumber=7 and opening_hours=09.00-17.00, the address field of
1044 the Garmin POI will be _7, Alya Street, Lagos, 90210 open 09.00-17.00_.
1045
1046 ====
1047
1048 .Mountain Passes depending on the way they belong to
1049 ====
1050 [source]
1051 mkgmap:from-node:mountain_pass=yes & highway=* & highway!=path & highway!=track
1052 {set mkgmap:label:1='${mkgmap:from-node:name}'} [0x5208 resolution 24-14]
1053
1054 Note: This only works if you activated --add-pois-to-lines.
1055 When you activate this option, all points of a line (a way in OpenStreetMap) generate a point.
1056
1057 Those points attributes are those from OpenStreetMap's way. The specific node's
1058 attributes are set as mkgmap:from-node:attribute_name. For instance, here,
1059 all points from a way are available to a "points" rule. We're looking for
1060 mountain passes, but only if they can be reached by something else than a path
1061 or a track. So we match all points that belong to a way that's not a path or a
1062 track, and where the original point is tagged as a mountain pass.
1063
1064 Please note that if the point is part of several ways, you'll get duplicates
1065 (you could use --nearby-poi-rules to solve this).
1066
1067 ====