Utilising OpenStreetMap to unlock hidden gems for vegetarians

Data EngineeringMobileQ2—2026
Charl's map of London's vegetarian restaurants on two phones

Introduction

Building a map of London's vegan and vegetarian spots that were already tagged but challenging to discover.

Context

Eating out means exploring an area on a phone, checking reviews, cuisines and identifying vegetarian food options. OpenStreetMap already had the dietary tags - they were just messy, duplicated and unideal for mobile users.

Problem solved

700+ restaurants turned from free-text, crowd-sourced tags into one clean map you can pan through on your device.

The Data Already Exists

OpenStreetMap contributors have been tagging London’s restaurants for years, and a surprising number carry dietary tags. diet:vegan=yes for places with vegan options, diet:vegan=only for fully vegan kitchens. The data was there - it just wasn’t in a shape anyone could browse on a phone.

The job was less about building a map and more about turning community data into something reliable enough to put a pin on.

Asking OpenStreetMap the Right Question

OSM data is queried through the Overpass API. The obvious version of the query looks up Greater London by name, but name-based area lookups are expensive and regularly timed out with a 504 on the public servers. Using the numeric area ID for the Greater London relation skips that lookup entirely:

[out:json][timeout:90];
area(3600175342)->.london;
(
  nwr["amenity"~"^(restaurant|cafe)$"]["diet:vegan"~"^(yes|only)$"](area.london);
  nwr["amenity"~"^(restaurant|cafe)$"]["cuisine"="vegan"](area.london);
  nwr["amenity"~"^(restaurant|cafe)$"]["diet:vegetarian"="only"](area.london);
);
out center tags;
  • nwr covers nodes, ways and relations in a single branch, so a restaurant drawn as a building outline is found just like one drawn as a pin. out center then collapses every shape to a single coordinate.
  • Public Overpass servers are shared and occasionally overloaded, so the import tries three mirrors in order before giving up.
  • Results are de-duplicated on type/id before anything touches the database, since one place can match more than one branch.

Each result is then classified from its tags. Only two outcomes matter to the user, so the classification stays deliberately small:

OSM tagMeaningStored as
diet:vegan=onlyKitchen is fully veganis_fully_vegan = true
cuisine=veganKitchen is fully veganis_fully_vegan = true
diet:vegan=yesVegan options on the menuis_fully_vegan = false
diet:vegetarian=onlyFully vegetarian kitchenis_fully_vegan = false
“Vegan” is a dietary signal, not a cuisine, so it's stripped from the cuisine list and drives the flag instead.

Taming the Cuisine Tags

Cuisine strings are split on ;, | and ,, lowercased, and underscores become spaces. Each value becomes a row in a cuisine table with a unique slug, so South_Indian and south indian land on the same row.

That still left dozens of narrow cuisines, far too many for a phone screen. Rather than collapsing them in the database and losing detail, I mapped them to display groups in application code:

  • Asian
    21 slugs

    japanese, thai, vietnamese, korean, ramen, sushi, udon, malatang, bubble-tea…

  • Café
    10 slugs

    coffee-shop, cafe, tea, bakery, sandwich, breakfast, brunch, pancake…

  • Middle Eastern
    9 slugs

    lebanese, levantine, persian, syrian, yemeni, iraqi, jordanian…

  • Indian
    5 slugs

    indian, curry, south-indian, nepalese, pakistani

The database keeps every raw cuisine; the grouping only decides what the browse grid shows.

Two rules handle everything that doesn’t fit a group:

  1. A minimum count. An ungrouped cuisine only gets its own card once it has more than eight restaurants, so the grid isn’t cluttered by one-offs.
  2. A blocklist. A vegan-friendly kebab shop is still mostly a kebab shop. Cuisines like steakhouse, seafood, bbq and kebab never surface as categories, even if the restaurants themselves stay on the map.

Designing the Database

The database is Postgres on Neon, with two extensions: PostGIS for location queries and pg_trgm for fuzzy name search.

