# first set the country code
mkgmap:country!=* & mkgmap:admin_level2=* { set mkgmap:country='${mkgmap:admin_level2}' }
mkgmap:country!=* & addr:country=* { set mkgmap:country='${addr:country}' }
mkgmap:country!=* & is_in:country=* { set mkgmap:country='${is_in:country}' }
# country specific rules first
# Netherlands = NLD
mkgmap:country=NLD & mkgmap:region!=* & mkgmap:admin_level4=* { set mkgmap:region='${mkgmap:admin_level4}' }
mkgmap:country=NLD & mkgmap:city!=* & mkgmap:admin_level10=* { set mkgmap:city='${mkgmap:admin_level10}' } 
mkgmap:country=NLD & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' } 
# Germany = DEU cities
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level4=Hamburg { set mkgmap:city='${mkgmap:admin_level4}' }
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level4=Berlin { set mkgmap:city='${mkgmap:admin_level4}' }
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level6=Rostock { set mkgmap:city='${mkgmap:admin_level6}' }
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8|subst:Gemeinde |subst:Stadt }'}
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level7=* { set mkgmap:city='${mkgmap:admin_level7}' } 
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level6=* { set mkgmap:city='${mkgmap:admin_level6}' } 
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' } 
mkgmap:country=DEU & mkgmap:city!=* & mkgmap:admin_level10=* { set mkgmap:city='${mkgmap:admin_level10}' } 

mkgmap:country=AUT & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=BEL & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=CZE & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=CZE & mkgmap:city!=* & mkgmap:admin_level7=* { set mkgmap:city='${mkgmap:admin_level7}' }
mkgmap:country=DNK & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=DNK & mkgmap:city!=* & mkgmap:admin_level7=* { set mkgmap:city='${mkgmap:admin_level7}' }
mkgmap:country=FIN & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' }
mkgmap:country=FIN & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=FRA & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' }
mkgmap:country=FRA & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=ISL & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=ITA & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=LUX & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=NOR & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' }
mkgmap:country=POL & mkgmap:city!=* & mkgmap:admin_level10=* { set mkgmap:city='${mkgmap:admin_level10}' }
mkgmap:country=POL & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=PRT & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' }
mkgmap:country=PRT & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=SVN & mkgmap:city!=* & mkgmap:admin_level10=* { set mkgmap:city='${mkgmap:admin_level10}' }
mkgmap:country=ESP & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
mkgmap:country=SWE & mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' }
mkgmap:country=SWE & mkgmap:city!=* & mkgmap:admin_level7=* { set mkgmap:city='${mkgmap:admin_level7}' }
mkgmap:country=CHE & mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' }
 
# common rules for all the rest of countries
mkgmap:region!=* & mkgmap:admin_level6=* { set mkgmap:region='${mkgmap:admin_level6}' } 
mkgmap:region!=* & mkgmap:admin_level5=* { set mkgmap:region='${mkgmap:admin_level5}' } 
mkgmap:region!=* & mkgmap:admin_level4=* { set mkgmap:region='${mkgmap:admin_level4}' } 
mkgmap:region!=* & mkgmap:admin_level3=* { set mkgmap:region='${mkgmap:admin_level3}' } 
mkgmap:region!=* & is_in:county=* { set mkgmap:region='${is_in:county}' } 

mkgmap:city!=* & mkgmap:admin_level8=* { set mkgmap:city='${mkgmap:admin_level8}' } 
mkgmap:city!=* & mkgmap:admin_level7=* { set mkgmap:city='${mkgmap:admin_level7}' } 
mkgmap:city!=* & mkgmap:admin_level9=* { set mkgmap:city='${mkgmap:admin_level9}' } 
mkgmap:city!=* & mkgmap:admin_level10=* { set mkgmap:city='${mkgmap:admin_level10}' } 
mkgmap:city!=* & is_in:city=* { set mkgmap:city='${is_in:city}' }
mkgmap:city!=* & addr:city=* { set mkgmap:city='${addr:city}' }

mkgmap:postal_code!=* & mkgmap:postcode=* { set mkgmap:postal_code='${mkgmap:postcode}' } 
mkgmap:postal_code!=* & addr:postcode=* { set mkgmap:postal_code='${addr:postcode}' } 

mkgmap:street!=* & addr:street=* { set mkgmap:street='${addr:street}' }
mkgmap:street!=* & addr:housename=* { set mkgmap:street='${addr:housename}' }

mkgmap:housenumber!=* & addr:housenumber=* { set mkgmap:housenumber='${addr:housenumber}' }

mkgmap:phone!=* & phone=* { set mkgmap:phone='${phone}' }

mkgmap:is_in!=* & is_in=* { set mkgmap:is_in='${is_in}' }

#------------------------------------------------------------------------------
# generall access

highway=* & (impassable=yes | access=private)   { set access=no; }

#------------------------------------------------------------------------------
# contours take their name from the elevation setting

