OS Data Hub NGD API

NGD

class osdatahub.NGD.ngd_api.NGD(key: str, collection: str)

Bases: object

Main class for querying OS NGD Features API (https://osdatahub.os.uk/docs/ofa/overview)

Parameters

Example:

from osdatahub import NGD
from os import environ

key = environ.get("OS_API_KEY")
extent = Extent.from_bbox((600000, 310200, 600900, 310900), "EPSG:27700")
features = NGD(key, "bld-fts-buildingline")
results = features.query(max_results=50, extent=extent)
classmethod get_collections() dict

Retrieves all OS NGD Feature Collections :returns: Dictionary containing all Feature Collections currently supported with details for each :rtype: Dict

query(extent: Optional[osdatahub.extent.Extent] = None, crs: Optional[Union[str, int]] = None, start_datetime: Optional[datetime.datetime] = None, end_datetime: Optional[datetime.datetime] = None, cql_filter: Optional[str] = None, filter_crs: Optional[Union[str, int]] = None, max_results: int = 100, offset: int = 0) geojson.feature.FeatureCollection

Retrieves features from a Collection

Parameters
  • extent (Extent, optional) – An extent, either from a bounding box or a Polygon. Only features within this extent will be returned Available CRS values are: EPSG:27700, EPSG:4326, EPSG:3857, and CRS84. Defaults to CRS84

  • crs (str|int, optional) – The CRS for the returned features, either in the format “epsg:xxxx” or an epsg number. e.g. British National Grid can be supplied as “epsg:27700” or 27700. Available CRS values are: EPSG:27700, EPSG:4326, EPSG:7405, EPSG:3857, and CRS84. Defaults to CRS84

  • start_datetime (datetime, optional) – Selects features that have a temporal property after the given start time. If you want to query a single timestamp, provide the same value to both start_datetime and end_datetime

  • end_datetime (datetime, optional) – Selects features that have a temporal property before the given end time. If you want to query a single timestamp, provide the same value to both start_datetime and end_datetime

  • cql_filter (str, optional) – A filter query in the CQL format. More information about supported CQL operators can be found at https://osdatahub.os.uk/docs/ofa/technicalSpecification

  • filter_crs (str|int, optional) – The CRS for a given CQL query, either in the format “epsg:xxxx” or an epsg number. e.g. British National Grid can be supplied as “epsg:27700” or 27700 Available CRS values are: EPSG:27700, EPSG:4326, EPSG:7405, EPSG:3857, and CRS84. Defaults to CRS84

  • max_results (int, optional) – The maximum number of features to return. Defaults to 100

  • offset (int, optional) – The offset number skips past the specified number of features in the collection. Defaults to 0

Returns

The results of the query in GeoJSON format

Return type

FeatureCollection

query_feature(feature_id: str, crs: Optional[Union[str, int]] = None) geojson.feature.Feature

Retrieves a single feature from a collection

Parameters
  • feature_id – An identifier ID for a feature

  • crs (str|int, optional) – The CRS for the returned feature, either in the format “epsg:xxxx” or an epsg number. e.g. British National Grid can be supplied as “epsg:27700” or 27700. Available CRS values are: EPSG:27700, EPSG:4326, EPSG:7405, EPSG:3857, and CRS84. Defaults to CRS84

Returns

A GeoJSON Feature containing the requested feature

Return type

Feature