0

I would like to know the simplest way to handle units of distance in Sparql. In this Wikidata example I would like to select all the mountains over 8000m; however when I run the text below it also includes all of the mountains over 8000ft. Is it possible to specify that the units I am interested is meters, and for the mountains that are specified in feet, is a conversion to meters necessary?

#Mountains Over 8000m
SELECT ?mountainLabel ?height 
WHERE 
{
  ?mountain wdt:P31 wd:Q8502. 
  ?mountain wdt:P2044 ?height.

  FILTER(8000 <= ?height)

  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en, de". }
}
alkey
  • 986
  • 4
  • 16
  • 33

1 Answers1

2

The psn namespace prefix is used to normalize units of measure. Your query can look like this:

SELECT ?mountainLabel ?height 
WHERE 
{
  ?mountain wdt:P31 wd:Q8502. 
  ?mountain p:P2044/psn:P2044/wikibase:quantityAmount ?height .
  FILTER(8000 <= ?height)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en, de". }
}
John Skiles Skinner
  • 1,611
  • 1
  • 8
  • 21
  • I tried this in the Wikidata query service but I got a timeout error. Is this because it is trying to process too much information with this request? – alkey Aug 20 '19 at 07:23
  • Yes indeed. I got timeout errors a few times, then eventually got it to work. I think Wikidata is a little slower today than other days? – John Skiles Skinner Aug 20 '19 at 15:18
  • Well you successfully answered the question, despite the questionable performance of wikidata! I changed the request to mountains over 4000m in the USA (where the heights are in ft) and it does the job. – alkey Aug 21 '19 at 07:52