contour=elevation & contour_ext=elevation_minor     { name '${ele|conv:m=>ft}'; }  [0x20 resolution 22]
contour=elevation & contour_ext=elevation_medium    { name '${ele|conv:m=>ft}'; }  [0x21 resolution 20]
contour=elevation & contour_ext=elevation_major     { name '${ele|conv:m=>ft}'; }  [0x22 resolution 18]

#------------------------------------------------------------------------------
# flag unpaved roads

highway=*
& (surface=cobblestone | surface=compacted | surface=dirt |
   surface=earth | surface=grass | surface=grass_paver |
   surface=gravel | surface=grit | surface=ground | surface=mud |
   surface=pebblestone | surface=sand | surface=unpaved |
   mtb:scale=* |
   tracktype~'grade[2-6]' |
   smoothness~'.*(bad|horrible|impassable)' |
   sac_scale~'.*(mountain|alpine)_hiking' |
   sport=via_ferrata)
{ add mkgmap:unpaved=1; }

(highway=bridleway | highway=path | highway=track | highway=unsurfaced) 
& surface!=* & tracktype!=* & smoothness!=* & sac_scale!=*
{ add mkgmap:unpaved=1; }

#------------------------------------------------------------------------------
# construction and disused

highway=construction | (highway=* & construction=* & construction!=minor & construction!=no) {add access = no; add bicycle = yes; add foot = yes; add mkgmap:dead-end-check = false } [0x08 road_class=0 road_speed=1 resolution 22]
#highway=* & construction=minor { add mkgmap:road-speed = '-2'; add mkgmap:road-speed-min = '1' } [0x08 resolution 22]
highway=* & construction=minor & maxspeed!=* { add mkgmap:road-speed = '4'; add mkgmap:road-speed-min = '3' } [0x01 road_class=4 resolution 12]

# Treat disused ways as highway=service, but at lower road_speed.
highway=* & disused=yes [0x07 road_class=0 road_speed=1 resolution 22]

highway=* & (motor_vehicle=no | motor_vehicle=destination | motor_vehicle=agricultural | motor_vehicle=private) { add motorcar=no }
highway=* & (vehicle=no | vehicle=destination | vehicle=agricultural | vehicle=private) { add motorcar=no }

#------------------------------------------------------------------------------
# highways

highway=* & motorroad=yes   { add bicycle=no; add foot=no; }

# Set the routing direction
(highway=motorway|highway=motorway_link) & destination=* { add display_name = '${ref} (${destination})' }
(highway=trunk|highway=trunk_link)       & destination=* { add display_name = '${ref} (${destination})' }

# motorway
highway=motorway        { add oneway=yes; add bicycle=no; add foot=no; name '${ref|highway-symbol:hbox} ${name}' | '${ref|highway-symbol:hbox}' | '${name}'; }   [0x01 road_class=4 road_speed=7 resolution 12]
highway=motorway_link   { add bicycle=no; add foot=no; } [0x01 road_class=3 road_speed=3 resolution 17]

# trunk
highway=trunk & junction=roundabout         [0x0c road_class=4 road_speed=3 resolution 16]
highway=trunk | highway=trunk_link          { name '${ref|highway-symbol:hbox} ${name}' | '${ref|highway-symbol:hbox}' | '${name}'; add display_name='${name} (${ref})'; }   [0x02 road_class=4 road_speed=6 resolution 17]

# primary
highway=primary & junction=roundabout       [0x0c road_class=3 road_speed=4 resolution 17]
highway=primary | highway=primary_link      { name '${ref|highway-symbol:box} ${name}' | '${ref|highway-symbol:box}' | '${name}'; add display_name='${name} (${ref})'; } [0x02 road_class=3 road_speed=5 resolution 17]

# secondary
highway=secondary & junction=roundabout     [0x0c road_class=3 road_speed=3 resolution 18]
highway=secondary | highway=secondary_link  { name '${ref|highway-symbol:oval} ${name}' | '${ref|highway-symbol:oval}' | '${name}'; add display_name='${name} (${ref})'; }   [0x03 road_class=3 road_speed=4 resolution 18]

# tertiary
highway=tertiary & junction=roundabout      [0x0c road_class=2 road_speed=2 resolution 20]
highway=tertiary | highway=tertiary_link    { name '${ref|highway-symbol:round} ${name}' | '${ref|highway-symbol:round}' | '${name}'; add display_name='${name} (${ref})'; }    [0x04 road_class=2 road_speed=3 resolution 20]

#------------------------------------------------------------------------------
# minor roads

highway=*   { name '${name} (${ref}) ' | '${ref}' | '${name}'; }

# unclassified
highway=unclassified & junction=roundabout  [0x0c road_class=2 road_speed=2 resolution 21]
highway=unclassified                        [0x05 road_class=2 road_speed=2 resolution 21]

# residential
highway=residential & junction=roundabout                       [0x0c road_class=2 road_speed=1 resolution 22]
highway=residential | highway=living_street | highway=minor     [0x06 road_class=2 road_speed=2 resolution 22]

# service
highway=service   {add mkgmap:dead-end-check=false}  [0x07 road_class=2 road_speed=1 resolution 22]

#------------------------------------------------------------------------------
# ways

