Wikimedia Developer Support

Geo API: how to filter results by type?

Hi all,

I’m currently attempting to get a list of articles near a set of coordinates (e.g. inside a bounding box in a map).

Ultimately I’d like an API call that can answer the question “What are (e.g.) museums/landmarks in this bounding box?”.

I’ve thus far identified 2 ways to do it, but both techniques have their shortcomings.

Technique 1 – GET’ting the following URL:

https://en.wikipedia.org/w/api.php?colimit=50&generator=search&action=query&prop=coordinates|pageimages|description|pageprops&gsrlimit=50&pithumbsize=240&ppprop=displaytitle&format=json&coprop=type|dim&piprop=thumbnail&pilimit=50&gsrsearch=nearcoord%3A1222946m,31.500,-100.469

returns a list of articles sorted as “top links”, but I’m not sure how I can limit the results to those of type “landmark”.

Technique 2 – Using SPARQL:

SELECT ?place ?placeLabel ?location
WHERE {
  ?link schema:isPartOf <https://en.wikipedia.org/>;
  SERVICE wikibase:box {
    ?place wdt:P625 ?location.
    bd:serviceParam wikibase:cornerSouthWest "Point(-99.19583534720724 31.360033395287584)"^^geo:wktLiteral.
    bd:serviceParam wikibase:cornerNorthEast "Point(-98.68085116910731 32.05052263746356)"^^geo:wktLiteral.
  }
  ?place wdt:P31 wd:Q33506.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
  }
LIMIT 50

I can effectively filter by “museum”, but 1) the query is very slow to compute and 2) I’m not sure how I can sort by top links. A lot of the results I get are secondary (e.g. less popular museums).

Thank you!

There is a haswbstatement search keyword but it only works on Wikidata. So you could use the Wikidata search API to search for nearcoord:1222946m,31.500,-100.469 haswbstatement:P31=Q33506, but you’d have to figure out a different way to get the extra data like pageimages, or make a second query to en.wikipedia.