RSGISLib Projection Tools

Representation

rsgislib.tools.projection.get_epsg_code_from_wkt(wkt_str: str) int

Using GDAL to return the EPSG code for inputted WKT string.

Returns:

the EPSG code.

rsgislib.tools.projection.get_wkt_from_epsg_code(epsg_code: int) str

Using GDAL to return the WKT string for inputted EPSG Code.

Parameters:

epsg_code – integer variable of the epsg code.

Returns:

string with WKT representation of the projection.

GDAL / OSR

rsgislib.tools.projection.get_osr_prj_obj(epsg_code: int) <osgeo.osr.SpatialReference; proxy of <Swig Object of type 'OSRSpatialReferenceShadow *' at 0x7fcacb48a040> >

A function which returns an OSR SpatialReference object for a given EPSG code.

Parameters:

epsg_code – An EPSG code for the projection. Must be an integer.

Returns:

osr.SpatialReference object.

Conversion

rsgislib.tools.projection.degrees_to_metres(latitude: float, lon_size: float, lat_size: float) -> (<class 'float'>, <class 'float'>)

Convert pixel sizes or distances in degrees to metres.

Parameters:
  • latitude – latitude

  • lon_size – numpy array of x pixel sizes (degrees)

  • lat_size – numpy array of y pixel sizes (degrees)

Returns:

x_size (numpy array of x pixel sizes (m)), y_size (numpy array of y pixel sizes (m))

from rsgislib import tools
x_size, y_size = tools.degrees_to_metres(52,1.0,1.0)
rsgislib.tools.projection.metres_to_degrees(latitude: float, x_size: float, y_size: float) -> (<class 'float'>, <class 'float'>)

Convert pixel sizes or distances in metres to degrees.

Parameters:
  • latitude – latitude

  • x_size – numpy array of x pixel sizes (m)

  • y_size – numpy array of y pixel sizes (m)

Returns:

lon_size (numpy array of x pixel sizes (degrees)), lat_size (numpy array of y pixel sizes (degrees))

from rsgislib import tools
x_size, y_size = tools.metres_to_degrees(52, 1.0, 1.0)

Numeric Representation

rsgislib.tools.projection.get_deg_coord_as_str(lat: float, lon: float, n_chars: int = 4) str

A function which produces a string representation of the coordinate provided in degrees.

Parameters:
  • lat – the latitude in degrees

  • lon – the longitude in degrees

  • n_chars – the number of characters to be used for each number.

Returns:

string representation of the coordinates.

Calculation

rsgislib.tools.projection.great_circle_distance(wgs84_p1: List[float], wgs84_p2: List[float], earth_radius=6378137.0) float

A function which calculates the great circle distance between two points provided in degrees and projected with WGS84.

Parameters:
  • wgs84_p1 – A point provided as a list [lon (x), lat (y)]

  • wgs84_p2 – A point provided as a list [lon (x), lat (y)]

  • earth_radius – the radius of the earth to use for the calculation. The unit of this distance will define the unit of the returned distance. The default is 6,378,137 metres and therefore the the returned distance will also be in metres. However, if 6378.137 km was passed then the returned value will be in km.

Returns:

the great circle distance between the two points.