Search code examples
geolocationmediawikimediawiki-apiwikidata-apiwikimedia-commons

Wikimedia Commons API: search for Commons categories near a location


After reading Wikimedia Commons API search images by (latitude, longitude), I know that we can find pages around a specified location using the MediaWiki API with the GeoData extension. However, I am looking to obtain Commons categories around a specified location via that API - is that doable?

I am also aware that WikiData API does this (as stated at API to get Wikimedia Commons categories that are near a particular latitude/longitude). I have already used that, and am looking for a different API so that I can perform a comparison between the results of the two if possible.


Solution

  • This is moot because Commons has precisely zero categories with geotags (and why would it? how can a category have coordinates?), however the general solution is to filter by category namespace, 14 (full list of namespaces is here). So you take the query from the question you mentioned and modify it with gsnamespace=14:

    https://commons.wikimedia.org/w/api.php?action=query&list=geosearch&gsprimary=all&gsnamespace=14&gsradius=10000&gscoord=51.5|11.95

    You might also want to try looking for galleries in mainspace (gsnamespace=0), maybe there is anything that could interest you.