Close a road in the request, not in your map data
MapMap's POST /route, POST /isochrone and POST /matrix all accept
exclude_polygons: a list of rings whose intersecting roads are cut out of the
search for that one request, against the same graph everything else uses. Drop a
300 m box over Worcester's only city-centre crossing of the Severn and a car
journey from Henwick to a school on the east bank goes from 2,353 m and 341
seconds to 10,680 m and 1,096 seconds. Two requests, no rebuild, no second copy
of the data.
What do exclude_polygons and exclude_locations actually do?
They remove roads from one request's search space and nothing else.
exclude_polygons takes an array of exterior rings, each ring an array of
[lon, lat] pairs (longitude first, the GeoJSON order), and every road
intersecting any ring is excluded from path finding for that request.
exclude_locations takes {lat, lon} objects, each matched to its nearest
road, which is then excluded; closing 2,000 places in one route request
covers that half in detail, including the exclusions block that says what
each place closed. This post is about the polygons, and about asking the
what-if question of a whole network rather than of one route. Both are Valhalla
common request options, so they mean the same thing on every service that
carries them. Nothing
is written, nothing persists: the next request sees the untouched graph.
That matters because the usual way to answer "if we shut this area, what breaks" is to delete the ways from your own extract, re-run the tile build, stand up a second engine, and query that. It is slow, and it drifts from the graph your live traffic is using. A control room asking whether the diversion plan holds needs the answer in seconds, on the same data that produced the baseline.
Which endpoints take them?
The direct routing surfaces, but not the ones that compute matrices on your behalf.
| Surface | exclude_polygons | exclude_locations |
|---|---|---|
POST /route | Yes, in the JSON body | Yes, in the JSON body |
POST /isochrone | Yes, in the JSON body | Yes, in the JSON body |
POST /matrix and the async POST /v1/jobs/matrix | Yes, in the JSON body | Yes, in the JSON body |
GET /route/v1/{profile}/{coordinates} (OSRM-compatible) | Yes, as a JSON query parameter | Yes, as lon,lat pairs separated by ; |
| Mapbox Directions-compatible endpoint | Yes | Yes |
MCP tools route, matrix, reachable_area | Yes | No |
POST /optimise, POST /route/along, POST /v1/fuel/along, POST /v1/charging/along | No | No |
POST /route carried both already. We added them to /isochrone and /matrix
so the two questions a planner actually asks, what is still reachable and what
does every pair now cost, can be asked of a hypothetical network. The
analysis endpoints documentation covers the rest of the
request shape for both, and the MCP server exposes the same option to agents.
What does a closed-bridge matrix request look like?
One extra field on the body you already send. Here is the closure over Worcester Bridge, with one origin on the west bank and two east-bank destinations:
export BASE=https://api.mapmap.ai
export API_KEY=snk_...
curl -fsS -X POST "$BASE/matrix" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"sources": [{ "lat": 52.198, "lon": -2.243 }],
"targets": [
{ "lat": 52.1946, "lon": -2.2231 },
{ "lat": 52.1927, "lon": -2.1783 }
],
"costing": "auto",
"exclude_polygons": [
[
[-2.229, 52.1895], [-2.2245, 52.1895], [-2.2245, 52.1918],
[-2.229, 52.1918], [-2.229, 52.1895]
]
]
}'
The response shape is unchanged: row-major durations in seconds and
distances in metres, durations[i][j] from sources[i] to targets[j].
{
"durations": [[1095.986, 836.925]],
"distances": [[10680.0, 11737.0]]
}
Send the same body without exclude_polygons and you get the baseline,
{"durations": [[340.723, 742.94]], "distances": [[2353.0, 5541.0]]}. The
difference between the two grids is the answer: the school run more than
quadruples in distance and takes more than three times as long, while the
hospital trip, which was already heading for a different crossing, adds about
a minute and a half. Both grids were measured on the production graph on 25
November 2026.
The responses also carry an eta_calibration block, because car times on
local roads in Great Britain include the junction and congestion delay a
typical car meets, from Department for Transport statistics, on top of the
engine's free-flowing time. The engine's own figures sit alongside in
eta_calibration.engine_durations ([[237.0, 464.0]] open, [[756.0, 735.0]]
closed), so you can compare like with like if your model works in free-flow
time.
POST /isochrone takes the identical field, so the same ring turns "where can a
depot reach in 20 minutes" into "where can it reach with that crossing shut",
one contour per call. Truck isochrones and their billing are covered in
isochrones billed one call per contour.
What happens when the exclusion makes a destination unreachable?
You get an honest null, not a large number. We widened the ring to a box of
roughly 1 km around the east-bank destination, and the grid came back as
{"durations": [[null]], "distances": [[null]]}. Unreachable pairs are always
null, never a sentinel cost, so a closure that isolates a destination shows up
as a hole in the grid rather than a plausible-looking long journey.
POST /route answers the same way in its own terms. When the exclusion leaves
no path, you get HTTP 400 application/problem+json with
type: urn:sn-gateway:problem:upstream-error and a detail that starts "No
path could be found for input" and says the snap was not widened because the
request excludes places.
That last part matters when you draw closures. Without exclusions, a NoRoute is
retried once with a wider snap (a 1,000 m radius and a minimum_reachability of
500 at every location that did not set its own), so a lorry whose destination
snapped into a truck-restricted town core still gets a route, and the answer
carries a snap_retry block saying how far each point moved. With exclusions
that retry is never sent: it would move a stop inside your closure to the
nearest open road outside it, and the route would reach a place you had cut
off.
What do the caps and the calls cost?
The caps are per request and enforced on every surface: 50 exclude_polygons
rings, 500 vertices in total across all rings, 10 km of ring perimeter in
total, and 2,000 exclude_locations on a route (50 on a matrix or an
isochrone). A ring smaller than 1 m² is refused as degenerate. Exceed one and
you get a 400 naming the field and the count, before any routing work starts. On the OSRM-compatible endpoint the same caps come back in OSRM's
own error envelope:
{
"code": "InvalidValue",
"message": "exclude_polygons has 51 rings, over the limit of 50 per request"
}
Vertices and perimeter are capped as well as rings because they, not the ring
count, bound the work the engine does to find the roads inside. Every vertex is checked as a finite
in-range [lon, lat] pair, and the error names the offending one, for example
exclude_polygons[0][0].
Billing does not change. A matrix bills one call per started block of 25
elements (sources × targets), capped at 10,000 elements per request; an
isochrone bills one call per contour, maximum 4 per request. An exclusion adds
nothing to that, so a before-and-after comparison costs exactly twice the call it
would have cost anyway. On the hosted gateway that is Standard class at 0.05p
per call from 50,001 to 1,000,000 calls a month, or Premium at 1p when the body
carries "costing": "truck", after a free tier of 50,000 standard calls a month.
A self-hosted deployment has no per-call charge (the quota and rate limit are
the ones you set on the key), which is what makes sweeping a hundred candidate
closures practical as a batch job.
What this does not do
An exclusion is a hard cut, not a penalty. There is no weight and no "avoid if
reasonable" form of it: a road inside the ring is gone for that request, and if
the only legal path ran through it you get an error rather than an expensive
route. Soft preferences live in costing_options, a different mechanism with
different semantics.
The rest of the honest list:
- Not on
/optimiseor the along-route searches. They compute matrices internally and pass no caller exclusions (/optimiseuses rings only for its own clean-air zone avoidance), so you cannot yet re-solve a day's stop order under a closure in one call. Compute the closed matrix yourself and feed it to your own solver, or read route optimisation over a truck-aware matrix for what the endpoint does today. - Valhalla engine only. A deployment configured with
SN_ROUTING_ENGINE=graphhopperdrops both fields silently, because GraphHopper can express avoid-areas only throughcustom_model.areasand our adapter does not synthesise them. Silently is the accurate word, which is why the MCP tool descriptions say so out loud. - Only the nested-array ring form. Valhalla's alternative
FeatureCollectionform ofexclude_polygonsis not modelled, so you cannot post a GeoJSON feature straight from a GIS export without reshaping it to rings. - Longitude first, and a swap can be invisible. A UK lat/lon swap puts 51.5 in the longitude slot and -0.1 in the latitude slot. Both are in range, so validation passes and your polygon sits in the sea, avoiding nothing. We reject swaps only when they push a value out of range.
- Matrix cells can be upper bounds. Valhalla's cost matrix stops improving
a pair a bounded number of edge pops after the first connection, while
/routeextends until it can prove the optimum. We have measured a matrix cell 9.4 per cent longer than the same/routeleg on the production graph. On the short Worcester pairs above the two agree to within a second. Use a closed matrix for the shape of the damage, and/routefor the number you quote. - Documented once, not in every endpoint's table.
Avoiding areas and points
carries the shapes, caps and unreachable-target behaviour for every surface.
The OpenAPI document at
GET /openapi.jsoncarries the full schema, and it is authoritative where the two disagree.
Try it
The Worcester bridge-closure demo is public. It closes
Worcester Bridge with exactly the ring shown above and recomputes six
hypothetical journeys live through POST /route, baseline as a dashed ghost,
diversion solid, with a receipt of what each one costs. Two rows run the same
journey as a car and as an 18 t rigid, because the northern crossing takes one
and not the other. Drag a rectangle anywhere on the map and it becomes a second
exclude_polygons ring.
The journeys are archetypes, the closures are simulated, and the times are engine estimates rather than a forecast. The map is rendered from OpenStreetMap data, so credit © OpenStreetMap contributors when you render it yourself.
