faninsar.query.BoundingBox#
- class faninsar.query.BoundingBox(left: float, bottom: float, right: float, top: float, crs: CRS | str | None = None)[source]#
Bases:
objecta class used for indexing datasets using a spatial bounding box.
Note
This class is a modified version of the BoundingBox class from the torchgeo package. The main modifications include:
Removal of
date boundsChange of the bounding box to (left, bottom, right, top), which aligns with the
rasterio.coords.BoundingBoxclass.Addition of the CRS attribute to automatically convert the bounding box to the CRS of the dataset.
- __init__(left: float, bottom: float, right: float, top: float, crs: CRS | str | None = None) None[source]#
Initialize a BoundingBox.
- Parameters:
left (float) – The western boundary.
bottom (float) – The southern boundary.
right (float) – The eastern boundary.
top (float) – The northern boundary.
crs (CRS | str | None, optional) – The coordinate reference system of the bounding box. Can be any object that can be passed to
pyproj.crs.CRS.from_user_input(). Default is None.
Methods
__init__(left, bottom, right, top[, crs])Initialize a BoundingBox.
buffer(distance)Buffer the bounding box.
intersects(other)Whether or not two bounding boxes intersect.
set_crs(crs)Set the coordinate reference system of the bounding box.
split(proportion[, horizontal])Split BoundingBox in two.
Convert the bounding box to a GeoDataFrame.
to_crs(crs)Convert the bounding box to a new coordinate reference system.
to_dict()Convert the bounding box to a dictionary.
Attributes
- buffer(distance: float) BoundingBox[source]#
Buffer the bounding box.
- Parameters:
distance (float) – the buffer distance in the units of the bounding box
- Return type:
the buffered bounding box
- intersects(other: BoundingBox) bool[source]#
Whether or not two bounding boxes intersect.
- Parameters:
other (BoundingBox) – another bounding box
- Return type:
True if bounding boxes intersect, else False
- set_crs(crs: CRS | str) None[source]#
Set the coordinate reference system of the bounding box.
- Parameters:
crs (CRS | str) –
The new coordinate reference system. Can be any object that can be passed to
pyproj.crs.CRS.from_user_input().Warning
This method will only set the crs attribute without converting the bounding box to a new coordinate reference system. If you want to convert the bounding box values to a new coordinate, please use
to_crs()
- split(proportion: float, horizontal: bool = True) tuple[BoundingBox, BoundingBox][source]#
Split BoundingBox in two.
- to_GeoDataFrame() gpd.GeoDataFrame[source]#
Convert the bounding box to a GeoDataFrame.
- Return type:
GeoDataFrame with the bounding box as a polygon
- to_crs(crs: CRS | str) BoundingBox[source]#
Convert the bounding box to a new coordinate reference system.
- Parameters:
crs (CRS | str) – The new coordinate reference system. Can be any object that can be passed to
pyproj.crs.CRS.from_user_input().