From 6a5d5d0c2fafbb087818b6cf0c1ccd3060ea4f73 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 19 Apr 2026 14:07:05 +0100 Subject: [PATCH] Extend nearest-polygon fallback to all countries, not just Scotland Points in the sea near England (or any other country) now fall back to Polygon.nearest() to find the closest admin_level>=7 polygon on land, giving a specific civil parish or district instead of just returning England (Q21). Closes #30 --- lookup.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lookup.py b/lookup.py index 9c6ad53..76c1745 100755 --- a/lookup.py +++ b/lookup.py @@ -151,6 +151,13 @@ def lat_lon_to_wikidata( if not nearby_result.get("missing"): return {"elements": elements, "result": nearby_result} + # For points in the sea near any coast (e.g. England), try nearest polygon + nearest = model.Polygon.nearest(lat, lon) + if nearest: + nearby_result = do_lookup([nearest], lat, lon) + if not nearby_result.get("missing"): + return {"elements": elements, "result": nearby_result} + if not needs_commons: # Direct lookup: find Wikidata items whose P402 (OSM relation ID) matches # one of the OSM polygons that contain this point.