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
This commit is contained in:
Edward Betts 2026-04-19 14:07:05 +01:00
parent 76437d5240
commit 6a5d5d0c2f

View file

@ -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.