src.digitaltwin.get_data_using_geoapis

This script provides functions to retrieve vector data from multiple providers, including StatsNZ, LINZ, LRIS, and MFE, using the ‘geoapis’ library. To access data from each provider, you’ll need to set an API key in the environment variables.

Classes

MFE

A class to manage fetching Vector data from MFE.

Functions

clean_fetched_vector_data(→ geopandas.GeoDataFrame)

Clean the fetched vector data by performing necessary transformations.

fetch_vector_data_using_geoapis(→ geopandas.GeoDataFrame)

Fetch vector data using 'geoapis' based on the specified data provider, layer ID, and other parameters.

Module Contents

class src.digitaltwin.get_data_using_geoapis.MFE

Bases: geoapis.vector.WfsQueryBase

A class to manage fetching Vector data from MFE.

General details at: https://data.mfe.govt.nz/ API details at: https://help.koordinates.com/

Note that the ‘GEOMETRY_NAMES’ used when making WFS ‘cql_filter’ queries varies between layers. The MFE generally follows the LINZ LDS but uses ‘Shape’ in place of ‘shape’. It still uses ‘GEOMETRY’.

NETLOC_API = 'data.mfe.govt.nz'
GEOMETRY_NAMES = ['GEOMETRY', 'Shape']
src.digitaltwin.get_data_using_geoapis.clean_fetched_vector_data(fetched_data: geopandas.GeoDataFrame) geopandas.GeoDataFrame

Clean the fetched vector data by performing necessary transformations.

Parameters:

fetched_data (gpd.GeoDataFrame) – A GeoDataFrame containing the fetched vector data.

Returns:

A GeoDataFrame containing the cleaned vector data.

Return type:

gpd.GeoDataFrame

src.digitaltwin.get_data_using_geoapis.fetch_vector_data_using_geoapis(data_provider: str, layer_id: int, crs: int = 2193, verbose: bool = False, bounding_polygon: geopandas.GeoDataFrame | None = None) geopandas.GeoDataFrame

Fetch vector data using ‘geoapis’ based on the specified data provider, layer ID, and other parameters.

Parameters:
  • data_provider (str) – The data provider to use. Supported values: “StatsNZ”, “LINZ”, “LRIS”, “MFE”.

  • layer_id (int) – The ID of the layer to fetch.

  • crs (int = 2193) – The coordinate reference system (CRS) code to use. Default is 2193.

  • verbose (bool = False) – Whether to print messages. Default is False.

  • bounding_polygon (Optional[gpd.GeoDataFrame] = None) – Bounding polygon for data fetching. Default is all of New Zealand.

Returns:

A GeoDataFrame containing the fetched vector data.

Return type:

gpd.GeoDataFrame

Raises:

ValueError – If an unsupported ‘data_provider’ value is provided.