# Avoid routing segments

A routing segment is a topology segment that represents a section of road or an otherwise linear, navigable stretch (see Segment).

The following will describe how to avoid routing segments with some examples.

## Avoid segment of the returned route

If a route is calculated with the span=segmentRef specified, the returned route (blue line at Figure 1) would include a list of segment spans.

The following command can be used to calculate a list of segment spans between the given origin and destination:

curl -X GET \
'https://router.hereapi.com/v8/routes?origin=45.484661,9.228382&destination=45.485542,9.234576&return=polyline&spans=segmentRef&transportMode=car&apikey={YOUR_API_KEY}'


It returns the follwing list of segment spans:

{
"routes": [
{
"sections": [
{
"type": "vehicle",
"departure": {},
"arrival": {},
"polyline": "BG8vl42CwvqzR8D4X0FgoB8Lk1B0FwbqEoR",
"refReplacements": {
"0": "hrn:here:data::olp-here:rib-2:3217:",
"1": "here:cm:segment"
},
"spans": [
{
"offset": 0,
"segmentRef": "$0:377570872:$1:76764732#+0.6376674544619554..1"
},
{
"offset": 1,
"segmentRef": "$0:377570872:$1:89214839#+0..1"
},
{
"offset": 2,
"segmentRef": "$0:377570872:$1:95058600#+0..1"
},
{
"offset": 3,
"segmentRef": "$0:377570872:$1:82740696#+0..1"
},
{
"offset": 4,
"segmentRef": "$0:377570872:$1:96835127#+0..0.626940133196055"
}
],
"transport": {
"mode": "car"
}
}
]
}
]
}


The segment at offset 2 has segmentId and direction specified as \$1:95058600#+, which converts to here:cm:segment:95058600#+ with the help of the refReplacement parameter. If this segment has to be avoided in both directions, then the route request should include avoid[segments]=here:cm:segment:95058600 without the direction part:

Note: More on constructing the complete HRN using refReplacement is described on the Referencing HERE Map Content entities page.

curl -X GET \
'https://router.hereapi.com/v8/routes?origin=45.484785,9.229564&destination=45.485299,9.232146&avoid[segments]=here:cm:segment:95058600&return=polyline&spans=segmentRef&transportMode=car&departureTime=any&apikey={YOUR_API_KEY}'


And the returned route with avoidance (purple line at Figure 1) would go around the avoided segment.

Tip: Calculating a tiny route over one or few segments would allow to learn the ID of those segments and their direction when part of the route.

## Avoid segment of the map in the specific direction

Assume a user would like to avoid traveling a certain road in a certain direction e.g. from east to west (see Figure 2).

When fetching this segment from the map (see Segment) the user gets a segment ID as well as the geometry and the start and end nodes:

{
"identifier": "here:cm:segment:95058600",
"geometry": [
{
"latitude": 45.48495,
"longitude": 9.23058,
"z_level": 0,
"elevation": 0
},
{
"latitude": 45.48514,
"longitude": 9.23143,
"z_level": 0,
"elevation": 0
}
],
"length": 69.72647,
"startNode": {
"identifier": "here:cm:node:66488603",
"geometry": {
"latitude": 45.48495,
"longitude": 9.23058,
"z_level": 0,
"elevation": 0
}
},
"endNode": {
"identifier": "here:cm:node:66488604",
"geometry": {
"latitude": 45.48514,
"longitude": 9.23143,
"z_level": 0,
"elevation": 0
}
}
}


Positive direction of the segment corresponds to travelling from the start node to the end node. Since longitude of the start node is smaller than of the end node, then positive direction corresponds to travelling from west to east. To avoid traveling on this segment from east to west this segment should be avoided in the negative direction avoid[segments]=here:cm:segment:95058600#-:

curl -X GET \
'https://router.hereapi.com/v8/routes?origin=45.485299,9.232146&destination=45.484785,9.229564&avoid[segments]=here:cm:segment:95058600#-&return=polyline&spans=segmentRef&transportMode=car&departureTime=any&apikey={YOUR_API_KEY}'