geo_utils

Module for manipulation of geographical information

sentinelhub.geo_utils.bbox_to_dimensions(bbox, resolution)[source]

Calculates width and height in pixels for a given bbox of a given pixel resolution (in meters). The result is rounded to nearest integers

Parameters:
  • bbox (geometry.BBox) – bounding box
  • resolution (float or (float, float)) – Resolution of desired image in meters. It can be a single number or a tuple of two numbers - resolution in horizontal and resolution in vertical direction.
Returns:

width and height in pixels for given bounding box and pixel resolution

Return type:

int, int

sentinelhub.geo_utils.bbox_to_resolution(bbox, width, height, meters=True)[source]

Calculates pixel resolution for a given bbox of a given width and height. By default it returns result in meters.

Parameters:
  • bbox (geometry.BBox) – bounding box
  • width (int) – width of bounding box in pixels
  • height (int) – height of bounding box in pixels
  • meters (bool) – If True result will be given in meters, otherwise it will be given in units of current CRS
Returns:

resolution east-west at north and south, and resolution north-south for given CRS

Return type:

float, float

Raises:

ValueError if CRS is not supported

sentinelhub.geo_utils.get_image_dimension(bbox, width=None, height=None)[source]

Given bounding box and one of the parameters width or height it will return the other parameter that will best fit the bounding box dimensions

Parameters:
  • bbox (geometry.BBox) – bounding box
  • width (int or None) – image width or None if height is unknown
  • height (int or None) – image height or None if height is unknown
Returns:

width or height rounded to integer

Return type:

int

sentinelhub.geo_utils.to_utm_bbox(bbox)[source]

Transform bbox into UTM CRS

Parameters:bbox (geometry.BBox) – bounding box
Returns:bounding box in UTM CRS
Return type:geometry.BBox
sentinelhub.geo_utils.get_utm_bbox(img_bbox, transform)[source]

Get UTM coordinates given a bounding box in pixels and a transform

Parameters:
  • img_bbox (list) – boundaries of bounding box in pixels as [row1, col1, row2, col2]
  • transform (tuple or list) – georeferencing transform of the image, e.g. (x_upper_left, res_x, 0, y_upper_left, 0, -res_y)
Returns:

UTM coordinates as [east1, north1, east2, north2]

Return type:

list

sentinelhub.geo_utils.wgs84_to_utm(lng, lat, utm_crs=None)[source]

Convert WGS84 coordinates to UTM. If UTM CRS is not set it will be calculated automatically.

Parameters:
  • lng (float) – longitude in WGS84 system
  • lat (float) – latitude in WGS84 system
  • utm_crs (constants.CRS or None) – UTM coordinate reference system enum constants
Returns:

east, north coordinates in UTM system

Return type:

float, float

sentinelhub.geo_utils.to_wgs84(east, north, crs)[source]

Convert any CRS with (east, north) coordinates to WGS84

Parameters:
Returns:

latitude and longitude coordinates in WGS84 system

Return type:

float, float

sentinelhub.geo_utils.utm_to_pixel(east, north, transform, truncate=True)[source]

Convert UTM coordinate to image coordinate given a transform

Parameters:
  • east (float) – east coordinate of point
  • north (float) – north coordinate of point
  • transform (tuple or list) – georeferencing transform of the image, e.g. (x_upper_left, res_x, 0, y_upper_left, 0, -res_y)
  • truncate (bool) – Whether to truncate pixel coordinates. Default is True
Returns:

row and column pixel image coordinates

Return type:

float, float or int, int

sentinelhub.geo_utils.pixel_to_utm(row, column, transform)[source]

Convert pixel coordinate to UTM coordinate given a transform

Parameters:
  • row (int or float) – row pixel coordinate
  • column (int or float) – column pixel coordinate
  • transform (tuple or list) – georeferencing transform of the image, e.g. (x_upper_left, res_x, 0, y_upper_left, 0, -res_y)
Returns:

east, north UTM coordinates

Return type:

float, float

sentinelhub.geo_utils.wgs84_to_pixel(lng, lat, transform, utm_epsg=None, truncate=True)[source]

Convert WGS84 coordinates to pixel image coordinates given transform and UTM CRS. If no CRS is given it will be calculated it automatically.

Parameters:
  • lng (float) – longitude of point
  • lat (float) – latitude of point
  • transform (tuple or list) – georeferencing transform of the image, e.g. (x_upper_left, res_x, 0, y_upper_left, 0, -res_y)
  • utm_epsg (constants.CRS or None) – UTM coordinate reference system enum constants
  • truncate (bool) – Whether to truncate pixel coordinates. Default is True
Returns:

row and column pixel image coordinates

Return type:

float, float or int, int

sentinelhub.geo_utils.get_utm_crs(lng, lat, source_crs=<CRS.WGS84: '4326'>)[source]

Get CRS for UTM zone in which (lat, lng) is contained.

Parameters:
Returns:

CRS of the zone containing the lat,lon point

Return type:

constants.CRS

sentinelhub.geo_utils.transform_point(point, source_crs, target_crs)[source]

Maps point form src_crs to tgt_crs

Parameters:
Returns:

point in target CRS

Return type:

(float, float)

sentinelhub.geo_utils.transform_bbox(bbox, target_crs)[source]

Maps bbox from current crs to target_crs

Parameters:
Returns:

bounding box in target CRS

Return type:

geometry.BBox