Geospatial
Distance Queries
Calculate distances between points and find entities within a specified radius. Master the wikibase:around service for proximity searches.
The wikibase:around Service
Wikidata provides the wikibase:around service for finding entities
within a certain distance of a point. This is optimized for geospatial searches
and much faster than manual distance calculations.
| Parameter | Description |
|---|---|
wikibase:center |
The center point (WKT literal) |
wikibase:radius |
Search radius in kilometers |
wikibase:distance |
Variable to store calculated distance |
Finding Nearby Places
Universities Within 50km of Paris
#defaultView:Map
SELECT ?uni ?uniLabel ?coord ?dist
WHERE {
# Paris center point
BIND("Point(2.3522 48.8566)"^^geo:wktLiteral AS ?center)
SERVICE wikibase:around {
?uni wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "50" .
bd:serviceParam wikibase:distance ?dist .
}
# Filter to universities only
?uni wdt:P31/wdt:P279* wd:Q3918 . # university
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en,fr" .
}
}
ORDER BY ?dist
Programming: Tech Companies Near Silicon Valley
Software Companies Near San Jose
#defaultView:Map
SELECT ?company ?companyLabel ?coord ?dist
WHERE {
# San Jose, California
BIND("Point(-121.8863 37.3382)"^^geo:wktLiteral AS ?center)
SERVICE wikibase:around {
?company wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "30" .
bd:serviceParam wikibase:distance ?dist .
}
?company wdt:P31/wdt:P279* wd:Q4830453 ; # business
wdt:P452 wd:Q638 . # software industry
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?dist
Cultural Heritage: Museums Near Me
Art Museums Within 25km of Any City
#defaultView:Map
SELECT ?museum ?museumLabel ?coord ?dist
WHERE {
# London coordinates
BIND("Point(-0.1276 51.5074)"^^geo:wktLiteral AS ?center)
SERVICE wikibase:around {
?museum wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "25" .
bd:serviceParam wikibase:distance ?dist .
}
?museum wdt:P31/wdt:P279* wd:Q207694 . # art museum
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
ORDER BY ?dist
Archaeological Sites Near Rome
#defaultView:Map
SELECT ?site ?siteLabel ?coord ?dist
WHERE {
# Rome coordinates
BIND("Point(12.4964 41.9028)"^^geo:wktLiteral AS ?center)
SERVICE wikibase:around {
?site wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "50" .
bd:serviceParam wikibase:distance ?dist .
}
?site wdt:P31 wd:Q839954 . # archaeological site
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en,it" .
}
}
ORDER BY ?dist
Urban: Transit Within Walking Distance
Metro Stations Within 1km
#defaultView:Map
SELECT ?station ?stationLabel ?coord
(ROUND(?dist * 1000) AS ?meters)
WHERE {
# Eiffel Tower
BIND("Point(2.2945 48.8584)"^^geo:wktLiteral AS ?center)
SERVICE wikibase:around {
?station wdt:P625 ?coord .
bd:serviceParam wikibase:center ?center .
bd:serviceParam wikibase:radius "1" . # 1 km
bd:serviceParam wikibase:distance ?dist .
}
?station wdt:P31 wd:Q928830 . # metro station
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en,fr" .
}
}
ORDER BY ?dist
Manual Distance Calculation
For calculating distance without the around service, use geof:distance.
This is useful when comparing distances between known points.
Distance Between Two Cities
SELECT ?city1Label ?city2Label
(ROUND(geof:distance(?coord1, ?coord2, uom:kilometre)) AS ?distKm)
WHERE {
VALUES (?city1 ?city2) {
(wd:Q90 wd:Q84) # Paris - London
(wd:Q60 wd:Q65) # New York - Los Angeles
(wd:Q1490 wd:Q956) # Tokyo - Beijing
}
?city1 wdt:P625 ?coord1 .
?city2 wdt:P625 ?coord2 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}