# designated

highway=cycleway    { add motorcar=no; add bicycle=yes; add foot=yes; } [0x16 road_class=2 road_speed=2 resolution 22]
highway=footway     { add motorcar=no; }                                [0x0d road_class=0 road_speed=0 resolution 23]

highway=bridleway   [0x17 road_class=0 road_speed=0 resolution 23]
highway=byway       [0x08 road_class=0 road_speed=0 resolution 23]

highway=pedestrian & (area!=yes & area!=true & area!=1) { add motorcar=no; add bicycle=no; } [0x0d road_class=0 road_speed=0 resolution 23]

# track

highway=track & (tracktype~'grade[3-6]')                { add motorcar=no; }

highway=track & tracktype=grade1                        [0x0e road_class=2 road_speed=2 resolution 21]
highway=track & tracktype=grade2 & (route=* | ref=*)    [0x0f road_class=1 road_speed=2 resolution 21]
highway=track & tracktype=grade2                        [0x0f road_class=1 road_speed=2 resolution 22]
highway=track & tracktype=grade3 & (route=* | ref=*)    [0x10 road_class=0 road_speed=1 resolution 21]
highway=track & tracktype=grade3                        [0x10 road_class=0 road_speed=1 resolution 22]
highway=track & tracktype=grade4                        [0x11 road_class=0 road_speed=0 resolution 23]
highway=track & tracktype=grade5                        [0x12 road_class=0 road_speed=0 resolution 23]

highway=track | highway=unsurfaced { add motorcar=no; } [0x0a road_class=0 road_speed=0 resolution 22]

# path

highway=path    { add motorcar=no; }

highway=path & (mtb:scale=* | mtb:scale:imba=*)         { add bicycle=yes; }
highway=path & (mtb:scale>0 | mtb:scale:imba>0)         { set toll=yes; }
highway=path & (mtb:scale>2 | mtb:scale:imba>1)         { set bicycle=no; }
highway=path & (sac_scale~'.*(mountain|alpine)_hiking') { add bicycle=no; }             

#highway=path & sac_scale=hiking                         [0x3a road_class=0 road_speed=0 resolution 22]
#highway=path & sac_scale=mountain_hiking                [0x3b road_class=0 road_speed=0 resolution 22]
#highway=path & sac_scale=demanding_mountain_hiking      [0x3c road_class=0 road_speed=0 resolution 22]
#highway=path & sac_scale=alpine_hiking                  [0x3d road_class=0 road_speed=0 resolution 22]
#highway=path & sac_scale=demanding_alpine_hiking        [0x3e road_class=0 road_speed=0 resolution 22]
#highway=path & sac_scale=difficult_alpine_hiking        [0x3f road_class=0 road_speed=0 resolution 22]

highway=path & (mtb:scale<2) & (route=* | ref=*)    [0x0d road_class=0 road_speed=1 resolution 21]
highway=path & (mtb:scale<2)                        [0x0d road_class=0 road_speed=1 resolution 22]
highway=path & (route=* | ref=*)                    [0x0d road_class=0 road_speed=0 resolution 21]
highway=path                                        [0x0d road_class=0 road_speed=0 resolution 22]

# steps

highway=steps   { add motorcar=no; add bicycle=no; add mkgmap:unpaved=1; } [0x13 road_class=0 road_speed=0 resolution 23]

#------------------------------------------------------------------------------
# mop up any unrecognised highway types but keep areas like pedestrian for polygons!

highway=* & area!=yes & area!=true & area!=1    [0x09 ]
junction=roundabout                             [0x0c road_class=1 road_speed=1 resolution 21]

#------------------------------------------------------------------------------

# aeroway
aeroway=runway      [0x27 resolution 19]
aeroway=taxiway     [0x27 resolution 21]

# railway
railway=rail                        [0x39 resolution 17]
railway=light_rail                  [0x14 resolution 21]
railway=tram | railway=narrow_gauge [0x14 resolution 21]
railway=subway                      [0x14 resolution 22]

# route
route=ferry {add mkgmap:ferry=1; add toll=yes} [0x1b road_class=2 road_speed=1 resolution 19]
route=shuttle_train {add mkgmap:ferry=1; add toll=yes} [0x1b road_class=2 road_speed=1 resolution 24]

# aerialway
aerialway=chair_lift | aerialway=drag_lift | aerialway=gondola | aerialway=cable_car    [0x38 resolution 24]

# barrier
barrier=wall | barrier=retaining_wall | barrier=city_wall   [0x32 resolution 24]
barrier=fence       [0x33 resolution 24 continue]
barrier=hedge       [0x34 resolution 24 continue]

# man made
man_made=pipeline   [0x28 resolution 22]

# power
power=line          {name '${voltage} V'}   [0x29 resolution 22]

# natural
natural=coastline   [0x15 resolution 12]
natural=cliff       [0x31 resolution 19]

# waterway
waterway=canal      [0x1f resolution 21]
waterway=drain      [0x1f resolution 22]
waterway=river      [0x1f resolution 18]
waterway=stream     [0x18 resolution 22]
