Module rok4.utils
Provide functions to manipulate OGR / OSR entities
Functions
def bbox_to_geometry(bbox: Tuple[float, float, float, float], densification: int = 0)-
Convert bbox coordinates to OGR geometry
Args
bbox:Tuple[float, float, float, float]- bounding box (xmin, ymin, xmax, ymax)
densification:int, optional- Number of point to add for each side of bounding box. Defaults to 0.
Raises
RuntimeError- Provided SRS is invalid for OSR
Returns
osgeo.ogr.Geometry- Corresponding OGR geometry, with spatial reference if provided
def compute_bbox(source_dataset: osgeo.gdal.Dataset) ‑> Tuple[]-
Image boundingbox computing method
Args
source_dataset:gdal.Dataset- Dataset instanciated from the raster image
Limitations
Image's axis must be parallel to SRS' axis
Raises
AttributeError- source_dataset is not a gdal.Dataset instance.
Exception- The dataset does not contain transform data.
def compute_format(dataset: osgeo.gdal.Dataset, path: str = None) ‑> ColorFormat-
Image color format computing method
Args
dataset:gdal.Dataset- Dataset instanciated from the image
path:str, optionnal- path to the original file/object
Raises
AttributeError- source_dataset is not a gdal.Dataset instance.
Exception- No color band found or unsupported color format.
def reproject_bbox(bbox: Tuple[float, float, float, float], srs_src: str, srs_dst: str, densification: int = 5) ‑> Tuple[float, float, float, float]-
Return bounding box in other coordinates system
Points are added to be sure output bounding box contains input bounding box
Args
bbox:Tuple[float, float, float, float]- bounding box (xmin, ymin, xmax, ymax) with source coordinates system
srs_src:str- source coordinates system
srs_dst:str- destination coordinates system
densification:int, optional- Number of point to add for each side of bounding box. Defaults to 5.
Returns
Tuple[float, float, float, float]- bounding box (xmin, ymin, xmax, ymax) with destination coordinates system
def reproject_point(point: Tuple[float, float], sr_src: osgeo.osr.SpatialReference, sr_dst: osgeo.osr.SpatialReference)-
Reproject a point
Args
point:Tuple[float, float]- source spatial reference point
sr_src:osgeo.osr.SpatialReference- source spatial reference
sr_dst:osgeo.osr.SpatialReference- destination spatial reference
Returns
Tuple[float, float]- X/Y in destination spatial reference
def srs_to_spatialreference(srs: str)-
Convert coordinates system as string to OSR spatial reference
Using a cache, to instanciate a Spatial Reference from a string only once.
Args
srs:str- coordinates system PROJ4 compliant, with authority and code, like EPSG:3857 or IGNF:LAMB93
Raises
RuntimeError- Provided SRS is invalid for OSR
Returns
osgeo.osr.SpatialReference- Corresponding OSR spatial reference