【问题标题】:How to fetch GPS coordinates of world's largest cities from WikiData via SPARQL, so that the result set includes Paris?如何通过 SPARQL 从 WikiData 中获取世界最大城市的 GPS 坐标,以便结果集包括巴黎?
【发布时间】:2022-11-01 19:52:48
【问题描述】:

通过在 Google 和 SO 上搜索,我想出了以下 SPARQL 查询,用于查找世界上最大的城市,以进行基本地理编码:


SELECT ?city ?cityLabel ?countryLabel ?iso ?population ?gps
WHERE {
  ?city wdt:P31 wd:Q515 . hint:Prior hint:runFirst true .
  ?city wdt:P17 ?country .
  ?country wdt:P297 ?iso .
  ?city wdt:P625 ?gps .
  ?city wdt:P1082 ?population .
  FILTER (?population > 100000) .

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY DESC(?population)
LIMIT 5000

https://query.wikidata.org/#SELECT%20%3Fcity%20%3FcityLabel%20%3FcountryLabel%20%3Fiso%20%3Fpopulation%20%3Fgps%0AWHERE%20%7B%0A%20%20%3Fcity%20wdt%3AP31%20wd%3AQ515%20.%20hint%3APrior%20hint%3ArunFirst%20true%20.%0A%20%20%3Fcity%20wdt%3AP17%20%3Fcountry%20.%0A%20%20%3Fcountry%20wdt%3AP297%20%3Fiso%20.%0A%20%20%3Fcity%20wdt%3AP625%20%3Fgps%20.%0A%20%20%3Fcity%20wdt%3AP1082%20%3Fpopulation%20.%0A%20%20FILTER%20(%3Fpopulation%20%3E%20100000)%20.%0A%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22en%22.%20%7D%0A%7D%0AORDER%20BY%20DESC(%3Fpopulation)%0ALIMIT%205000

出于某种原因,结果集不包括巴黎(法国),但包括法国的较小城市。我究竟做错了什么?

谢谢!

【问题讨论】:

  • 除了?vs ?gps 中的错字之外,您能解释一下您的查询结果中缺少什么吗?
  • 我只是修补了一下,它现在返回 GPS 坐标,但结果集不知何故错过了巴黎。可能有些过滤是错误的......

标签: gis sparql geocoding wikidata


【解决方案1】:
?city wdt:P31 wd:Q515 .

这个三元组模式不包括Paris (Q90),因为它不是city (Q515) 的实例。

不过,它是 city (Q515) 子类的一个实例。例如:capital city (Q5119)

要查找属于城市 (Q515) 或城市子类 (Q515) 的所有项目,您可以使用 property path

wdt:P31/wdt:P279*

由于一个城市可以是多个城市子类的实例,您可能希望使结果不同,否则这些城市将在结果中出现多次:

SELECT DISTINCT ?city ?cityLabel #etc.

【讨论】:

  • 唔。我试过?city wdt:P31/wdt:P279* wd:Q515 . hint:Prior hint:runFirst true .,但这给了Unknown error: scope=Prior, name=runFirst, value=true, op=PropertyPathNode
  • ?city wdt:P31/wdt:P279* wd:Q515 . 似乎可以工作,但工作速度较慢。我想知道我是否可以保留这些提示
  • 将您的答案标记为已接受。您能否将最终的完整查询(可能带有固定提示)作为您答案的一部分?例如SELECT DISTINCT ?city ?cityLabel ?countryLabel ?iso ?population ?gps WHERE { ?city wdt:P31/wdt:P279* wd:Q515 . ?city wdt:P17 ?country . ?city wdt:P1082 ?population . ?city wdt:P625 ?gps . ?country wdt:P297 ?iso . FILTER (?population > 100000) . SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ORDER BY DESC(?population) LIMIT 5000
  • @VadimKantorov:我对这些查询提示没有经验。您可以在单独的问题中询问这些问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 2011-09-05
  • 2014-02-12
相关资源
最近更新 更多