Get the region (bounding box) of a set of points

1. Get the region (bounding box) of a set of points#

Let’s say we have a dataset that has longitude and latitude coordinates (but it could also be whatever other type of coordinate). And we need to know the bounding box of this dataset, which we call a region, comprised of West, East, South, and North values. Bordado offers bordado.get_region to do this.

import ensaio
import pandas as pd
import bordado as bd

To demonstrate, we’ll use ensaio.fetch_southern_africa_gravity to get a sample dataset of ground-based gravity observation across Southern Africa. The dataset is a CSV file, which we’ll load using pandas.read_csv:

fname = ensaio.fetch_southern_africa_gravity(version=1)
data = pd.read_csv(fname)
data
longitude latitude height_sea_level_m gravity_mgal
0 18.34444 -34.12971 32.2 979656.12
1 18.36028 -34.08833 592.5 979508.21
2 18.37418 -34.19583 18.4 979666.46
3 18.40388 -34.23972 25.0 979671.03
4 18.41112 -34.16444 228.7 979616.11
... ... ... ... ...
14354 21.22500 -17.95833 1053.1 978182.09
14355 21.27500 -17.98333 1033.3 978183.09
14356 21.70833 -17.99166 1041.8 978182.69
14357 21.85000 -17.95833 1033.3 978193.18
14358 21.98333 -17.94166 1022.6 978211.38

14359 rows × 4 columns

We can then use get_region to extract the bounding box information:

coordinates = (data.longitude, data.latitude)
region = bd.get_region(coordinates)
print(region)
(11.90833, 32.74667, -34.996, -17.33333)

The region above will have the minimum and maximum values of each coordinate in order. The order of the coordinates will be the order of the output region. In this case, the numbers correspond to the West and East longitude, followed by the South and North latitude.

Note

We tend to always use “longitude” or “easting” and then “latitude” or “northing” as the order of coordinates. But Bordado can work with whatever order you choose:

coordinates = (data.latitude, data.longitude)
region = bd.get_region(coordinates)
print(region)
(-34.996, -17.33333, 11.90833, 32.74667)

Just be aware of your own conventions.

If the height_sea_level_m column is considered another coordinate and we want the 3D bounding box, we can pass more than 2 values to get_region:

coordinates_3d = (data.longitude, data.latitude, data.height_sea_level_m)
region_3d = bd.get_region(coordinates_3d)
print(region_3d)
(11.90833, 32.74667, -34.996, -17.33333, 0.0, 2622.2)

In this case, the minimum and maximum height are the two last values of the region_3d tuple.