Utilising OpenStreetMap to unlock hidden gems for vegetarians

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;
nwrcovers 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 centerthen 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/idbefore 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 tag | Meaning | Stored as |
|---|---|---|
| diet:vegan=only | Kitchen is fully vegan | is_fully_vegan = true |
| cuisine=vegan | Kitchen is fully vegan | is_fully_vegan = true |
| diet:vegan=yes | Vegan options on the menu | is_fully_vegan = false |
| diet:vegetarian=only | Fully vegetarian kitchen | is_fully_vegan = false |
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:
- 21 slugs
Asianjapanese, thai, vietnamese, korean, ramen, sushi, udon, malatang, bubble-tea…
- 10 slugs
Cafécoffee-shop, cafe, tea, bakery, sandwich, breakfast, brunch, pancake…
- 9 slugs
Middle Easternlebanese, levantine, persian, syrian, yemeni, iraqi, jordanian…
- 5 slugs
Indianindian, curry, south-indian, nepalese, pakistani
Two rules handle everything that doesn’t fit a group:
- 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.
- A blocklist. A vegan-friendly kebab shop is still mostly a kebab shop. Cuisines like
steakhouse,seafood,bbqandkebabnever 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.
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_idasnode/123456orway/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:
| Index | Serves |
|---|---|
| GiST on location, active rows only | Every map pan and zoom |
| (status, is_fully_vegan) | The vegan-only toggle |
| restaurant_cuisine (cuisine_id) | Browsing by category |
| GIN trigram on name | Fuzzy search, e.g. “wild” → Wild Larder |
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 OpenStreetMap | Charl | |
|---|---|---|
| Finding vegan places | Write an Overpass query | Open the map |
| Cuisines | Free text, mixed separators | Normalised table + 10 groups |
| Duplicates | One place, many matches | De-duplicated on OSM ID |
| Refreshing the data | n/a | Re-runnable upsert, manual fixes kept |
| Map queries | n/a | Partial 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:
- 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.
- Photos. Most restaurant websites set an
og:imagefor 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. - Menus and price. The
menu,menu_itemandprice_rangecolumns exist, but OSM doesn’t carry price or menu data. Filling them needs a source other than OpenStreetMap.

