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.Initialization
Construct a
NUTSregionfrom a geojson-like feature likefeature = { 'type': 'Feature', 'geometry': { 'type': 'MultiPolygon', 'coordinates': [[[[x1, y1], ..., [xN, yN]]]] }, 'properties': {"NUTS_ID": "DE", ...} }
- property id: str
The region’s ID as specified by the field
NUTS_ID. E.g. ‘DE’
- property level: int
The region’s level as specified by the field
LEVL_CODE. E.g. 0
- property type: str
The region’s feature type as specified by the geometry. Either
'Polygon'or'MultiPolygon'.
- class fastpynuts.fastpynuts.NUTSfinder(geojsonfile, buffer_geoms=None, 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.Initialization
- classmethod from_web(scale=1, year=2021, epsg=4326, level=None, datadir='.data', force_reload=False, temporary=False, **kwargs)
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.
- to_geometry_collection()
Construct a shapely
GeometryCollectionfrom the finder’s regions.
- to_geojson(geojsonfile)
Write the NUTSfinder’s regions to file as a FeatureCollection. Useful if the input dataset has been altered, i.e. by buffering, filtering, etc.
- 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_geometry(geom)
Find NUTS regions overlapping with a geometry.
geommust be either ashapelygeometry that supportsshapely.intersectsor must be a GeoJSON-like geometry that can be converted into such ashapelygeometry. Seeutils.geometry2shapelyfor info on supported formats ofgeom.
- find_bbox(lon_min, lat_min, lon_max, lat_max)
Find NUTS regions overlapping with a rectangle (format
(lon_min, lat_min, lon_max, lat_max)).
- static filter_levels(regions, *levels)
Filter the results of a
findoperation for specific NUTS levels.Usage
regions = nf.find_bbox((13.1, 47.2, 14.2, 49.0)) level3 = nf.filter_levels(regions, 3) level2or3 = nf.filter_levels(regions, 2, 3)