fastpynuts.fastpynuts
This submodule defines the core functionality of fastpynuts.
Module Contents
Classes
Hold a NUTS region’s geometry and bounding box for efficient querying.
Properties from the NUTS dataset are accessible via the |
|
Find NUTS regions for a point coordinate |
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
propertiesattribute.Construct a
NUTSregionfrom a geojson-like feature likefeature = { '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
shapelymay suffer from floating-point precision issues for points on the boundary of regions. A buffer to the regions may be introduced via thebuffer_geomskeyword 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
NUTSfinderobject 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 thedatadirkeyword. The construction of the finder object can be specified viakwargs. For available keyword arguments, see the documentation ofNUTSfinder.
- 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 = Truefor a speedup.
- find_level(lon, lat, level, valid_point=False) list