Geofence places with Overture boundaries
"Is this place inside the city?" comes up everywhere: delivery zones, licensing areas, local news, tax rules, a directory that should only list one borough. Overture's divisions theme has the polygons to answer it, and the API serves them one at a time, so you don't need to download gigabytes of GeoParquet or load a spatial extension into DuckDB to test a handful of points.
This guide tags restaurants and cafés on both sides of the border between Paris and Saint-Ouen-sur-Seine, at Porte de Clignancourt. Paris is one of the demo key's cities, so every request below works as written with DEMO-API-KEY.

/divisions and /places responses. Map: OpenFreeMap, © OpenMapTiles, data © OpenStreetMap contributors.
What you'll build
A small TypeScript module that:
- finds a boundary by name and fetches its polygon
- tests whether a point is inside it, holes and multi-part areas included
- tags every place in a search with the area it belongs to
- tells you which answers to double-check because they sit right on the line
Why not just search divisions by lat/lng?
/divisions accepts lat, lng and radius, so it's tempting to ask it which areas contain a point. In practice that search returns areas near the point, mostly small ones, not every area that contains it. At Porte de Clignancourt, a 2,000 m search returns a single microhood, and Paris itself isn't in the list:
curl -H "x-api-key: DEMO-API-KEY" -X GET -G 'https://api.overturemapsapi.com/divisions' \
-d 'lat=48.9003' -d 'lng=2.3443' -d 'radius=2000' -d 'include_geometry=false'
So for "which city is this in", fetch the boundaries you care about once and test points against them yourself. It's reliable, and after the first request it costs nothing per point.
Step 1: Find the boundary by name
name is a case-insensitive substring match, so narrow it with country and subtype:
curl -H "x-api-key: DEMO-API-KEY" -X GET -G 'https://api.overturemapsapi.com/divisions' \
-d 'name=paris' -d 'country=FR' -d 'subtype=locality'
That returns 11 localities with "paris" somewhere in the name, including Villeparisis, Cormeilles-en-Parisis and Le Touquet-Paris-Plage. Paris itself is fourth, so pick the exact match in code rather than taking the first result:
{
"id": "97b66514-3f41-47ac-a348-9cfd51d983d5",
"bbox": { "xmin": 2.2241, "xmax": 2.4698, "ymin": 48.8156, "ymax": 48.9022 },
"properties": {
"subtype": "locality",
"primary_name": "Paris",
"country": "FR",
"region": "FR-IDF"
}
}
Name searches come back without geometry, which keeps them fast enough for a search box. With your own key you can add include_geometry=true, but polygons can be large, so the next step fetches only the one you chose.
Which subtype to ask for depends on the country. French communes are locality; London boroughs such as Westminster and Camden are county with admin_level: 2. The subtype table lists them all.
Step 2: Fetch the polygon
GET /divisions/{id} always includes the full boundary:
curl -H "x-api-key: DEMO-API-KEY" -X GET \
'https://api.overturemapsapi.com/divisions/97b66514-3f41-47ac-a348-9cfd51d983d5'
The response is a GeoJSON-style feature with a Polygon geometry: 994 positions for Paris, and 214 for Saint-Ouen-sur-Seine (253c259b-1c85-4972-a9ae-e24d36523b43). Some areas come back as a MultiPolygon, so the code below handles both.
In TypeScript (Node 20+ or the browser), the lookup and fetch together:
const API = "https://api.overturemapsapi.com";
const KEY = "DEMO-API-KEY";
type Position = [number, number]; // [lng, lat]
type Ring = Position[];
type Geometry =
| { type: "Polygon"; coordinates: Ring[] }
| { type: "MultiPolygon"; coordinates: Ring[][] };
type BBox = { xmin: number; ymin: number; xmax: number; ymax: number };
type Division = {
id: string;
bbox: BBox;
geometry?: Geometry;
properties: { primary_name: string; subtype: string; country: string; region?: string };
};
async function get<T>(path: string, params: Record<string, string> = {}): Promise<T> {
const res = await fetch(`${API}${path}?${new URLSearchParams(params)}`, {
headers: { "x-api-key": KEY },
});
if (!res.ok) throw new Error(`${path} failed: ${res.status} ${await res.text()}`);
return res.json() as Promise<T>;
}
export async function findDivision(name: string, country: string, subtype: string): Promise<Division> {
const matches = await get<Division[]>("/divisions", { name, country, subtype, limit: "50" });
const exact = matches.find((d) => d.properties.primary_name.toLowerCase() === name.toLowerCase());
if (!exact) throw new Error(`No ${subtype} called ${name} in ${country}`);
return get<Division>(`/divisions/${exact.id}`);
}
Step 3: Test a point against the polygon
The classic ray-casting test needs no library. A point is inside an area when it's inside one of its outer rings and not inside any of that ring's holes. The bbox check first skips the polygon maths for points nowhere near:
function inRing([x, y]: Position, ring: Ring): boolean {
let inside = false;
for (let i = 0, j = ring.length - 1; i < ring.length; j = i++) {
const [xi, yi] = ring[i];
const [xj, yj] = ring[j];
if (yi > y !== yj > y && x < ((xj - xi) * (y - yi)) / (yj - yi) + xi) inside = !inside;
}
return inside;
}
export function contains(area: Division, point: Position): boolean {
const [x, y] = point;
const b = area.bbox;
if (x < b.xmin || x > b.xmax || y < b.ymin || y > b.ymax) return false;
const g = area.geometry;
if (!g) throw new Error("Fetch the division with GET /divisions/{id} to get its geometry");
const polygons = g.type === "Polygon" ? [g.coordinates] : g.coordinates;
return polygons.some(
([outer, ...holes]) => inRing(point, outer) && !holes.some((hole) => inRing(point, hole)),
);
}
Coordinates are [lng, lat], the GeoJSON order, for both the polygon and the point. Mixing that up is the most common reason everything comes back "outside".
If you already use Turf, booleanPointInPolygon does the same job.
Step 4: Tag every place in a search
Fetch the places, then check each one against your areas. The demo key returns 25 results per page, so page through with page until you have the total from the Pagination-Count header:
curl -H "x-api-key: DEMO-API-KEY" -X GET -G 'https://api.overturemapsapi.com/places' \
-d 'lat=48.9003' -d 'lng=2.3443' -d 'radius=500' -d 'taxonomy=food_and_drink' -d 'page=0'
type Place = {
id: string;
geometry: { type: "Point"; coordinates: Position };
properties: { names: { primary: string }; addresses?: { locality?: string }[] };
};
export async function allPlaces(params: Record<string, string>): Promise<Place[]> {
const out: Place[] = [];
for (let page = 0; ; page++) {
const res = await fetch(`${API}/places?${new URLSearchParams({ ...params, page: String(page) })}`, {
headers: { "x-api-key": KEY },
});
if (!res.ok) throw new Error(`/places failed: ${res.status}`);
const batch = (await res.json()) as Place[];
out.push(...batch);
const total = Number(res.headers.get("Pagination-Count") ?? 0);
if (batch.length === 0 || out.length >= total) return out;
}
}
const paris = await findDivision("Paris", "FR", "locality");
const saintOuen = await findDivision("Saint-Ouen-sur-Seine", "FR", "locality");
const areas = [paris, saintOuen];
const places = await allPlaces({
lat: "48.9003",
lng: "2.3443",
radius: "500",
taxonomy: "food_and_drink",
limit: "100",
});
const tally = new Map<string, number>();
for (const place of places) {
const area = areas.find((a) => contains(a, place.geometry.coordinates));
const label = area?.properties.primary_name ?? "outside both";
tally.set(label, (tally.get(label) ?? 0) + 1);
}
console.log(places.length, Object.fromEntries(tally));
// 110 { Paris: 56, 'Saint-Ouen-sur-Seine': 54 }
The 500 m circle around Porte de Clignancourt holds 110 food and drink places: 56 inside Paris and 54 in Saint-Ouen-sur-Seine, home of the flea market. The two polygons share an edge here, just north of the Boulevard Périphérique, so every place lands in exactly one of them.
Step 5: Be careful right on the line
Place coordinates are approximate, and boundaries are drawn by people. Compare the polygon's answer with each place's address and 9 of the 110 disagree. Seven of those are within 25 m of the boundary: four places within 4 m of it on the Paris side give a Saint-Ouen-sur-Seine address, and three just across it say Paris. The other two are plain address errors, 174 m and 502 m from the line.
So for anything with consequences, such as tax or licensing, measure how far each point is from the boundary and flag the close ones for a human:
function metresToSegment([px, py]: Position, [ax, ay]: Position, [bx, by]: Position): number {
const kx = 111_320 * Math.cos((py * Math.PI) / 180); // metres per degree of longitude here
const ky = 110_540; // metres per degree of latitude
const [x1, y1, x2, y2] = [(ax - px) * kx, (ay - py) * ky, (bx - px) * kx, (by - py) * ky];
const [dx, dy] = [x2 - x1, y2 - y1];
const t = Math.max(0, Math.min(1, -(x1 * dx + y1 * dy) / (dx * dx + dy * dy || 1)));
return Math.hypot(x1 + t * dx, y1 + t * dy);
}
export function metresToBoundary(area: Division, point: Position): number {
const g = area.geometry!;
const rings = (g.type === "Polygon" ? [g.coordinates] : g.coordinates).flat();
let best = Infinity;
for (const ring of rings)
for (let i = 0; i < ring.length - 1; i++) best = Math.min(best, metresToSegment(point, ring[i], ring[i + 1]));
return best;
}
const needsReview = places.filter((p) => metresToBoundary(paris, p.geometry.coordinates) < 25);
At Porte de Clignancourt, a 25 m margin flags 17 of the 110 places, including all seven near-the-line disagreements. The flat-earth approximation is fine at these distances. Use a geodesic library if your boundaries are hundreds of kilometres long.
Step 6: Cache the boundaries
Boundaries change rarely, and Overture releases new data monthly. Fetch each polygon once, store it with its id, and refresh it when the data does. The Changelog notes each Overture release as it reaches the API. Testing a point against a cached polygon is a local calculation, so you can tag thousands of places without another request.
Going further
- Pick areas from a map. The search box over a map pattern uses
bboxto keep name searches inside the viewport, then fetches one polygon by ID. - Consistent levels across countries.
admin_levelgives you "state-level" or "county-level" areas where subtype names vary. See By Admin Level. - Whole-country lists. Pull every place of one type and tag it by region with your own key. Pagination explains
page,limitand the headers. - Hand it to a GIS. Export Overture places to GeoJSON and CSV shows
format=geojson, which drops straight onto a map next to your polygons. - The background. Divisions API upgrade: search by name, filter by viewport, fetch by ID covers what the endpoint can do.
That's the whole geofence: look the area up by name, fetch its polygon once, test points locally, and send anything within a few metres of the line for a second look.