Geospatial

Bounding Boxes

Query entities within rectangular regions using bounding boxes. Define areas using corner coordinates for efficient spatial queries.

The wikibase:box Service

Use wikibase:box to find entities within a rectangular region defined by southwest and northeast corner coordinates.

Parameter Description
wikibase:cornerSouthWest Southwest corner point (min lat, min long)
wikibase:cornerNorthEast Northeast corner point (max lat, max long)

Basic Bounding Box Query

All Places in a Region
Run ↗
#defaultView:Map
SELECT ?place ?placeLabel ?coord
WHERE {
  # Define bounding box for Île-de-France region
  SERVICE wikibase:box {
    ?place wdt:P625 ?coord .
    bd:serviceParam wikibase:cornerSouthWest
      "Point(1.4 48.1)"^^geo:wktLiteral .
    bd:serviceParam wikibase:cornerNorthEast
      "Point(3.6 49.3)"^^geo:wktLiteral .
  }

  # Filter to museums
  ?place wdt:P31/wdt:P279* wd:Q33506 .  # museum

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en,fr" .
  }
}

Cultural Heritage: Heritage Sites in a Country

UNESCO Sites in Mediterranean Region
Run ↗
#defaultView:Map
SELECT ?site ?siteLabel ?coord ?country ?countryLabel
WHERE {
  # Mediterranean bounding box
  SERVICE wikibase:box {
    ?site wdt:P625 ?coord .
    bd:serviceParam wikibase:cornerSouthWest
      "Point(-6 30)"^^geo:wktLiteral .
    bd:serviceParam wikibase:cornerNorthEast
      "Point(36 46)"^^geo:wktLiteral .
  }

  ?site wdt:P1435 wd:Q9259 ;  # UNESCO site
        wdt:P17 ?country .

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Urban: City Infrastructure

Train Stations in Manhattan
Run ↗
#defaultView:Map
SELECT ?station ?stationLabel ?coord
WHERE {
  # Manhattan bounding box
  SERVICE wikibase:box {
    ?station wdt:P625 ?coord .
    bd:serviceParam wikibase:cornerSouthWest
      "Point(-74.02 40.70)"^^geo:wktLiteral .
    bd:serviceParam wikibase:cornerNorthEast
      "Point(-73.90 40.88)"^^geo:wktLiteral .
  }

  # Railway or metro stations
  { ?station wdt:P31 wd:Q55488 . }  # railway station
  UNION
  { ?station wdt:P31 wd:Q928830 . } # metro station

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}

Manual Bounding Box with FILTER

You can also create bounding boxes manually using FILTER on extracted coordinates. This is more flexible but less performant than the service.

Manual Lat/Long Filtering
Run ↗
#defaultView:Map
SELECT ?city ?cityLabel ?coord ?lat ?long
WHERE {
  ?city wdt:P31/wdt:P279* wd:Q515 ;
        wdt:P625 ?coord .

  BIND(geof:latitude(?coord) AS ?lat)
  BIND(geof:longitude(?coord) AS ?long)

  # Manual bounding box for Europe
  FILTER(?lat >= 35 && ?lat <= 70)
  FILTER(?long >= -10 && ?long <= 40)

  SERVICE wikibase:label {
    bd:serviceParam wikibase:language "en" .
  }
}
LIMIT 500