spatialdata.get_extent

Contents

spatialdata.get_extent#

spatialdata.get_extent(e, coordinate_system='global', exact=True, has_images=True, has_labels=True, has_points=True, has_shapes=True, elements=None)#

Get the extent (bounding box) of a SpatialData object or a SpatialElement.

Parameters:

e (Union[SpatialData, SpatialImage, MultiscaleSpatialImage, GeoDataFrame, DataFrame]) – The SpatialData object or SpatialElement to compute the extent of.

Return type:

dict[str, tuple[float, float]]

Returns:

: The bounding box description.

min_coordinate

The minimum coordinate of the bounding box.

max_coordinate

The maximum coordinate of the bounding box.

axes

The names of the dimensions of the bounding box.

exact

Whether the extent is computed exactly or not.

  • If True, the extent is computed exactly.

  • If False, an approximation faster to compute is given.

The approximation is guaranteed to contain all the data, see notes for details.

has_images

If True, images are included in the computation of the extent.

has_labels

If True, labels are included in the computation of the extent.

has_points

If True, points are included in the computation of the extent.

has_shapes

If True, shapes are included in the computation of the extent.

elements

If not None, only the elements with the given names are included in the computation of the extent.

Notes

The extent of a SpatialData object is the extent of the union of the extents of all its elements. The extent of a SpatialElement is the extent of the element in the coordinate system specified by the argument coordinate_system.

If exact is False, first the extent of the SpatialElement before any transformation is computed. Then, the extent is transformed to the target coordinate system. This is faster than computing the extent after the transformation, since the transformation is applied to extent of the untransformed data, as opposed to transforming the data and then computing the extent.

The exact and approximate extent are the same if the transformation does not contain any rotation or shear, or in the case in which the transformation is affine but all the corners of the extent of the untransformed data (bounding box corners) are part of the dataset itself. Note that this is always the case for raster data.

An extreme case is a dataset composed of the two points (0, 0) and (1, 1), rotated anticlockwise by 45 degrees. The exact extent is the bounding box [minx, miny, maxx, maxy] = [0, 0, 0, 1.414], while the approximate extent is the box [minx, miny, maxx, maxy] = [-0.707, 0, 0.707, 1.414].