Where queries: coordinates

“Where” queries refer to retrieving geographical locations which can be expressed in coordinates. It is then possible to present this information in the form of a map.

We recommend going over the introduction to Wikidata and learning about the structure of Wikidata, as well as the section regarding the simplest query before proceeding.

Let’s start with a simple example: Where did aviation accidents happen?

After running the query, scroll to the results. Above the table, click on the arrow next to the eye. A drop-down menu will pop up. Choose “Map” from the menu, and WDQS will display the locations on a map. You can click on each point to see the item’s label and the associated coordinates.

Another way to display the results in the Map view is to specify it in the query itself. The code on line 2, after the hashtag sign, tells the query that the query results should be shown not as a table, but as a map.

You don’t need to remember the exact code for the map view: thanks to the autocompletion function of WDQS, once you type a hashtag in the query window, a drop-down menu will suggest the different display options.

Linked coordinates

Retrieving coordinates linked to values

In the previous query, coordinates were directly linked to the items we selected. But coordinates are not always directly linked to the items of interest to us. The following query shows the filming locations for each film in the Star Wars series. 

The query gives back the value of P915 property (filming location) for each film. Once you have learned how to retrieve data linked to values, it is quite a straightforward task to retrieve the coordinates for each location:

# A little bit of syntax

A shorter way of formulating the above query is using square brackets to join the two statements on lines 7 and 8. So instead of:
?item wdt:P915 ?location. 
?location wdt:P625 ?coords.

We write:
?item wdt:P915 [wdt:P625 ?coords]. 

What has changed in the results? Why?

The map shows the same locations but because this syntax omits the ?location variable ?locationLabel is empty and the location’s label does not appear.

Another exercise

| Exercise: Write a query to show where the actors in each film in the Star Wars film series were born.

Tip: use DISTINCT to remove duplicates from the results

show solution

Edit the query to add the image (P18) of each actor to the results

show solution

If you’re wondering why there are less results than in the previous query, see the section about the OPTIONAL clause.

Skip to content