User:PAC2/Longest watercourses in France

This page is a documented query. All documented queries can be found in Category:Documented query.

This query looks at the longest natural watercourses (natural watercourse (Q55659167)) in France. It is adapted by an example in the SPARQL wikibook[1].

Of course, the query can easily be adapted to any other country.

Context edit

Query edit

We select all instances of natural watercourse (Q55659167) whose value of country (country (P17)) is France (Q142) and with a value of length (P2043).

length (P2043) statements provide a quantity with a value and a unit (ie meter, kilometer, etc). So we get the quantity amount (?length) with the quantity unit (?unit).

Most of the times, the quantity is in kilometers but we've found some examples in meters. So we need to convert all quantities to the same unit. We use conversion to SI unit (P2370) to convert every quantity to the international system unit : metre (Q11573). This gives us the ?conversion parameter which can then be used to compute the length in meter. We divide it per thousand to get the length in kilometer for all watercourses.

Variables :

  • ?item : qid if the watercourse
  • ?itemLabel : label of the watercourse in your preferred language or in English
  • ?length : length of the watercourse
  • ?unit : original qid if the unit
  • ?unitLabel : original label of the unit
  • ?length_in_km : length in kilometers
#title: Longest rivers in France
SELECT DISTINCT ?item ?itemLabel ?length ?unit ?unitLabel ?length_in_km WHERE {
  ?item (wdt:P31/(wdt:P279*)) wd:Q55659167;
    wdt:P17 wd:Q142;
    p:P2043 ?length_statement.
  ?length_statement psv:P2043 ?length_value.
  ?length_value wikibase:quantityAmount ?length;
    wikibase:quantityUnit ?unit.
  ?unit p:P2370 ?unit_statement.
  ?unit_statement psv:P2370 ?unit_value.
  ?unit_value wikibase:quantityAmount ?conversion;
    wikibase:quantityUnit wd:Q11573.
  BIND(?length * ?conversion / 1000 AS ?length_in_km)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
ORDER BY DESC (?length_in_km)
LIMIT 100
Longest rivers in France

Tests and checks edit

Insights edit

References edit

See also edit