sentinelhub.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 the nearest integers.

Parameters
  • bbox (BBox) – bounding box

  • resolution (Union[float, Tuple[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

Tuple[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 (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

Raises

ValueError if CRS is not supported

Return type

Tuple[float, float]

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 (BBox) – bounding box

  • width (Optional[int]) – image width or None if height is unknown

  • height (Optional[int]) – 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 (BBox) – bounding box

Returns

bounding box in UTM CRS

Return type

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 (Sequence[float]) – boundaries of bounding box in pixels as [row1, col1, row2, col2]

  • transform (Sequence[float]) – 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[float]

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 (Optional[CRS]) – UTM coordinate reference system enum constants

Returns

east, north coordinates in UTM system

Return type

Tuple[float, float]

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

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

Parameters
  • east (float) – east coordinate

  • north (float) – north coordinate

  • crs (CRS) – CRS enum constants

Returns

latitude and longitude coordinates in WGS84 system

Return type

Tuple[float, float]

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

Convert a UTM coordinate to image coordinate given a transform

Parameters
  • east (float) – east coordinate of point

  • north (float) – north coordinate of point

  • transform (Sequence[float]) – 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

Union[Tuple[float, float], Tuple[int, int]]

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

Convert pixel coordinate to UTM coordinate given a transform

Parameters
  • row (float) – row pixel coordinate

  • column (float) – column pixel coordinate

  • transform (Sequence[float]) – 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

Tuple[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 (Sequence[float]) – georeferencing transform of the image, e.g. (x_upper_left, res_x, 0, y_upper_left, 0, -res_y)

  • utm_epsg (Optional[CRS]) – 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

Union[Tuple[float, float], Tuple[int, int]]

sentinelhub.geo_utils.get_utm_crs(lng, lat, source_crs=CRS.WGS84)[source]

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

Parameters
  • lng (float) – longitude

  • lat (float) – latitude

  • source_crs (CRS) – source CRS

Returns

CRS of the zone containing the lat,lon point

Return type

CRS

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

Maps point form src_crs to tgt_crs

Parameters
  • point (Tuple[float, float]) – a tuple (x, y)

  • source_crs (CRS) – source CRS

  • target_crs (CRS) – target CRS

  • always_xy (bool) – Parameter that is passed to pyproj.Transformer object and defines axis order for transformation. The default value True is in most cases the correct one.

Returns

point in target CRS

Return type

Tuple[float, float]