Extent Definition
Extent
- class osdatahub.extent.Extent(polygon: shapely.geometry.polygon.Polygon, crs: str)
Bases:
object
Extent is a dataclass that has two main uses:
It is a standardised way to store polygon extents that will interface with all of the osdatahub APIs.
It has multiple constructors that allow the user to create custom Extents without needing to write out polygon coordinates.
- property bbox: osdatahub.bbox.BBox
- crs: str
- classmethod from_bbox(bbox: Union[Collection[float], osdatahub.bbox.BBox], crs: str) osdatahub.extent.Extent
Creates a rectangular extent, given a bounding box.
- Parameters
bbox (Union[Collection[float], BBox]) – A bounding box, passed in as either a BBox object or a collection of the form (west, south, east, north).
crs (str) – The CRS corresponding to the bouding box, must be either ‘’EPSG:4326’, EPSG:27700’ or ‘EPSG:3857’.
- Raises
TypeError – If bbox is not a tuple or BBox object.
- Returns
A rectangular extent that matches the specified bounding box.
- Return type
- classmethod from_ons_code(ons_code: str) osdatahub.extent.Extent
Creates an extent of an existing ONS boundary. Note that the output will be in the “EPSG:4326” coordinate system. A full list of available ONS geographies can be found here: http://statistics.data.gov.uk/atlas/resource?uri=http://statistics.data.gov.uk/id/statistical-geography/K02000001
- Parameters
ons_code (str) – The code for the desired geography
- Raises
ValueError – If the ONS geography is not a Polygon.
- Returns
An extent of the ONS geography.
- Return type
- classmethod from_radius(centre: Iterable, radius: float, crs: str) osdatahub.extent.Extent
Creates a circular extent, given a centre point and a radius.
- Parameters
centre (Iterable) – Either a coordinate tuple in the form (x, y) or a shapely Point.
radius (float) – The radius of the circle in metres
crs (str) – The CRS corresponding to the point coordinate, must be either ‘EPSG:27700’ or ‘EPSG:3857’.
- Raises
TypeError – If centre is not a tuple or shapely Point.
- Returns
A rectangular extent that matches the specified bounding box.
- Return type
- is_within(bbox: Union[Collection[float], osdatahub.bbox.BBox]) bool
Checks whether a bounding box is within the Extent object
- Parameters
bbox (Union[Collection[float], BBox]) – A bounding box, passed in as either a BBox object or a collection of the form (west, south, east, north).
- Returns
True if the bounding box is within the Extent object, False if not
- Return type
bool
- polygon: shapely.geometry.polygon.Polygon
- set_crs(crs: str) osdatahub.extent.Extent
Changes the coordinate reference system of the Extent object to the value specified
- Parameters
crs (str) – The CRS to change to, must be either ‘’EPSG:4326’, EPSG:27700’ or ‘EPSG:3857’.
- Returns
A rectangular extent with an updated CRS
- Return type
- to_json()
Converts the extent object into a json
- Returns
A json containing the coordinates of the Extent
- Return type
dict
- property xml_coords: str