{% extends "base.html" %} {% block title %}Geocode to Commons{% endblock %} {% block style %} {% endblock %} {% block content %}

Geocode to Commons Category

Convert latitude/longitude to a Wikidata item and Wikimedia Commons category.

Interactive map ↗ — click any location to geocode it.

How it works
{% for step in [ ("Find OSM polygons", "Query PostGIS for all polygons that contain the given point."), ("Sort by admin level", "Order polygons by admin_level descending — most specific first."), ("Check wikidata tag", "For each polygon, look for a wikidata tag and resolve the Commons category."), ("Check ref:gss tag", "If no wikidata tag, try ref:gss and look up the matching Wikidata item via WDQS."), ("Match by name", "Try finding a nearby Wikidata item with the same name using WDQS."), ("Return result", "Return the most specific Wikidata QID and Commons category found.") ] %}
{{ loop.index }}
{{ step[0] }}
{{ step[1] | safe }}
{% endfor %}
API

GET /?lat=<lat>&lon=<lon>

Returns JSON with the Wikidata item and Commons category for the given coordinates.

Parameter Values Description
lat decimal degrees Latitude
lon decimal degrees Longitude
needs_commons true (default)
false
When true, only returns a result if a Wikimedia Commons category can be found. When false, returns the best matching Wikidata item even if it has no Commons category — matched by OSM relation or way ID via the Wikidata Query Service.
Example response
{
  "wikidata": "Q184618",
  "commons_cat": {
    "title": "County Tipperary",
    "url": "https://commons.wikimedia.org/wiki/Category:County_Tipperary"
  },
  "admin_level": 6,
  "coords": { "lat": 52.41037, "lon": -7.84651 }
}
Examples
{% for lat, lon, name in samples %} {% endfor %}
Place Coordinates Links
{{ name }} {{ lat }}, {{ lon }} detail API

Source code: https://git.4angle.com/edward/geocode

{% endblock %}