RSGISLib Geometry Tools

Projections

rsgislib.tools.geometrytools.reproj_bbox(bbox: ~typing.List[float], in_osr_proj_obj: <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fa534e61560> >, out_osr_proj_obj: <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fa534e61530> >) List[float]

A function to reproject a bounding box.

Parameters:
  • bbox – input bounding box (MinX, MaxX, MinY, MaxY)

  • in_osr_proj_obj – an osr.SpatialReference() object representing input projection.

  • out_osr_proj_obj – an osr.SpatialReference() object representing output projection.

Returns:

(MinX, MaxX, MinY, MaxY)

rsgislib.tools.geometrytools.reproj_bbox_epsg(bbox: List[float], in_epsg: int, out_epsg: int)

A function to reproject a bounding box.

Parameters:
  • bbox – input bounding box (MinX, MaxX, MinY, MaxY)

  • in_epsg – an EPSG code representing input projection.

  • out_epsg – an EPSG code representing output projection.

Returns:

(MinX, MaxX, MinY, MaxY)

rsgislib.tools.geometrytools.reproj_point(in_osr_proj_obj: <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fa534e638a0> >, out_osr_proj_obj: <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fa534e637b0> >, x: float, y: float) -> (<class 'float'>, <class 'float'>)

Reproject a point from ‘in_osr_proj_obj’ to ‘out_osr_proj_obj’ where they are gdal osgeo.osr.SpatialReference objects.

Parameters:
  • in_osr_proj_obj – an osr.SpatialReference() object representing input projection.

  • out_osr_proj_obj – an osr.SpatialReference() object representing output projection.

  • x – the x coordinate to be reprojected

  • y – the y coordinate to be reprojected

Returns:

x, y.

rsgislib.tools.geometrytools.reproj_point_to_wgs84(osr_proj_obj: <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fa534e62b80> >, x: float, y: float) -> (<class 'float'>, <class 'float'>)

A function which reprojects a point to the WGS84 projection

Parameters:
  • osr_proj_obj – an osr.SpatialReference() object representing input projection.

  • x – the x coordinate to be reprojected

  • y – the y coordinate to be reprojected

Returns:

lon, lat

Testing

rsgislib.tools.geometrytools.do_bboxes_intersect(bbox1: List[float], bbox2: List[float]) bool

A function which tests whether two bboxes (MinX, MaxX, MinY, MaxY) intersect.

Parameters:
  • bbox1 – The first bounding box (MinX, MaxX, MinY, MaxY)

  • bbox2 – The second bounding box (MinX, MaxX, MinY, MaxY)

Returns:

boolean (True they intersect; False they do not intersect)

rsgislib.tools.geometrytools.does_bbox_contain(bbox1: List[float], bbox2: List[float]) bool

A function which tests whether bbox1 contains bbox2.

Parameters:
  • bbox1 – The first bounding box (MinX, MaxX, MinY, MaxY)

  • bbox2 – The second bounding box (MinX, MaxX, MinY, MaxY)

Returns:

boolean (True bbox1 contains bbox2; False bbox1 does not contain bbox2)

rsgislib.tools.geometrytools.bbox_equal(bbox1: List[float], bbox2: List[float]) bool

A function which tests whether two bboxes (xMin, xMax, yMin, yMax) are equal.

Parameters:
  • bbox1 – is a bbox (xMin, xMax, yMin, yMax)

  • bbox2 – is a bbox (xMin, xMax, yMin, yMax)

Returns:

boolean

rsgislib.tools.geometrytools.pt_in_bbox(pt: List[float], bbox: List[float]) bool

A function which tests whether a point is within a bbox.

Parameters:
  • pt – the point (x, y)

  • bbox – the bounding box (MinX, MaxX, MinY, MaxY)

Returns:

returns a boolean specifying whether the point is within the bbox

Calculations

rsgislib.tools.geometrytools.calc_bbox_area(bbox: List[float]) float

Calculate the area of the bbox.

Parameters:

bbox – bounding box (MinX, MaxX, MinY, MaxY)

Returns:

area in projection of the bbox.

rsgislib.tools.geometrytools.calc_pt_distance(x1: float, y1: float, x2: float, y2: float) float

Calculate the euclidean distance between two points

Parameters:
  • x1 – x1 coordinate

  • y1 – y1 coordinate

  • x2 – x2 coordinate

  • y2 – y2 coordinate

Returns:

euclidean distance

Compute New BBOX

rsgislib.tools.geometrytools.bbox_intersection(bbox1: List[float], bbox2: List[float]) List[float]

A function which calculates the intersection of the two bboxes (xMin, xMax, yMin, yMax).

Parameters:
  • bbox1 – is a bbox (xMin, xMax, yMin, yMax)

  • bbox2 – is a bbox (xMin, xMax, yMin, yMax)

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.bboxes_intersection(bboxes: List[List[float]]) List[float]

A function to find the intersection between a list of bboxes.

Parameters:

