OS Data Hub Features API

FeaturesAPI

class osdatahub.FeaturesAPI.features_api.FeaturesAPI(key: str, product_name: str, extent: osdatahub.extent.Extent, spatial_filter_type: str = 'intersects')

Bases: object

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

Parameters
  • key (str) – A valid OS API Key. Get a free key here - https://osdatahub.os.uk/

  • product_name (str) – A valid OS product

  • extent (Extent) – The geographical extent of your query

  • spatial_filter_type (str) – Set the default spatial filter operation (defaults to “intersects”)

Example:

from osdatahub import FeaturesAPI, Extent
from os import environ

key = environ.get("OS_API_KEY")
extent = Extent.from_bbox((600000, 310200, 600900, 310900), "EPSG:27700")
features = FeaturesAPI(key, "zoomstack_local_buildings", extent)
results = features.query(limit=50)
DEFAULTS = {'count': 100, 'outputFormat': 'geojson', 'request': 'GetFeature', 'service': 'wfs', 'version': '2.0.0'}
ENDPOINT = 'https://api.os.uk/features/v1/wfs'
add_filters(*xml_filters: osdatahub.filters.Filter) None

Add XML filter strings to the final query

Parameters

xml_filters (str) – Valid OGC XML filter objects

property extent
property product
query(limit: int = 100) geojson.feature.FeatureCollection

Run a query of the OS Features API

Parameters

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

Returns

The results of the query in GeoJSON format

Return type

FeatureCollection

property xml_filter

Product

class osdatahub.FeaturesAPI.feature_products.Product(name, geometry)

Bases: tuple

geometry

Alias for field number 1

name

Alias for field number 0

osdatahub.FeaturesAPI.feature_products.convert_product_to_new_geometry(product: osdatahub.FeaturesAPI.feature_products.Product) osdatahub.FeaturesAPI.feature_products.Product

Takes a Product object and returns a copy with an updated geometry for the new API endpoint. The new API returns a MultiPolygon and a MultiLineString where the old API returned a Polygon and Linestring respectively. :param product Product): Product object to convert

Returns (Product): a copy of the Product object with updated geometry.

osdatahub.FeaturesAPI.feature_products.get_product(product_name: str, new_api: bool = False) osdatahub.FeaturesAPI.feature_products.Product
osdatahub.FeaturesAPI.feature_products.suggest_product(text: str) list
osdatahub.FeaturesAPI.feature_products.validate_product_name(product_name: str) str