<?xml version="1.0" encoding="UTF-8" ?>

<!-- ============================================================
     An XML format file containing Routino tagging rules

     Part of the Routino routing software.
     ============================================================
     This file Copyright 2010-2015, 2018, 2019, 2020, 2021, 2022, 2023 Andrew M. Bishop

     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU Affero General Public License as published by
     the Free Software Foundation, either version 3 of the License, or
     (at your option) any later version.
     ============================================================ -->

<routino-tagging xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                 xsi:noNamespaceSchemaLocation="http://www.routino.org/xml/routino-tagging.xsd">

  <!-- - - - - - - - - - - Node rules - - - - - - - - - - -->

  <node>

    <!-- Add barrier tags to quasi-barriers that are not tagged as barriers -->

    <ifnot k="barrier">

      <if k="entrance">
        <set k="barrier" v="entrance"/>
      </if>

      <if k="railway" v="level_crossing">
        <set k="barrier" v="level_crossing"/>
      </if>

      <if k="ford">
        <set k="barrier" v="ford"/>
      </if>

    </ifnot>

    <!-- Note: The default is that all transport types are allowed past a barrier
               unless it is specifically recognised here; access must be specified
               to disallow each transport type. -->

    <if k="barrier">

      <!-- Barriers that are too generic to determine default access -->

      <if k="barrier" v="door"          > <unset/> </if>

      <if k="barrier" v="gate"          > <unset/> </if>
      <if k="barrier" v="lift_gate"     > <unset/> </if>
      <if k="barrier" v="swing_gate"    > <unset/> </if>
      <if k="barrier" v="sliding_gate"  > <unset/> </if>
      <if k="barrier" v="hampshire_gate"> <unset/> </if>

      <if k="barrier" v="block"         > <unset/> </if>
      <if k="barrier" v="jersey_barrier"> <unset/> </if>
      <if k="barrier" v="debris"        > <unset/> </if>
      <if k="barrier" v="kerb"          > <unset/> </if>

      <if k="barrier" v="chicane"       > <unset/> </if>

      <if k="barrier" v="gap"           > <unset/> </if>
      <if k="barrier" v="entrance"      > <unset/> </if>
      <if k="barrier" v="sally_port"    > <unset/> </if>

      <if k="barrier" v="toll_booth"    > <unset/> </if>
      <if k="barrier" v="border_control"> <unset/> </if>

      <if k="barrier" v="ford"          > <unset/> </if>

      <if k="barrier" v="level_crossing"> <unset/> </if>

      <!-- Barriers that imply no access (as a default) -->

      <if k="barrier" v="wall" > <set v="no_access"/> </if>
      <if k="barrier" v="fence"> <set v="no_access"/> </if>
      <if k="barrier" v="hedge"> <set v="no_access"/> </if>

      <if k="barrier" v="no_access">
        <output k="foot"       v="no"/>
        <output k="horse"      v="no"/>
        <output k="wheelchair" v="no"/>
        <output k="bicycle"    v="no"/>
        <output k="moped"      v="no"/>
        <output k="motorcycle" v="no"/>
        <output k="motorcar"   v="no"/>
        <output k="goods"      v="no"/>
        <output k="hgv"        v="no"/>
        <output k="psv"        v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Barriers that imply foot-only access (as a default) -->

      <if k="barrier" v="kissing_gate"         > <set v="foot_only"/> </if>
      <if k="barrier" v="footgate"             > <set v="foot_only"/> </if>
      <if k="barrier" v="lych_gate"            > <set v="foot_only"/> </if>
      <if k="barrier" v="wicket_gate"          > <set v="foot_only"/> </if>
      <if k="barrier" v="stile"                > <set v="foot_only"/> </if>
      <if k="barrier" v="v_stile"              > <set v="foot_only"/> </if>
      <if k="barrier" v="full-height_turnstile"> <set v="foot_only"/> </if>
      <if k="barrier" v="turnstile"            > <set v="foot_only"/> </if>
      <if k="barrier" v="squeeze"              > <set v="foot_only"/> </if>
      <if k="barrier" v="squeeze_stile"        > <set v="foot_only"/> </if>

      <if k="barrier" v="foot_only">
        <output k="horse"      v="no"/>
        <output k="wheelchair" v="no"/>
        <output k="bicycle"    v="no"/>
        <output k="moped"      v="no"/>
        <output k="motorcycle" v="no"/>
        <output k="motorcar"   v="no"/>
        <output k="goods"      v="no"/>
        <output k="hgv"        v="no"/>
        <output k="psv"        v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Barriers that imply no wheeled access (as a default) -->

      <if k="barrier" v="horse_stile"> <set v="not_wheeled"/> </if>
      <if k="barrier" v="horse_jump" > <set v="not_wheeled"/> </if>
      <if k="barrier" v="step_over"  > <set v="not_wheeled"/> </if>
      <if k="barrier" v="chain"      > <set v="not_wheeled"/> </if>
      <if k="barrier" v="log"        > <set v="not_wheeled"/> </if>
      <if k="barrier" v="tree"       > <set v="not_wheeled"/> </if>
      <if k="barrier" v="fallen_tree"> <set v="not_wheeled"/> </if>
      <if k="barrier" v="bar"        > <set v="not_wheeled"/> </if>

      <if k="barrier" v="not_wheeled">
        <output k="wheelchair" v="no"/>
        <output k="bicycle"    v="no"/>
        <output k="moped"      v="no"/>
        <output k="motorcycle" v="no"/>
        <output k="motorcar"   v="no"/>
        <output k="goods"      v="no"/>
        <output k="hgv"        v="no"/>
        <output k="psv"        v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Barriers that imply no horse access (as a default) -->

      <if k="barrier" v="horse_barrier"> <set v="no_horse"/> </if>
      <if k="barrier" v="cattle_grid"  > <set v="no_horse"/> </if>

      <if k="barrier" v="no_horse">
        <output k="horse"      v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Barriers that imply no motor vehicle access (as a default) -->

      <if k="barrier" v="cycle_barrier"     > <set v="no_motorised"/> </if>
      <if k="barrier" v="motorcycle_barrier"> <set v="no_motorised"/> </if>

      <if k="barrier" v="no_motorised">
        <output k="moped"      v="no"/>
        <output k="motorcycle" v="no"/>
        <output k="motorcar"   v="no"/>
        <output k="goods"      v="no"/>
        <output k="hgv"        v="no"/>
        <output k="psv"        v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Barriers that imply no wide motor vehicle access (as a default) -->

      <if k="barrier" v="bollard"    > <set v="not_2plus_wheels"/> </if>
      <if k="barrier" v="post"       > <set v="not_2plus_wheels"/> </if>
      <if k="barrier" v="car_barrier"> <set v="not_2plus_wheels"/> </if>
      <if k="barrier" v="car_trap"   > <set v="not_2plus_wheels"/> </if>
      <if k="barrier" v="planter"    > <set v="not_2plus_wheels"/> </if>

      <if k="barrier" v="not_2plus_wheels">
        <output k="motorcar"   v="no"/>
        <output k="goods"      v="no"/>
        <output k="hgv"        v="no"/>
        <output k="psv"        v="no"/>

        <unset k="barrier"/>
      </if>

      <!-- Log any remaining, unrecognised, barriers that do not have a generic access permission -->

      <if k="barrier">
        <ifnot k="access">
          <logerror k="barrier" message="no 'access' tag so assuming access='yes' plus tagged restrictions"/>
        </ifnot>
      </if>


      <!-- Normalisation of access tag keys -->

      <ifnot k="foot"      > <if k="access:foot"      > <set k="foot"      /> </if> </ifnot>
      <ifnot k="horse"     > <if k="access:horse"     > <set k="horse"     /> </if> </ifnot>
      <ifnot k="wheelchair"> <if k="access:wheelchair"> <set k="wheelchair"/> </if> </ifnot>
      <ifnot k="bicycle"   > <if k="access:bicycle"   > <set k="bicycle"   /> </if> </ifnot>
      <ifnot k="moped"     > <if k="access:moped"     > <set k="moped"     /> </if> </ifnot>
      <ifnot k="motorcycle"> <if k="access:motorcycle"> <set k="motorcycle"/> </if> </ifnot>
      <ifnot k="motorcar"  > <if k="access:motorcar"  > <set k="motorcar"  /> </if> </ifnot>
      <ifnot k="goods"     > <if k="access:goods"     > <set k="goods"     /> </if> </ifnot>
      <ifnot k="hgv"       > <if k="access:hgv"       > <set k="hgv"       /> </if> </ifnot>
      <ifnot k="psv"       > <if k="access:psv"       > <set k="psv"       /> </if> </ifnot>

      <!-- Normalisation of access tag values -->

      <if v="designated"  > <set v="yes"/> </if>
      <if v="permissive"  > <set v="yes"/> </if>
      <if v="true"        > <set v="yes"/> </if>
      <if v="public"      > <set v="yes"/> </if>
      <if v="official"    > <set v="yes"/> </if>

      <if v="destination" > <set v="no"/> </if>
      <if v="permit"      > <set v="no"/> </if>
      <if v="customer"    > <set v="no"/> </if>
      <if v="customers"   > <set v="no"/> </if>
      <if v="delivery"    > <set v="no"/> </if>
      <if v="residents"   > <set v="no"/> </if>
      <if v="private"     > <set v="no"/> </if>

      <if v="unknown"     > <set v="no"/> </if>
      <if v="construction"> <set v="no"/> </if>
      <if v="unsuitable"  > <set v="no"/> </if>
      <if v="limited"     > <set v="no"/> </if>
      <if v="restricted"  > <set v="no"/> </if>
      <if v="agricultural"> <set v="no"/> </if>
      <if v="forestry"    > <set v="no"/> </if>
      <if v="emergency"   > <set v="no"/> </if>

      <!-- Generic access permissions for all transport types (to override defaults) -->

      <if k="access">

        <ifnot k="access" v="yes">
          <output k="foot"       v="no"/>
          <output k="horse"      v="no"/>
          <output k="wheelchair" v="no"/>
          <output k="bicycle"    v="no"/>
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <if k="access" v="foot">
            <set k="foot" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'foot' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <ifnot k="access" v="no">
            <logerror k="access" message="using 'no'"/>
          </ifnot>

        </ifnot>

      </if> <!-- k="access" -->

      <!-- Generic access permissions for classes of transport types -->

      <if k="vehicle">

        <ifnot k="vehicle" v="yes">
          <output k="bicycle"    v="no"/>
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <ifnot k="vehicle" v="no">
            <logerror k="vehicle" message="using 'no'"/>
          </ifnot>
        </ifnot>

      </if> <!-- k="vehicle" -->

      <if k="motor_vehicle">

        <ifnot k="motor_vehicle" v="yes">
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <ifnot k="motor_vehicle" v="no">
            <logerror k="motor_vehicle" message="using 'no'"/>
          </ifnot>
        </ifnot>

      </if> <!-- k="motor_vehicle" -->

      <!-- Specific access rules (to override the generic ones) -->

      <if k="foot"      > <output/> </if>
      <if k="horse"     > <output/> </if>
      <if k="wheelchair"> <output/> </if>
      <if k="bicycle"   > <output/> </if>
      <if k="moped"     > <output/> </if>
      <if k="motorcycle"> <output/> </if>
      <if k="motorcar"  > <output/> </if>
      <if k="goods"     > <output/> </if>
      <if k="hgv"       > <output/> </if>
      <if k="psv"       > <output/> </if>

    </if> <!-- k="barrier" -->

    <!-- Mini-roundabouts  -->

    <if k="highway" v="mini_roundabout">
      <output k="roundabout" v="yes"/>
    </if>

    <if k="junction" v="roundabout">
      <output k="roundabout" v="yes"/>
    </if>

  </node>

  <!-- - - - - - - - - - - Way rules - - - - - - - - - - -->

  <way>

    <!-- Note: The default is that no transport type is allowed on any highway;
               access must be specified to allow each transport type. -->

    <ifnot k="highway">

      <if k="route" v="ferry">
        <set k="highway" v="ferry"/>
      </if>

      <if k="public_transport" v="platform">
        <set k="highway" v="platform"/>
      </if>

      <if k="railway" v="platform">
        <set k="highway" v="platform"/>
      </if>

    </ifnot>

    <if k="highway">

      <!-- Not useful highway types (future highways) -->

      <if k="highway" v="construction"> <unset/> </if>
      <if k="highway" v="planned"     > <unset/> </if>
      <if k="highway" v="proposed"    > <unset/> </if>

      <!-- Not useful highway types (previous highways) -->

      <if k="highway" v="no"          > <unset/> </if>
      <if k="highway" v="abandoned"   > <unset/> </if>
      <if k="highway" v="disused"     > <unset/> </if>

      <!-- Not useful highway types (limited use highways) -->

      <if k="highway" v="raceway"     > <unset/> </if>

      <!-- Motorway types (includes default access and default properties) -->

      <if k="highway" v="motorway_link">
        <set v="motorway"/>
      </if>

      <if k="highway" v="motorway">
        <output k="highway"/>

        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>
        <output k="multilane"  v="yes"/>
        <output k="oneway"     v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Trunk road types (includes default access and default properties) -->

      <if k="highway" v="trunk_link">
        <set v="trunk"/>
      </if>

      <if k="highway" v="trunk">
        <output k="highway"/>

        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Primary road types (includes default access and default properties) -->

      <if k="highway" v="primary_link">
        <set v="primary"/>
      </if>

      <if k="highway" v="primary">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="no" />
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Secondary road types (includes default access and default properties) -->

      <if k="highway" v="secondary_link">
        <set v="secondary"/>
      </if>

      <if k="highway" v="secondary">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Tertiary road types (includes default access and default properties) -->

      <if k="highway" v="tertiary_link">
        <set v="tertiary"/>
      </if>

      <if k="highway" v="tertiary">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Unclassified road types (includes default access and default properties) -->

      <if k="highway" v="minor">
        <set k="highway" v="unclassified"/>
      </if>

      <if k="highway" v="road">
        <set k="highway" v="unclassified"/>
      </if>

      <if k="highway" v="unclassified">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Residential road types (includes default access and default properties) -->

      <if k="highway" v="living_street">
        <set k="highway" v="residential"/>
      </if>

      <if k="highway" v="residential">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Service road types (includes default access and default properties) -->

      <if k="highway" v="access">
        <set k="highway" v="service"/>
      </if>

      <if k="highway" v="services">
        <set k="highway" v="service"/>
      </if>

      <if k="highway" v="rest_area">
        <set k="highway" v="service"/>
      </if>

      <if k="highway" v="layby">
        <set k="highway" v="service"/>
      </if>

      <if k="highway" v="service">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>
        <output k="moped"      v="yes"/>
        <output k="motorcycle" v="yes"/>
        <output k="motorcar"   v="yes"/>
        <output k="goods"      v="yes"/>
        <output k="hgv"        v="yes"/>
        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Busway types (includes default access and default properties) -->

      <if k="highway" v="bus_guideway">
        <set k="highway" v="busway"/>
      </if>

      <if k="highway" v="bus_stop">
        <set k="highway" v="busway"/>
      </if>

      <if k="highway" v="busway">
        <output k="highway" v="service"/>

        <output k="psv"        v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Track types (includes default access and default properties) -->

      <if k="highway" v="byway">
        <set k="highway" v="track"/>
      </if>

      <if k="highway" v="unsurfaced">
        <set k="highway" v="track"/>
      </if>

      <if k="highway" v="unpaved">
        <set k="highway" v="track"/>
      </if>

      <if k="highway" v="track">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="horse"      v="yes"/>
        <output k="bicycle"    v="yes"/>

        <unset k="highway"/>
      </if>

      <if k="tracktype" v="grade1">
        <output k="paved"      v="yes"/>
      </if>

      <!-- Cycleway types (includes default access and default properties) -->

      <if k="highway" v="cycleway">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="wheelchair" v="yes"/>
        <output k="bicycle"    v="yes"/>

        <output k="paved"      v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Path types (includes default access and default properties) -->

      <if k="highway" v="footway">
        <set k="highway" v="path"/>
      </if>

      <if k="highway" v="platform">
        <set k="highway" v="path"/>
      </if>

      <if k="highway" v="bridleway">
        <set k="highway" v="path"/>

        <output k="horse"      v="yes"/>
        <output k="bicycle"    v="yes"/>
      </if>

      <if k="highway" v="pedestrian">
        <set k="highway" v="path"/>

        <output k="paved"      v="yes"/>
      </if>

      <if k="highway" v="walkway">
        <set k="highway"  v="path"/>

        <output k="paved"      v="yes"/>
      </if>

      <if k="highway" v="trail">
        <set k="highway"  v="path"/>

        <output k="paved"      v="no"/>
      </if>

      <if k="highway" v="path">
        <output k="highway"/>

        <output k="foot"       v="yes"/>
        <output k="wheelchair" v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Steps types (includes default access and default properties) -->

      <if k="highway" v="steps">
        <output k="highway"/>

        <output k="foot"       v="yes"/>

        <unset k="highway"/>
      </if>

      <!-- Ferries -->

      <if k="highway" v="ferry">
        <output k="highway"/>

        <!-- Heuristics for ferries - only a common vehicle type within its category -->

        <if k="foot" v="yes">
          <output k="wheelchair" v="yes"/>
        </if>

        <if k="bicycle" v="yes">
          <output k="foot"       v="yes"/>
          <output k="wheelchair" v="yes"/>
        </if>

        <if k="motorcycle" v="yes">
          <output k="moped" v="yes"/>
        </if>

        <if k="motorcar" v="yes">
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
        </if>

        <if k="goods" v="yes">
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
          <output k="motorcar"   v="yes"/>
        </if>

        <if k="psv" v="yes">
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
          <output k="motorcar"   v="yes"/>
          <output k="goods"      v="yes"/>
        </if>

        <if k="hgv" v="yes">
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
          <output k="motorcar"   v="yes"/>
          <output k="goods"      v="yes"/>
          <output k="psv"        v="yes"/>
        </if>

        <!-- Heuristics for ferries - tag groups instead of individual vehicle types -->

        <if k="access" v="yes">
          <output k="foot"       v="yes"/>
          <output k="horse"      v="yes"/>
          <output k="wheelchair" v="yes"/>

          <set k="vehicle" v="yes"/>
        </if>

        <if k="vehicle" v="yes">
          <output k="bicycle" v="yes"/>

          <set k="motor_vehicle" v="yes"/>
        </if>

        <if k="motor_vehicle" v="yes">
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
          <output k="motorcar"   v="yes"/>
          <output k="goods"      v="yes"/>
          <output k="hgv"        v="yes"/>
          <output k="psv"        v="yes"/>
        </if>

        <unset k="highway"/>
      </if>

      <!-- Unrecognised highway type -->

      <if k="highway">
        <logerror k="highway" message="ignoring it"/>
      </if>

      <!-- Normalisation of access tag keys -->

      <ifnot k="foot"      > <if k="access:foot"      > <set k="foot"      /> </if> </ifnot>
      <ifnot k="horse"     > <if k="access:horse"     > <set k="horse"     /> </if> </ifnot>
      <ifnot k="wheelchair"> <if k="access:wheelchair"> <set k="wheelchair"/> </if> </ifnot>
      <ifnot k="bicycle"   > <if k="access:bicycle"   > <set k="bicycle"   /> </if> </ifnot>
      <ifnot k="moped"     > <if k="access:moped"     > <set k="moped"     /> </if> </ifnot>
      <ifnot k="motorcycle"> <if k="access:motorcycle"> <set k="motorcycle"/> </if> </ifnot>
      <ifnot k="motorcar"  > <if k="access:motorcar"  > <set k="motorcar"  /> </if> </ifnot>
      <ifnot k="goods"     > <if k="access:goods"     > <set k="goods"     /> </if> </ifnot>
      <ifnot k="hgv"       > <if k="access:hgv"       > <set k="hgv"       /> </if> </ifnot>
      <ifnot k="psv"       > <if k="access:psv"       > <set k="psv"       /> </if> </ifnot>

      <!-- Normalisation of access tag values -->

      <if v="designated"  > <set v="yes"/> </if>
      <if v="permissive"  > <set v="yes"/> </if>
      <if v="true"        > <set v="yes"/> </if>
      <if v="public"      > <set v="yes"/> </if>
      <if v="official"    > <set v="yes"/> </if>

      <if v="destination" > <set v="no"/> </if>
      <if v="permit"      > <set v="no"/> </if>
      <if v="customer"    > <set v="no"/> </if>
      <if v="customers"   > <set v="no"/> </if>
      <if v="delivery"    > <set v="no"/> </if>
      <if v="residents"   > <set v="no"/> </if>
      <if v="private"     > <set v="no"/> </if>

      <if v="unknown"     > <set v="no"/> </if>
      <if v="construction"> <set v="no"/> </if>
      <if v="unsuitable"  > <set v="no"/> </if>
      <if v="discouraged" > <set v="no"/> </if>
      <if v="limited"     > <set v="no"/> </if>
      <if v="restricted"  > <set v="no"/> </if>
      <if v="agricultural"> <set v="no"/> </if>
      <if v="forestry"    > <set v="no"/> </if>
      <if v="emergency"   > <set v="no"/> </if>

      <!-- Generic access restrictions for all transport types (to subtract from highway specific defaults) -->

      <if k="access">

        <ifnot k="access" v="yes">
          <output k="foot"       v="no"/>
          <output k="horse"      v="no"/>
          <output k="wheelchair" v="no"/>
          <output k="bicycle"    v="no"/>
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <if k="access" v="foot">
            <set k="foot" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'foot' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <if k="access" v="wheelchair">
            <set k="wheelchair" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'wheelchair' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <if k="access" v="motor_vehicle">
            <set k="motor_vehicle" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'motor_vehicle' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <if k="access" v="hgv">
            <set k="hgv" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'hgv' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <if k="access" v="bus">
            <set v="psv" />
          </if>

          <if k="access" v="psv">
            <set k="psv" v="yes"/>
            <logerror k="access" message="using 'access' = 'no' ; 'psv' = 'yes'"/>
            <set k="access" v="no"/>
          </if>

          <ifnot k="access" v="no">
            <logerror k="access" message="using 'no'"/>
          </ifnot>
        </ifnot>

      </if> <!-- k="access" -->

      <!-- Other access permissions (to add to highway specific defaults with generic restrictions) -->

      <if k="designation">

        <if k="designation" v="restricted_byway">
          <output k="foot"       v="yes"/>
          <output k="horse"      v="yes"/>
          <output k="wheelchair" v="yes"/>
          <output k="bicycle"    v="yes"/>

          <unset k="designation"/>
        </if>

        <if k="designation" v="public_highway">
          <set v="byway_open_to_all_traffic"/>
        </if>

        <if k="designation" v="public_byway">
          <set v="byway_open_to_all_traffic"/>
        </if>

        <if k="designation" v="byway">
          <set v="byway_open_to_all_traffic"/>
        </if>

        <if k="designation" v="byway_open_to_all_traffic">
          <output k="foot"       v="yes"/>
          <output k="horse"      v="yes"/>
          <output k="wheelchair" v="yes"/>
          <output k="bicycle"    v="yes"/>
          <output k="moped"      v="yes"/>
          <output k="motorcycle" v="yes"/>
          <output k="motorcar"   v="yes"/>

          <unset k="designation"/>
        </if>

        <if k="designation" v="permissive_bridleway">
          <set v="bridleway"/>
        </if>

        <if k="designation" v="public_bridleway">
          <set v="bridleway"/>
        </if>

        <if k="designation" v="bridleway">
          <output k="foot"       v="yes"/>
          <output k="horse"      v="yes"/>
          <output k="wheelchair" v="yes"/>
          <output k="bicycle"    v="yes"/>

          <unset k="designation"/>
        </if>

        <if k="designation" v="public_cycleway">
          <output k="foot"       v="yes"/>
          <output k="wheelchair" v="yes"/>
          <output k="bicycle"    v="yes"/>

          <unset k="designation"/>
        </if>

        <if k="designation" v="permissive_footpath">
          <set v="footpath"/>
        </if>

        <if k="designation" v="public_footpath">
          <set v="footpath"/>
        </if>

        <if k="designation" v="footpath">
          <output k="foot"       v="yes"/>
          <output k="wheelchair" v="yes"/>

          <unset k="designation"/>
        </if>

        <if k="designation">
          <logerror k="designation" message="ignoring it"/>
        </if>

      </if> <!-- k="designation" -->

      <!-- Motorroad derived access rules (to override the generic ones) -->

      <if k="motorroad" v="yes">
        <output k="foot"       v="no"/>
        <output k="horse"      v="no"/>
        <output k="wheelchair" v="no"/>
        <output k="bicycle"    v="no"/>
        <output k="moped"      v="no"/>
      </if>

      <!-- Footway/sidewalk derived access rules (to override the generic ones) -->

      <if k="footway" v="use_sidepath">
        <output k="foot"       v="no"/>
      </if>

      <if k="footway">
        <if k="footway" v="sidewalk"> <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="footway" v="both"    > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="footway" v="left"    > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="footway" v="right"   > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="footway" v="yes"     > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>

        <if k="footway" v="crossing"> <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
      </if>

      <if k="sidewalk">
        <if k="sidewalk" v="both"    > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="sidewalk" v="left"    > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="sidewalk" v="right"   > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
        <if k="sidewalk" v="yes"     > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
      </if>

      <if k="sidewalk:both"  v="yes" > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
      <if k="sidewalk:left"  v="yes" > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>
      <if k="sidewalk:right" v="yes" > <output k="foot" v="yes"/> <output k="wheelchair" v="yes"/> </if>

      <!-- Bicycle/cycleway derived access rules (to override the generic ones) -->

      <if k="bicycle" v="use_sidepath">
        <output k="bicycle"    v="no"/>
      </if>

      <if k="cycleway">

        <if k="cycleway" v="lane"       > <output k="bicycle" v="yes"/> </if>
        <if k="cycleway" v="track"      > <output k="bicycle" v="yes"/> </if>
        <if k="cycleway" v="shared_lane"> <output k="bicycle" v="yes"/> </if>
        <if k="cycleway" v="opposite"   > <output k="bicycle" v="yes"/> </if>
        <if k="cycleway" v="crossing"   > <output k="bicycle" v="yes"/> </if>
        <if k="cycleway" v="yes"        > <output k="bicycle" v="yes"/> </if>

        <if k="cycleway" v="opposite_lane">
          <output k="bicycle"       v="yes"/>
          <output k="cyclebothways" v="yes"/>
        </if>

        <if k="cycleway" v="opposite_track">
          <output k="bicycle"       v="yes"/>
          <output k="cyclebothways" v="yes"/>
        </if>

        <if k="cycleway" v="opposite">
          <output k="bicycle"       v="yes"/>
          <output k="cyclebothways" v="yes"/>
        </if>

      </if> <!-- k="cycleway" -->

      <if k="oneway:bicycle" v="no">
        <output k="bicycle"       v="yes"/>
        <output k="cyclebothways" v="yes"/>
      </if>

      <!-- Access restrictions for classes of transport types (to subtract from highway specific defaults and other access permissions) -->

      <if k="vehicle">

        <ifnot k="vehicle" v="yes">
          <output k="bicycle"    v="no"/>
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <ifnot k="vehicle" v="no">
            <logerror k="vehicle" message="using 'no'"/>
          </ifnot>
        </ifnot>

      </if> <!-- k="vehicle" -->

      <if k="motor_vehicle">

        <ifnot k="motor_vehicle" v="yes">
          <output k="moped"      v="no"/>
          <output k="motorcycle" v="no"/>
          <output k="motorcar"   v="no"/>
          <output k="goods"      v="no"/>
          <output k="hgv"        v="no"/>
          <output k="psv"        v="no"/>

          <ifnot k="motor_vehicle" v="no">
            <logerror k="motor_vehicle" message="using 'no'"/>
          </ifnot>
        </ifnot>

      </if> <!-- k="motor_vehicle" -->

      <!-- Specific access rules (to override the generic ones) -->

      <if k="foot"      > <output/> </if>
      <if k="horse"     > <output/> </if>
      <if k="wheelchair"> <output/> </if>
      <if k="bicycle"   > <output/> </if>
      <if k="moped"     > <output/> </if>
      <if k="motorcycle"> <output/> </if>
      <if k="motorcar"  > <output/> </if>
      <if k="goods"     > <output/> </if>
      <if k="hgv"       > <output/> </if>
      <if k="psv"       > <output/> </if>

      <!-- Normalisation of property tags -->

      <if k="surface">

        <!-- Tags from http://wiki.openstreetmap.org/wiki/Key:surface on 2023-08-29 -->

        <if k="surface" v="paved">                 <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="asphalt">               <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="chipseal">              <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="concrete">              <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="concrete:lanes">        <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="concrete:plates">       <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="paving_stones">         <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="sett">                  <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="unhewn_cobblestone">    <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="cobblestone">           <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="brick">                 <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="metal">                 <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="wood">                  <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="rubber">                <set k="paved" v="yes"/> <unset k="surface"/> </if>

        <if k="surface" v="unpaved">               <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="compacted">             <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="fine_gravel">           <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="gravel">                <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="shells">                <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="rock">                  <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="pebblestone">           <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="ground">                <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="dirt">                  <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="earth">                 <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="grass">                 <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="grass_paver">           <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="metal_grid">            <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="mud">                   <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="sand">                  <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="woodchips">             <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="snow">                  <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="ice">                   <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="salt">                  <set k="paved" v="no"/>  <unset k="surface"/> </if>

        <!-- Other tags -->

        <if k="surface" v="bitmac">       <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="chipseal">     <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="tarmac">       <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="bricks">       <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="brick_weave">  <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="slabs">        <set k="paved" v="yes"/> <unset k="surface"/> </if>
        <if k="surface" v="boardwalk">    <set k="paved" v="yes"/> <unset k="surface"/> </if>

        <if k="surface" v="soil">         <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="stones">       <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="stone">        <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="shingle">      <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="pebbles">      <set k="paved" v="no"/>  <unset k="surface"/> </if>
        <if k="surface" v="hardcore">     <set k="paved" v="no"/>  <unset k="surface"/> </if>

        <if k="surface">
          <logerror k="surface" message="ignoring it"/>
        </if>

      </if> <!-- k="surface" -->

      <!-- Bridges -->

      <if k="bridge">
        <ifnot k="bridge" v="no">
          <set k="bridge" v="yes"/>
        </ifnot>
      </if>

      <!-- Tunnels -->

      <if k="tunnel">
        <ifnot k="tunnel" v="no">
          <set k="tunnel" v="yes"/>
        </ifnot>
      </if>

      <!-- Roundabouts -->

      <if k="junction" v="circular">
        <output k="oneway"     v="yes"/>
        <output k="roundabout" v="yes"/>
      </if>

      <if k="junction" v="roundabout">
        <output k="oneway"     v="yes"/>
        <output k="roundabout" v="yes"/>
      </if>

      <!-- Specific property rules (to override the default ones) -->

      <if k="paved"> <output/> </if>

      <if k="lanes"> <output/> </if>

      <if k="bridge"> <output/> </if>

      <if k="tunnel"> <output/> </if>

      <!-- Output the restriction tags -->

      <if k="oneway"> <output/> </if>

      <if k="maxspeed"> <output/> </if>

      <if k="maxweight"> <output/> </if>
      <if k="maxheight"> <output/> </if>
      <if k="maxwidth" > <output/> </if>
      <if k="maxlength"> <output/> </if>

      <!-- Output the name and reference tags -->

      <if k="name"> <output/> </if>
      <if k="ref" > <output/> </if>
      <ifnot k="ref" > <if k="prow_ref" > <output k="ref"/> </if> </ifnot>

      <!-- Output the area tag -->

      <if k="area"> <output/> </if>

    </if> <!-- k="highway" -->

  </way>

  <!-- - - - - - - - - - - Relation rules - - - - - - - - - - -->

  <relation>

    <if k="type">
      <output/>
    </if>

    <!-- Copy route relations -->

    <if k="route">

      <if k="route" v="foot">
        <output k="footroute" v="yes"/>
      </if>

      <if k="route" v="walking">
        <output k="footroute" v="yes"/>
      </if>

      <if k="route" v="hiking">
        <output k="footroute" v="yes"/>
      </if>

      <if k="route" v="foot;bicycle">
        <output k="footroute"    v="yes"/>
        <output k="bicycleroute" v="yes"/>
      </if>

      <if k="route" v="bicycle;foot">
        <output k="footroute"    v="yes"/>
        <output k="bicycleroute" v="yes"/>
      </if>

      <if k="route" v="bicycle">
        <output k="bicycleroute" v="yes"/>
      </if>

    </if> <!-- k="route" -->

    <!-- Pass through turn relations -->

    <if k="restriction">
      <output/>
    </if>

    <if k="except">

      <if k="except" v="bus"> <set v="psv"/> </if>

      <if k="except">
        <output/>
      </if>

    </if>

  </relation>

</routino-tagging>
