Skip to content

BoundingBox

Bases: Iterable[Coordinate]

A bounding box specifies the spatial extent of an area of interest.

PARAMETER DESCRIPTION
x_min

Minimum x coordinate in meters

TYPE: Coordinate

y_min

Minimum y coordinate in meters

TYPE: Coordinate

x_max

Maximum x coordinate in meters

TYPE: Coordinate

y_max

Maximum y coordinate in meters

TYPE: Coordinate

x_min property

RETURNS DESCRIPTION
Coordinate

Minimum x coordinate in meters

y_min property

RETURNS DESCRIPTION
Coordinate

Minimum y coordinate in meters

x_max property

RETURNS DESCRIPTION
Coordinate

Maximum x coordinate in meters

y_max property

RETURNS DESCRIPTION
Coordinate

Maximum y coordinate in meters

area property

RETURNS DESCRIPTION
int

Area in square meters

from_gdf classmethod

Creates a bounding box from a geodataframe.

PARAMETER DESCRIPTION
gdf

Geodataframe

TYPE: gpd.GeoDataFrame

RETURNS DESCRIPTION
BoundingBox

Bounding box

__eq__

Compares the bounding boxes.

PARAMETER DESCRIPTION
other

Other bounding box

TYPE: object

RETURNS DESCRIPTION
bool

True if the bounding boxes are equal, False otherwise

__len__

Computes the number of coordinates.

RETURNS DESCRIPTION
int

Number of coordinates

__getitem__

Returns the coordinate.

PARAMETER DESCRIPTION
index

Index of the coordinate

TYPE: int

RETURNS DESCRIPTION
Coordinate

Coordinate in meters

__iter__

Iterates over the coordinates.

YIELDS DESCRIPTION
Coordinate

Coordinate in meters

__and__

Intersects the bounding boxes.

PARAMETER DESCRIPTION
other

Other bounding box

TYPE: BoundingBox

RETURNS DESCRIPTION
BoundingBox

Bounding box

__or__

Unions the bounding boxes.

PARAMETER DESCRIPTION
other

Other bounding box

TYPE: BoundingBox

RETURNS DESCRIPTION
BoundingBox

Bounding box

buffer

Buffers the bounding box.

Notes
  • A positive buffer size expands the bounding box
  • A negative buffer size shrinks the bounding box
Example

Assume the area of interest is specified by x_min=363084, y_min=5715326, x_max=363340, and y_max=5715582.

You can expand the area of interest by buffering the bounding box.

bounding_box = BoundingBox(
    x_min=363084,
    y_min=5715326,
    x_max=363340,
    y_max=5715582,
)
bounding_box = bounding_box.buffer(buffer_size=64)
print(bounding_box)
Output
BoundingBox(
    x_min=363020,
    y_min=5715262,
    x_max=363404,
    y_max=5715646,
)
PARAMETER DESCRIPTION
buffer_size

Buffer size in meters

TYPE: BufferSize

inplace

If True, the bounding box is buffered inplace

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
BoundingBox

Bounding box

snap

Snaps the bounding box.

Example

Assume the area of interest is specified by x_min=363084, y_min=5715326, x_max=363340, and y_max=5715582.

You can align the area of interest to a grid by snapping the bounding box.

bounding_box = BoundingBox(
    x_min=363084,
    y_min=5715326,
    x_max=363340,
    y_max=5715582,
)
bounding_box = bounding_box.snap(value=128)
print(bounding_box)
Output
BoundingBox(
    x_min=363008,
    y_min=5715200,
    x_max=363392,
    y_max=5715584,
)
PARAMETER DESCRIPTION
value

Value to snap the coordinates to in meters

TYPE: int

inplace

If True, the bounding box is snapped inplace

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
BoundingBox

Bounding box

to_gdf

Converts the bounding box to a geodataframe.

PARAMETER DESCRIPTION
epsg_code

EPSG code

TYPE: EPSGCode | None

RETURNS DESCRIPTION
gpd.GeoDataFrame

Geodataframe