Data Pipeline
Run locallyVercel · Next.js 16Overpass API3 mirrorsimport-osm.tsUpsert per elementNeon PostgresPostGIS · pg_trgmrestaurantcuisinerestaurant_cuisinerestaurant_with_cuisinesAPI routes/viewport · /cuisinesBrowserMapLibre · Superclusternwr queryupsertsreadsbounds
The import runs from my machine whenever I want fresh data. The deployed app only ever reads.

Re-runnable imports

OSM changes constantly, so the import had to be safe to run again and again without creating duplicates or wiping out anything I’d fixed by hand.

  • A stable natural key. Each restaurant stores its osm_id as node/123456 or way/789012. The type prefix matters: OSM numbers nodes and ways separately, so the same number can refer to two different places.
  • Upserts that don’t erase. On a re-run, the name, address and location are refreshed from OSM, but phone and website use COALESCE. If OSM drops a value, the one already stored survives.
  • Stable URLs. Every restaurant gets a slug. When two places share a name, the slug gains the postcode area (-e1, -sw9), then the tail of the OSM ID as a last resort. Once assigned, a slug never changes on re-import.
  • One transaction per restaurant. A bad row rolls back on its own and is logged, and the rest of the import carries on.

The import reports inserts and updates separately using Postgres’s xmax = 0 trick on RETURNING. That way every run tells me how much of London changed since the last one.

Indexing for the map

Every interaction on the map is either “what’s in this rectangle?” or “what’s in this rectangle, filtered?” The indexes are built around those two questions:

IndexServes
GiST on location, active rows onlyEvery map pan and zoom
(status, is_fully_vegan)The vegan-only toggle
restaurant_cuisine (cuisine_id)Browsing by category
GIN trigram on nameFuzzy search, e.g. “wild” → Wild Larder
The spatial index is partial (WHERE status = 'active'), so closed restaurants never take up space in it.

The map asks for restaurants inside the visible rectangle using PostGIS’s && bounding-box operator, instead of a distance search with ST_DWithin. A rectangle check is answered straight from the GiST index without calculating any distances, which is all a map viewport needs.

A view, restaurant_with_cuisines, folds each restaurant’s cuisines into an array on the row itself, so each query gets one row per pin with its cuisines attached, and the join is written once instead of in every query. The queries are covered by Jest tests running against a seeded fixture of ten restaurants, which check radius edges, distance ordering and filter combinations.

Testing It on the Street

What the MVP caught:

  • Slow, jittery panning. Every tiny map movement fired a new request. A 400 ms debounce now waits until the map settles before fetching.
  • Pins vanishing when zoomed in. Clustering stopped at zoom 14, so zooming further could leave restaurants hidden inside a cluster that never broke apart. Raising the cluster limit to zoom 20 fixed it.
  • Restaurants missing at the screen edges. This one was my own doing. To make cached responses easier to share, I’d rounded the viewport bounds to two decimal places (about 1 km). Rounding could pull any edge of the rectangle in by up to half a kilometre, so restaurants near the edge of the screen disappeared. I reverted it the next day. A cache hit isn’t worth a missing restaurant.
  • Empty lists with no explanation. Category lists now show a loading state, so a slow request no longer looks like an empty result.

tldr;

Raw OpenStreetMapCharl
Finding vegan placesWrite an Overpass queryOpen the map
CuisinesFree text, mixed separatorsNormalised table + 10 groups
DuplicatesOne place, many matchesDe-duplicated on OSM ID
Refreshing the datan/aRe-runnable upsert, manual fixes kept
Map queriesn/aPartial GiST index, bounding box

Takeaways

The schema was designed for more than the app currently shows, and these are the next layers I’d switch on:

  1. Community mentions from Reddit. A script already searches five subreddits for London vegan restaurant threads. It matches restaurant names with word boundaries so “Halo” doesn’t match “Shallot”, and stores each mention with a rough sentiment score. Before this goes in the UI it needs better matching, because short or generic restaurant names produce false positives.
  2. Photos. Most restaurant websites set an og:image for link previews. A polite crawler (8 s timeout, 300 ms between requests, <head> only) can store that image against the restaurant without needing an API key.
  3. Menus and price. The menu, menu_item and price_range columns exist, but OSM doesn’t carry price or menu data. Filling them needs a source other than OpenStreetMap.