# Bounding box finder

> Draw a box on the map, search a place or paste a bounding box you already have, then copy its coordinates in the order your library expects. Free, no account needed.

Open the tool: https://spatibase.com/tools/bounding-box/

The Spatibase bounding box finder gets the coordinates of a rectangle on the map, in your web browser. Draw the box, use the current map view, search a place or paste a bbox in any common format, then copy it as minLng,minLat,maxLng,maxLat, a GeoJSON polygon, WKT, Leaflet or MapLibre bounds, an Overpass bbox, an OpenLayers extent in EPSG:4326 or EPSG:3857, an ogr2ogr -spat argument or a Spatibase API query. It handles boxes that cross the 180° meridian and is free with no account. The box stays in your browser; a place search is sent to OpenStreetMap’s Nominatim.

It answers the question behind most bbox searches, “which order?”:

- **Four numbers, several orders.** GeoJSON and most web APIs write west, south, east, north; Leaflet, Overpass and Google Maps start with the latitude.
- **Paste to check.** Paste a box from your code and see where it lands: on another continent means two values traded places.
- **A Copy button per format.** Choose 2 to 7 decimals (6 by default, about 11 cm), and every output follows.

## What it does
- Draw a box, use the map view or search a place
- Paste a bbox in any common format to see it
- Reads latitude-first and longitude-first boxes
- Copy for GeoJSON, WKT, Leaflet, MapLibre, OpenLayers, Overpass and ogr2ogr
- Degrees (EPSG:4326) and Web Mercator metres (EPSG:3857)
- Width, height and area in kilometres
- Boxes across the 180° meridian
- Copy a link that reopens the same box

## How to get the bounding box of an area
Make the box, check it on the map, copy the format you need.

1. Press Draw a box and drag across the map; on a phone, tap two opposite corners. No area in mind? Open the sample: central Barcelona.
2. Or press Use the map view, or search a place to get the box OpenStreetMap stores for it.
3. Drag the corners or edges until the box covers what you need.
4. Have a bbox already? Paste it in, in any common order, WKT or GeoJSON, to see where it lands.
5. Set the decimals and press Copy next to the format your code uses.

## Input, output and limits
- **Input:** a box drawn on the map (drag, or two taps on a touch screen), the current map view, a place search (OpenStreetMap Nominatim’s bounding box for the place), or a pasted bbox.
- **Pasted formats:** four numbers in either order (separated by commas, spaces, semicolons or tabs), JSON arrays, Leaflet `[[south, west], [north, east]]` and MapLibre `[[west, south], [east, north]]` bounds or code, Overpass `(south,west,north,east)`, WKT geometries, `ENVELOPE`, CQL `BBOX`, PostGIS `BOX` and `ST_MakeEnvelope`, GeoJSON (its `bbox` member or its extent), Nominatim’s `boundingbox`, `ogr2ogr -spat`, a link with `bbox=`, named values (`west`, `minx`, `minLat` …) and EPSG:3857 metres. When both orders give a valid box, it reads longitude first and says so.
- **Outputs, each with a Copy button:** `minLng,minLat,maxLng,maxLat`, a GeoJSON Polygon, WKT, Leaflet `L.latLngBounds`, MapLibre or Mapbox `fitBounds`, an OpenLayers extent in EPSG:4326 and in EPSG:3857 metres, Overpass `(south,west,north,east)`, `ogr2ogr -spat`, and the Spatibase Delivery `bbox=` query.
- **Decimals:** 2 to 7, 6 by default; EPSG:3857 metres get 5 fewer (the same precision on the ground). Width, height and area are measured on the WGS 84 ellipsoid.
- **Across the 180° meridian:** supported (west greater than east). The GeoJSON and WKT outputs split the box into two polygons at the line; Leaflet, MapLibre and OpenLayers get east + 360; Overpass, ogr2ogr and the Spatibase query become two boxes, one on each side.
- **Shareable link:** the box lives in the page address (`?bbox=west,south,east,north`), so a link reopens it, for example https://spatibase.com/tools/bounding-box/?bbox=2.0523,41.317,2.228,41.4682
- **Privacy:** the box stays in your browser; a place search is sent to OpenStreetMap’s Nominatim.
- Try it with the sample (central Barcelona): https://spatibase.com/tools/bounding-box/?sample=1

## Which order is a bounding box in?
**There is no single order.** Most formats write west, south, east, north, which is longitude first; a few put latitude first, and one uses an order of its own.

The ones you’ll meet most, and the order each expects:

- **GeoJSON `bbox` member:** `[west, south, east, north]`, as RFC 7946 sets out. The same order in Turf’s `bbox()`, Shapely’s `bounds`, OpenLayers extents, PostGIS `ST_MakeEnvelope` and the Spatibase `bbox=` parameter.
- **MapLibre and Mapbox GL `fitBounds`:** `[[west, south], [east, north]]`, longitude first, or the same four numbers flat.
- **Leaflet `fitBounds`:** `[[south, west], [north, east]]`: latitude first, like everything in Leaflet.
- **Google Maps `LatLngBounds`:** the south-west corner, then the north-east one, each as `{ lat, lng }`.
- **Overpass QL:** `(south, west, north, east)`, latitude first.
- **Nominatim `boundingbox`:** `[south, north, west, east]`, as strings: both latitudes, then both longitudes.
- **WKT and `ogr2ogr -spat`:** x before y, so longitude before latitude: `POLYGON((west south, …))` and `-spat west south east north`.
- **WMS 1.3.0 with EPSG:4326:** latitude first, while WMS 1.1.1 and `CRS:84` use longitude first, the classic cause of a sideways map.

**Telling a pasted box apart.** A latitude lies between −90 and 90, so a larger value must be a longitude. When all four values fit both readings, the finder reads longitude first and says so.

**Across the 180° meridian,** west is greater than east (Fiji: 177 to −178). GeoJSON allows that, many libraries don’t, so each output notes how it handles one.

## Get a bounding box in code
Turf’s bbox function measures any GeoJSON, map libraries zoom to the result, and the Spatibase Content Delivery API filters your own places by it.

```js
import * as turf from '@turf/turf'

const box = turf.bbox(geojson) // [west, south, east, north] of every coordinate
geojson.bbox = box // GeoJSON can carry it as a "bbox" member

// MapLibre GL and Mapbox GL: longitude first, as two corners
map.fitBounds([[box[0], box[1]], [box[2], box[3]]], { padding: 40 })

// Leaflet: latitude first
leafletMap.fitBounds([[box[1], box[0]], [box[3], box[2]]])

// your published places inside the box (Spatibase Content Delivery API)
const url = `https://api.spatibase.com/delivery/v1/projects/${PROJECT_ID}/entries?bbox=${box.join(',')}`
const { data } = await (await fetch(url)).json()
```

**Turf’s bbox ignores the 180° meridian:** points on both sides give a box around the rest of the world. d3-geo’s `geoBounds` handles it and returns a west greater than the east.

**The Delivery API** takes `bbox=minLng,minLat,maxLng,maxLat` with each minimum at most its maximum, so a box across the 180° meridian takes two requests. A public project needs no key.

**With GDAL,** `ogrinfo -so -al in.gpkg` prints each layer’s extent; `ogr2ogr -spat` keeps what touches a box given in the layer’s own coordinates.

## Frequently asked questions
### What order are bounding box coordinates in?
Usually west, south, east, north (minLng, minLat, maxLng, maxLat), as in GeoJSON, Turf and most web APIs. Leaflet, Overpass and Google Maps put latitude first, and Nominatim gives south, north, west, east. Paste yours above to see which reading lands where you expect.

### Why is my bounding box upside down or in the wrong place?
Two values traded places. With latitude and longitude swapped, a box around Barcelona lands in East Africa; with south and north swapped, some libraries flip it back and others refuse it; with west and east swapped, the box runs the long way round the world.

### What is EPSG:3857, and why is that bbox in metres?
EPSG:3857 is Web Mercator, the projection of almost every web map. Its coordinates are metres from where the equator meets the Greenwich meridian, up to about 20,037,508 each way, and it stops at 85.05° north and south. OpenLayers uses it by default; most other tools want degrees (EPSG:4326).

### How do I get the bounding box of a city or country?
Search for it: OpenStreetMap’s Nominatim stores a box for every place it knows. A country with territories far away, such as France, can get a box around most of the world; draw a tighter one by hand.

### How do I write a bounding box that crosses the 180° meridian?
Keep west greater than east: Fiji’s box runs from 177 to −178. GeoJSON allows exactly that. For a library that doesn’t, add 360 to the east value (182) or split the box in two, one on each side of the line.

### How many decimals does a bounding box need?
Four decimals are about 11 m, plenty for a city or a map view; six are about 11 cm. More only make the numbers longer.

## Next step
Filter your own places by a box through an API: create a free Spatibase project (https://app.spatibase.com/signup), then ask the Content Delivery API for `bbox=minLng,minLat,maxLng,maxLat` (https://spatibase.com/docs/reference/delivery-api/).
