geometry

Module implementing geometry classes

class sentinelhub.geometry.BaseGeometry(crs)[source]

Bases: abc.ABC

Base geometry class

Parameters:crs (constants.CRS) – Coordinate reference system of the geometry
crs

Returns the coordinate reference system (CRS)

Returns:Coordinate reference system Enum
Return type:constants.CRS
get_crs()[source]

Returns the coordinate reference system (CRS)

Returns:Coordinate reference system Enum
Return type:constants.CRS
geometry

An abstract property - ever subclass must implement geometry property

get_geometry()[source]

Returns shapely geometry

Returns:A polygon or multipolygon
Return type:shapely.geometry.Polygon or shapely.geometry.MultiPolygon
geojson

Returns representation in a GeoJSON format. Use json.dump for writing it to file.

Returns:A dictionary in GeoJSON format
Return type:dict
get_geojson()[source]

Returns representation in a GeoJSON format. Use json.dump for writing it to file.

Returns:A dictionary in GeoJSON format
Return type:dict
wkt

Transforms geometry object into Well-known text format

Returns:string in WKT format
Return type:str
class sentinelhub.geometry.BBox(bbox, crs)[source]

Bases: sentinelhub.geometry.BaseGeometry

Class representing a bounding box in a given CRS.

Throughout the sentinelhub package this class serves as the canonical representation of a bounding box. It can initialize itself from multiple representations:

  1. ((min_x,min_y),(max_x,max_y)),
  2. (min_x,min_y,max_x,max_y),
  3. [min_x,min_y,max_x,max_y],
  4. [[min_x, min_y],[max_x,max_y]],
  5. [(min_x, min_y),(max_x,max_y)],
  6. ([min_x, min_y],[max_x,max_y]),
  7. 'min_x,min_y,max_x,max_y',
  8. {'min_x':min_x, 'max_x':max_x, 'min_y':min_y, 'max_y':max_y},
  9. bbox, where bbox is an instance of BBox.
Note that BBox coordinate system depends on crs parameter:
  • In case of constants.CRS.WGS84 axis x represents longitude and axis y represents latitude
  • In case of constants.CRS.POP_WEB axis x represents easting and axis y represents northing
  • In case of constants.CRS.UTM_* axis x represents easting and axis y represents northing
Parameters:
  • bbox – A bbox in any valid representation
  • crs (constants.CRS) – Coordinate reference system of the bounding box
lower_left

Returns the lower left vertex of the bounding box

Returns:min_x, min_y
Return type:(float, float)
get_lower_left()[source]

Returns the lower left vertex of the bounding box

Returns:min_x, min_y
Return type:(float, float)
upper_right

Returns the upper right vertex of the bounding box

Returns:max_x, max_y
Return type:(float, float)
get_upper_right()[source]

Returns the upper right vertex of the bounding box

Returns:max_x, max_y
Return type:(float, float)
middle

Returns the middle point of the bounding box

Returns:middle point
Return type:(float, float)
get_middle()[source]

Returns the middle point of the bounding box

Returns:middle point
Return type:(float, float)
reverse()[source]

Returns a new BBox object where x and y coordinates are switched

Returns:New BBox object with switched coordinates
Return type:BBox
transform(crs)[source]

Transforms BBox from current CRS to target CRS

Parameters:crs (constants.CRS) – target CRS
Returns:Bounding box in target CRS
Return type:BBox
buffer(buffer)[source]

Changes both BBox dimensions (width and height) by a percentage of size of each dimension. If number is negative, the size will decrease. Returns a new instance of BBox object.

Parameters:buffer (float) – A percentage of BBox size change
Returns:A new bounding box of buffered size
Return type:BBox
get_polygon(reverse=False)[source]

Returns a tuple of coordinates of 5 points describing a polygon. Points are listed in clockwise order, first point is the same as the last.

Parameters:reverse (bool) – True if x and y coordinates should be switched and False otherwise
Returns:((x_1, y_1), … , (x_5, y_5))
Return type:tuple(tuple(float))
geometry

Returns polygon geometry in shapely format

Returns:A polygon in shapely format
Return type:shapely.geometry.polygon.Polygon
get_partition(num_x=1, num_y=1)[source]

Partitions bounding box into smaller bounding boxes of the same size.

Parameters:
  • num_x (int) – Number of parts BBox will be horizontally divided into.
  • num_y (int or None) – Number of parts BBox will be vertically divided into.
Returns:

Two-dimensional list of smaller bounding boxes. Their location is

Return type:

list(list(BBox))

get_transform_vector(resx, resy)[source]

Given resolution it returns a transformation vector

Parameters:
  • resx (float or int) – Resolution in x direction
  • resy (float or int) – Resolution in y direction
Returns:

A tuple with 6 numbers representing transformation vector

Return type:

tuple(float)

class sentinelhub.geometry.Geometry(geometry, crs)[source]

Bases: sentinelhub.geometry.BaseGeometry

A class that combines shapely geometry with coordinate reference system. It currently supports polygons and multipolygons.

It can be initialize with any of the following geometry representations: - shapely.geometry.Polygon or shapely.geometry.MultiPolygon - A GeoJSON dictionary with (multi)polygon coordinates - A WKT string with (multi)polygon coordinates

Parameters:
  • geometry (shapely.geometry.Polygon or shapely.geometry.MultiPolygon or dict or str) – A polygon or multipolygon in any valid representation
  • crs (constants.CRS) – Coordinate reference system of the geometry
reverse()[source]

Returns a new Geometry object where x and y coordinates are switched

Returns:New Geometry object with switched coordinates
Return type:Geometry
transform(crs)[source]

Transforms Geometry from current CRS to target CRS

Parameters:crs (constants.CRS) – target CRS
Returns:Geometry in target CRS
Return type:Geometry
geometry

Returns shapely object representing geometry in this class

Returns:A polygon or a multipolygon in shapely format
Return type:shapely.geometry.Polygon or shapely.geometry.MultiPolygon
bbox

Returns BBox object representing bounding box around the geometry

Returns:A bounding box, with same CRS
Return type:BBox
class sentinelhub.geometry.BBoxCollection(bbox_list)[source]

Bases: sentinelhub.geometry.BaseGeometry

A collection of bounding boxes

Parameters:bbox_list (list(BBox)) – A list of BBox objects which have to be in the same CRS
bbox_list

Returns the list of bounding boxes from collection

Returns:The list of bounding boxes
Return type:list(BBox)
geometry

Returns shapely object representing geometry

Returns:A multipolygon of bounding boxes
Return type:shapely.geometry.MultiPolygon
bbox

Returns BBox object representing bounding box around the geometry

Returns:A bounding box, with same CRS
Return type:BBox
reverse()[source]

Returns a new BBoxCollection object where all x and y coordinates are switched

Returns:New Geometry object with switched coordinates
Return type:BBoxCollection
transform(crs)[source]

Transforms BBoxCollection from current CRS to target CRS

Parameters:crs (constants.CRS) – target CRS
Returns:BBoxCollection in target CRS
Return type:BBoxCollection