spatial
This module provides classes and functions to help with light geospatial objects (projections, bounding boxes, etc).
BoundingBox
¶
The bounding box class
Source code in scenes/spatial.py
__init__(xmin, ymin, xmax, ymax)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xmin |
float
|
Lower value on the x-axis |
required |
ymin |
float
|
Lower value on the y-axis |
required |
xmax |
float
|
Higher value on the x-axis |
required |
ymax |
float
|
Higher value on the y-axis |
required |
Source code in scenes/spatial.py
__str__()
¶
to_list()
¶
Converts the bbox into a list of coordinates, like rasterio does.
Returns:
| Type | Description |
|---|---|
List[float]
|
[xmin, ymin, xmax, ymax] |
to_ogrgeom()
¶
Converts the BoundingBox into an OGR geometry
Returns: an OGR Geometry from the bounding box
Source code in scenes/spatial.py
union(other)
¶
Return a new bounding box resulting in the union of self and other
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
other |
BoundingBox
|
another bounding box |
required |
Returns:
| Type | Description |
|---|---|
BoundingBox
|
a new bounding box |
Source code in scenes/spatial.py
coord_list_to_bbox(coords)
¶
Computes the bounding box of multiple coordinates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords |
Tuple[Tuple[float]]
|
coordinates (x1, y1), ..., (xN, yN) |
required |
Returns:
| Type | Description |
|---|---|
BoundingBox
|
BoundingBox instance |
Source code in scenes/spatial.py
coordinates_transform(src_srs, tgt_srs)
¶
Return a coordinates transform.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
src_srs |
SpatialReference
|
source CRS |
required |
tgt_srs |
SpatialReference
|
target CRS |
required |
Returns:
| Type | Description |
|---|---|
CoordinateTransformation
|
osr.CoordinateTransformation |
Source code in scenes/spatial.py
coords2poly(coords)
¶
Converts a list of coordinates into a polygon
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords |
Tuple[Tuple[float]]
|
tuple of (x, y) coordinates |
required |
Returns:
| Type | Description |
|---|---|
Geometry
|
a polygon |
Source code in scenes/spatial.py
epsg2srs(epsg)
¶
Return a Spatial Reference System corresponding to an EPSG
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
epsg |
int
|
EPSG (int) |
required |
Returns:
| Type | Description |
|---|---|
SpatialReference
|
OSR spatial reference |
Source code in scenes/spatial.py
extent_overlap(extent, other_extent)
¶
Returns the ratio of extents overlaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extent |
Tuple[Tuple[float]]
|
extent |
required |
other_extent |
Tuple[Tuple[float]]
|
other extent |
required |
Returns:
| Type | Description |
|---|---|
float
|
overlap (in the [0, 1] range). 0 -> no overlap with other_extent, 1 -> extent lies inside other_extent |
Source code in scenes/spatial.py
poly_overlap(poly, other_poly)
¶
Returns the ratio of polygons overlap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poly |
Geometry
|
polygon |
required |
other_poly |
Geometry
|
other polygon |
required |
Returns:
| Type | Description |
|---|---|
float
|
overlap (in the [0, 1] range). 0 -> no overlap with other_poly, 1 -> poly is completely inside other_poly |
Source code in scenes/spatial.py
reproject_coords(coords, src_srs, tgt_srs)
¶
Reproject a list of x,y coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
coords |
List[Tuple[float]]
|
list of (x, y) tuples |
required |
src_srs |
SpatialReference
|
source CRS |
required |
tgt_srs |
SpatialReference
|
target CRS |
required |
Returns:
| Name | Type | Description |
|---|---|---|
trans_coords |
Tuple[Tuple[float]]
|
coordinates in target CRS |