# Avoid routing zones

A routing zone is a group of roads that share the same regulations. Currently, three zone categories are supported, namely vignette, congestionPricing and environmental (see API Reference for more details). vignette roads are found in some European countries. The system works based on payment for a fixed time period (for example, one year). A traveler may want to avoid those roads to save the annual cost for occasional crossings. congestionPricing zones are another category of routing zones that consists of roads usually in the city centers, airports, bridges, or other busy areas. It is used to mitigate traffic congestion by charging a higher price in rush hours. environmental zones, on the other hand, are designed to improve air quality in urban areas by excluding vehicles under certain pollution standards from entering them.

For each category, there are multiple instances. For example, most cities in Germany have their own environmental zones. Each zone instance has its unique ID to identify it respectively.

Information about the various routing zones originates from the respective catalogs of platform.here.com. For example https://platform.here.com/data/hrn:here:data::olp-here:rib-2/environmental-zones/overview for Environmental Zones. If you do not have access to the platform catalogs then you can use the routing response to get this information.

A route can be planned avoiding certain categories of zones or certain instances of zones. Specifically, there are three ways to use the API:

1. avoid zones by category
2. avoid zones by ID
3. avoid zones by category except for certain IDs

The following will describe how to use them with some examples.

## Routing zones in the response message

Before jumping into the details, let's have a look at the routing zones in the response message. This is one possible way to get the zone IDs for avoidance.

If a route passes multiple routing zones, the involved routing zones can be found in routingZones section of the response message, provided the parameter routingZones is passed in the return option. For example return=travelSummary,summary,polyline,routingZones.

One example of routingZones section, in a route passing through Berlin, looks like

    "routingZones": [
{
"name": "BERLIN UMWELTZONE",
"type": "environmental",
"ref": "$0:all:$1:2"
},
{
"name": "BRÜCKENSTRASSE DIESELFAHRVERBOT",
"type": "environmental",
"ref": "$0:all:$1:262"
},
{
"name": "HERMANNSTRASSE DIESELFAHRVERBOT",
"type": "environmental",
"ref": "$0:all:$1:267"
}
]


In the response message, the name and type fields of the zones can be obtained. The type of a routing zone is its category, which is described above. The ref field is a compressed form of the ID of the zone. It can be interpreted along with the refReplacements section, which is included in the same response message:

    "refReplacements": {
"0": "hrn:here:data::olp-here:rib-2:2673:environmental-zones",
"1": "here:cm:envzone"
}


For example, to find out the ID of the first routing zone in the response, just check the last part of the ref field "ref": "$0:all:$1:2", which is $1:2". By replacing $1 with here:cm:envzone according to the refReplacements section, the zone ID here:cm:envzone:2 is obtained. Similarly, the IDs for the rest of the zones can be retrieved as here:cm:envzone:262 and here:cm:envzone:267. Avoiding the zones with those IDs will be described later in this page.

Additionally, the location of the zones along the route can be extracted with option span=routingZones. The information can be used to, for example, visualize the route polyline with routing zone highlighted.

## Avoid zones by category

In some cases, the user may want to avoid the entire category of the zones. This can be done with avoid[zoneCategories] option. For example, the following command can be used to avoid Berlin environmental zones by avoiding all zones of type environmental:

curl -X GET \
'https://router.hereapi.com/v8/routes?destination=52.451857,13.41379&origin=52.565889,13.417365&transportMode=car&avoid[zoneCategories]=environmental&apikey={YOUR_API_KEY}'


The blue line in the above image shows the route that avoids all the environmental zones. By comparison, the pale blue line shows the route which passes through the city without avoidance.

### Note

You can replace the avoidance option with avoid[zoneIdentifiers]=here:cm:envzone:2. here:cm:envzone:2 is the ID referring to "BERLIN UMWELTZONE", which dominates the central area of Berlin, so that avoiding this zone effectively avoids the environmental zone in this case.

For a request that demonstrates how to get an ID, see Get routing zone ID.

## Avoid zones by their IDs

In the above example, the avoidance option can be replaced with avoid[zoneIdentifiers]=here:cm:envzone:2. here:cm:envzone:2 is the ID referring to "BERLIN UMWELTZONE", which dominates the central area of Berlin, so that avoiding this zone effectively avoids the environmental zone in this case.

## Get routing zone ID

One possible way to get the zone IDs for avoidance is to obtain them from the routingZone blocks in the response message.

If a route passes multiple routing zones, you can find the involved routing zones in the routingZones section of the response message, provided you specified the parameter routingZones in the return option, for example return=travelSummary,summary,polyline,routingZones.

This request specifies a routingZones section in a route passing through Berlin as follows:

    "routingZones": [
{
"name": "BERLIN UMWELTZONE",
"type": "environmental",
"ref": "$0:all:$1:2"
},
{
"name": "BRÜCKENSTRASSE DIESELFAHRVERBOT",
"type": "environmental",
"ref": "$0:all:$1:262"
},
{
"name": "HERMANNSTRASSE DIESELFAHRVERBOT",
"type": "environmental",
"ref": "$0:all:$1:267"
}
]


In the response message, the name and type fields of the zones can be obtained. The type of a routing zone is its category, which is described above. The ref field is a compressed form of the ID of the zone. It can be interpreted along with the refReplacements section, which is included in the same response message:

    "refReplacements": {
"0": "hrn:here:data::olp-here:rib-2:2673:environmental-zones",
"1": "here:cm:envzone"
}


For example, to find out the ID of the first routing zone in the response, just check the last part of the ref field "ref": "$0:all:$1:2", which is $1:2". By replacing $1 with here:cm:envzone according to the refReplacements section, the zone ID here:cm:envzone:2 is obtained. Similarly, the IDs for the rest of the zones can be retrieved as here:cm:envzone:262 and here:cm:envzone:267. Avoiding the zones with those IDs will be described later in this page.

Additionally, the location of the zones along the route can be extracted with option span=routingZones. The information can be used to, for example, visualize the route polyline with routing zone highlighted.

# Avoid zone category with exceptions

In case that permission is granted to access some zones in a category but not all of them, the route can be planned using avoidance of a zone category with some exceptions.

For example, there is a driving ban on a few streets for diesel vehicles including cars in Berlin. Suppose an owner of a diesel car is a resident in one of the affected areas, say Leipzigerstraße, which is on the list of diesel driving ban. A route for this driver needs to avoid all other DIESELFAHRVERBOT zones except Leipzigerstraße. This can be done by avoiding all environmental zones except BERLIN UMWELTZONE and LEIPZIGER STRASSE DIESELFAHRVERBOT.

The avoidance option in this case is avoid[zoneCategories]=environmental;exceptZoneIds=here:cm:envzone:2,here:cm:envzone:261.

The blue line in the above image shows the route that passes through Leipzigerstraße using the avoidance option with an exception, while the pale blue route is planned without exception.