fastpynuts.fastpynuts

This submodule defines the core functionality of fastpynuts.

Module Contents

Classes

NUTSregion

Hold a NUTS region’s geometry and bounding box for efficient querying. Properties from the NUTS dataset are accessible via the properties attribute.

NUTSfinder

Find NUTS regions for a point coordinate (lon, lat). Optionally restrict the NUTS levels of interest. Custom input files must follow the official NUTS naming convention.

API

class fastpynuts.fastpynuts.NUTSregion(feature, buffer=None)

Hold a NUTS region’s geometry and bounding box for efficient querying. Properties from the NUTS dataset are accessible via the properties attribute.

Construct a NUTSregion from a geojson-like feature like

feature = {
    'type': 'Feature',
    'geometry': {
        'type': 'MultiPolygon',
        'coordinates': [[[[x1, y1], ..., [xN, yN]]]]
    },
    'properties': {"NUTS_ID": "DE", ...}
}
id -> int

The region’s ID as specified by the field NUTS_ID. E.g. ‘DE’

property level

The region’s level as specified by the field LEVL_CODE. E.g. 0

property type

The region’s feature type as specified by the geometry. Either 'Polygon' or 'MultiPolygon'.

class fastpynuts.fastpynuts.NUTSfinder(geojsonfile, buffer_geoms=0, min_level=0, max_level=3)

Find NUTS regions for a point coordinate (lon, lat). Optionally restrict the NUTS levels of interest. Custom input files must follow the official NUTS naming convention.

Note: Points-in-polyon tests via shapely may suffer from floating-point precision issues for points on the boundary of regions. A buffer to the regions may be introduced via the buffer_geoms keyword to ensure the correct assignment. On the flip-side, a buffer may lead to the assignment of multiple regions for points on the boundary.

classmethod from_web(scale=1, year=2021, epsg=4326, datadir='.data', **kwargs) NUTSfinder

Download a NUTS file from Eurostat and construct a NUTSfinder object from it. If previously downloaded, use existing file instead. By default, the file will be saved in .data. The download location can be changed via the datadir keyword. The construction of the finder object can be specified via kwargs. For available keyword arguments, see the documentation of NUTSfinder.

find(lon, lat, valid_point=False, **kwargs) list

Find a point’s NUTS regions by longitude and latitude. For large-scale applications, if it is known, that the point corresponds to a valid location within the NUTS regions, use valid_point = True for a speedup.

find_level(lon, lat, level, valid_point=False) list