SPARQL/SERVICE - 附近和框
外觀
< SPARQL
該服務允許搜尋座標位於中心一定半徑內或一定邊界框內的專案。
以下大多數示例使用地圖檢視,在查詢頂部使用 #defaultView:Map。您可以切換到表格顯示以檢視底層資料。
最常用於位置的屬性是 座標位置 (P625)。
柏林 100 公里範圍內的機場示例
# Airports within 100km from Berlin
#defaultView:Map
SELECT ?place ?placeLabel ?location ?dist
WHERE {
# Berlin coordinates
wd:Q64 wdt:P625 ?berlinLoc .
SERVICE wikibase:around {
?place wdt:P625 ?location .
bd:serviceParam wikibase:center ?berlinLoc .
bd:serviceParam wikibase:radius "100" .
bd:serviceParam wikibase:distance ?dist.
}
FILTER EXISTS {
# Is an airport
?place wdt:P31/wdt:P279* wd:Q1248784 .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ASC(?dist)
around 服務呼叫的第一行必須具有格式 ?item predicate ?location,其中搜索結果將繫結 ?item 到指定位置內的專案,並將 ?location 繫結到它們的座標。支援的引數是
| 謂詞 | 含義 |
|---|---|
| wikibase:center | 執行搜尋的點。必須繫結才能搜尋生效。 |
| wikibase:radius | 距中心的距離。目前距離始終以公里為單位,其他單位尚未支援。 |
| wikibase:globe | 正在搜尋的地球。可選,預設為 地球 (wd:Q2)。 |
| wikibase:distance | 接收距離資訊的變數 |
加利福尼亞州聖何塞和加利福尼亞州薩克拉門託之間的學校框搜尋示例
# Schools between San Jose, CA and Sacramento, CA
#defaultView:Map
SELECT ?place ?placeLabel ?location
WHERE {
wd:Q16553 wdt:P625 ?SJloc.
wd:Q18013 wdt:P625 ?SCloc.
SERVICE wikibase:box {
?place wdt:P625 ?location.
bd:serviceParam wikibase:cornerSouthWest ?SJloc.
bd:serviceParam wikibase:cornerNorthEast ?SCloc.
}
?place wdt:P31/wdt:P279* wd:Q3914.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
可以直接指定座標
# Schools between San Jose, CA and Sacramento, CA
#same as previous
#defaultView:Map
SELECT ?place ?placeLabel ?location
WHERE {
SERVICE wikibase:box {
?place wdt:P625 ?location.
bd:serviceParam wikibase:cornerWest "Point(-121.872777777 37.304166666)"^^geo:wktLiteral.
bd:serviceParam wikibase:cornerEast "Point(-121.486111111 38.575277777)"^^geo:wktLiteral.
}
?place wdt:P31/wdt:P279* wd:Q3914.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
box 服務呼叫的第一行必須具有格式 ?item predicate ?location,其中搜索結果將繫結 ?item 到指定位置內的專案,並將 ?location 繫結到它們的座標。支援的引數是
| 謂詞 | 含義 |
|---|---|
| wikibase:cornerSouthWest | 框的西南角。 |
| wikibase:cornerNorthEast | 框的東北角。 |
| wikibase:cornerWest | 框的西角。 |
| wikibase:cornerEast | 框的東角。 |
| wikibase:globe | 正在搜尋的地球。可選,預設為 地球 (wd:Q2)。 |
wikibase:cornerSouthWest 和 wikibase:cornerNorthEast 應該一起使用,wikibase:cornerWest 和 wikibase:cornerEast 也應該一起使用,並且不能混合使用。如果使用 wikibase:cornerWest 和 wikibase:cornerEast 謂詞,則假定這些點是框對角線的座標,並且相應的角將被推匯出來。
函式 geof:distance 返回兩點之間的距離,以公里為單位。示例用法
# Airports within 100km from Berlin
SELECT ?place ?placeLabel ?location ?dist
WHERE {
# Berlin coordinates
wd:Q64 wdt:P625 ?berlinLoc.
SERVICE wikibase:around {
?place wdt:P625 ?location.
bd:serviceParam wikibase:center ?berlinLoc.
bd:serviceParam wikibase:radius "100".
}
# Is an airport
?place wdt:P31/wdt:P279* wd:Q1248784.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
BIND(geof:distance(?berlinLoc, ?location) as ?dist)
}
ORDER BY ?dist
# Places around 0°,0°
SELECT ?place ?placeLabel ?location ?dist
WHERE {
SERVICE wikibase:around {
?place wdt:P625 ?location.
bd:serviceParam wikibase:center "Point(0 0)"^^geo:wktLiteral.
bd:serviceParam wikibase:radius "250".
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
BIND(geof:distance("Point(0 0)"^^geo:wktLiteral, ?location) as ?dist)
}
ORDER BY ?dist