RSGISLib Geometry Tools

Projections

rsgislib.tools.geometrytools.reproj_bbox(bbox, in_osr_proj_obj, out_osr_proj_obj)

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, in_epsg, out_epsg)

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, out_osr_proj_obj, x, y)

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

Returns

x, y.

Testing

rsgislib.tools.geometrytools.do_bboxes_intersect(bbox1, bbox2)

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, bbox2)

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, bbox2)

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

Calculations

rsgislib.tools.geometrytools.calc_bbox_area(bbox)

Calculate the area of the bbox.

Parameters

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

Returns

area in projection of the bbox.

Compute New BBOX

rsgislib.tools.geometrytools.bbox_intersection(bbox1, bbox2)

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)

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, buf)

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)

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)

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, base_grid, other_extent, full_contain=True)

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, base_grid, full_contain=True)

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, base_grid, full_contain=True, round_vals=None)

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) or integer for number of significant figures to round to.

Returns

bbox (xMin, xMax, yMin, yMax)

rsgislib.tools.geometrytools.get_bbox_grid(bbox, x_size, y_size)

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)