bboxes – a list of bboxes [(xMin, xMax, yMin, yMax)]

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.buffer_bbox(bbox: List[float], buf: float) List[float]

Buffer the input BBOX by a set amount.

Parameters:
  • bbox – the bounding box (MinX, MaxX, MinY, MaxY)

  • buf – the amount of buffer by

Returns:

the buffered bbox (MinX, MaxX, MinY, MaxY)

rsgislib.tools.geometrytools.find_bbox_union(bboxes: List[List[float]]) List[float]

A function which finds the union of all the bboxes inputted.

Parameters:

bboxes – a list of bboxes [(xMin, xMax, yMin, yMax), (xMin, xMax, yMin, yMax)]

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.unwrap_wgs84_bbox(bbox: List[float]) List[List[float]]

A function which unwraps a bbox if it projected in WGS84 and over the 180/-180 boundary.

Parameters:

bbox – the bounding box (MinX, MaxX, MinY, MaxY)

Returns:

list of bounding boxes [(MinX, MaxX, MinY, MaxY), (MinX, MaxX, MinY, MaxY)…]

rsgislib.tools.geometrytools.find_common_extent_on_grid(base_extent: List[float], base_grid: float, other_extent: List[float], full_contain: bool = True) List[float]

A function which calculates the common extent between two extents but defines output on grid with defined resolutions. Useful for finding common extent on a particular image grid.

Parameters:
  • base_extent – is a bbox (xMin, xMax, yMin, yMax) providing the base for the grid on which output will be defined.

  • base_grid – the size of the (square) grid on which output will be defined.

  • other_extent – is a bbox (xMin, xMax, yMin, yMax) to be intersected with the base_extent.

  • full_contain – is a boolean. True: moving output onto grid will increase size of bbox (i.e., intersection fully contained) False: move output onto grid will decrease size of bbox (i.e., bbox fully contained within intesection)

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.find_extent_on_grid(base_extent: List[float], base_grid: float, full_contain: bool = True) List[float]

A function which calculates the extent but defined on a grid with defined resolution. Useful for finding extent on a particular image grid.

Parameters:
  • base_extent – is a bbox (xMin, xMax, yMin, yMax) providing the base for the grid on which output will be defined.

  • base_grid – the size of the (square) grid on which output will be defined.

  • full_contain – is a boolean. True: moving output onto grid will increase size of bbox (i.e., intersection fully contained) False: move output onto grid will decrease size of bbox (i.e., bbox fully contained within intesection)

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.find_extent_on_whole_num_grid(base_extent: List[float], base_grid: float, full_contain: bool = True, round_vals: int = None) List[float]

A function which calculates the extent but defined on a grid with defined resolution. Useful for finding extent on a particular image grid.

Parameters:
  • base_extent – is a bbox (xMin, xMax, yMin, yMax) providing the base for the grid on which output will be defined.

  • base_grid – the size of the (square) grid on which output will be defined.

  • full_contain – is a boolean. True: moving output onto grid will increase size of bbox (i.e., intersection fully contained) False: move output onto grid will decrease size of bbox (i.e., bbox fully contained within intesection)

  • round_vals – specify whether outputted values should be rounded. None for no rounding (default; None) or integer for number of significant figures to round to.

Returns:

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.get_bbox_grid(bbox: List[float], x_size: int, y_size: int) List[List[float]]

Create a grid with size x_size, y_size for the area represented by bbox.

Parameters:
  • bbox – a bounding box within which the grid will be created (xMin, xMax, yMin, yMax)

  • x_size – Output grid size in X axis (same unit as bbox).

  • y_size – Output grid size in Y axis (same unit as bbox).

Returns:

list of bounding boxes (xMin, xMax, yMin, yMax)

Compute Points

rsgislib.tools.geometrytools.get_bbox_centre_pt(bbox: List) List

Function which returns the centre point of a bbox (xMin, xMax, yMin, yMax)

Parameters:

bbox – the bbox (xMin, xMax, yMin, yMax)

Returns:

the centre point [xPt, yPt]

rsgislib.tools.geometrytools.find_point_on_whole_num_grid(pt: List[float], bbox: List[float], x_grid_res: float, y_grid_res: float) List[float]

A function which returns places a point on to the grid defined by the bbox, base_x_grid and base_y_grid

Parameters:
  • pt – the point (x, y)

  • bbox – the bounding box for the whole region defining the grid extent (MinX, MaxX, MinY, MaxY)

  • x_grid_res – the resolution of the grid in x axis

  • y_grid_res – the resolution of the grid in y axis

Returns:

returns a point (x, y) which now on the defined grid.

Representation

rsgislib.tools.geometrytools.get_bbox_geojson_poly(bbox: List) Dict

Get the bbox (xMin, xMax, yMin, yMax) represented as a GeoJSON polygon using dict and list.

Parameters:

bbox – (xMin, xMax, yMin, yMax)

Returns:

a dict with the geojson polygon representation of the bbox.