如何获取维基数据中某个位置周围的城市?

How to get cities around a location in wikidata?

我对 WikiData 有以下请求。它工作正常,因为可以使用结果,但我想将结果限制为城市的子集(在这种情况下为 "commune de France")。

请求 returns 任何感兴趣的地方(包括河流 "Hérin" 这不是我的意图)并且我需要做 DISTINCT 以避免与 "city" 我添加.

 SELECT DISTINCT ?place ?placeLabel ?location WHERE {

   # Use the around service
   SERVICE wikibase:around { 
     # Looking for items with coordinate locations(P625)
     ?place wdt:P625 ?location . 

     # That are in a circle with a centre of with a point
     bd:serviceParam wikibase:center "Point(4.8,44.32)"^^geo:wktLiteral   . 
     # Where the circle has a radius of 20km
     bd:serviceParam wikibase:radius "20" . 
     bd:serviceParam wikibase:distance ?distance .
   } .

   ?place wdt:P31/wdt:P279* ?city .

   # Use the label service to get the English label
   SERVICE wikibase:label {
   bd:serviceParam wikibase:language "en" . 
   }
}
ORDER BY ?distance

Try this query online

是否有人可以帮助我选择具有 "P31" 属性 的地点(我认为像 wdt:P31/wdt:P279* wd:Q515 这样的地方会很完美)。预先感谢您的帮助。

只需将 ?city 替换为 wd:Q484170 (Try it here):

 SELECT DISTINCT ?distance ?place ?placeLabel ?location WHERE {

   # Use the around service
   SERVICE wikibase:around { 
     # Looking for items with coordinate locations(P625)
     ?place wdt:P625 ?location . 

     # That are in a circle with a centre of with a point
     bd:serviceParam wikibase:center "Point(4.8,44.32)"^^geo:wktLiteral   . 
     # Where the circle has a radius of 20km
     bd:serviceParam wikibase:radius "20" . 
     bd:serviceParam wikibase:distance ?distance .
   } .

   ?place wdt:P31/wdt:P279* wd:Q484170.

   # Use the label service to get the English label
   SERVICE wikibase:label {
   bd:serviceParam wikibase:language "en" . 
   }
}
ORDER BY ?distance