Skip to content

Basic Usage

Rose Pearson edited this page Nov 8, 2022 · 22 revisions

geoapis is designed to be used as a library. See Package Install for installation instructions.

lidar.OpenTopography

This saves LiDAR datas in the specified location on your computer. Data can either be selected as being within a search polygon, by name or both. Each dataset is saved in its own folder with its dataset name.

All datasets within a search polygon:

import geoapis.lidar

lidar_fetcher = geoapis.lidar.OpenTopography(cache_path=r"local/path/to/folder/to/save/files", 
                                             search_polygon=polygon, verbose=True)
lidar_fetcher.run()

A single dataset by name within a search polygon:

import geoapis.lidar

lidar_fetcher = geoapis.lidar.OpenTopography(cache_path=r"local/path/to/folder/to/save/files",
                                             search_polygon=polygon, verbose=True)
lidar_fetcher.run("Wellington_2013")

A complete single dataset by name:

import geoapis.lidar

lidar_fetcher = geoapis.lidar.OpenTopography(cache_path=r"local/path/to/folder/to/save/files", verbose=True)
lidar_fetcher.run("Wellington_2013")

vector.WfsQuery, vector.Linz, vector.Lris or vector.StatsNz

This returns unlimited vector layers from either any WFS data service (using vector.WfsQuery) or the LINZ, LRIS or Stats NZ data services. Call run for each layer you would like to be returned. The vector is returned as a geopandas.GeoDataFrame. The vector.WfsQuery class requires the netloc_url and geometry_names to be specified.

vector.WfsQuery

import geoapis.vector

vector_fetcher = geoapis.vector.WfsQuery(key="LINZ_API_KEY", netloc_url="data.linz.govt.nz",
                                         geometry_names=['GEOMETRY', 'shape'],
                                         bounding_polygon=polygon, verbose=True)
vector_layer_1 = vector_fetcher.run(layer_id_1)
vector_layer_2 = vector_fetcher.run(layer_id_2)

vector.Linz, vector.Lris, vector.StatsNz

import geoapis.vector

vector_fetcher = geoapis.vector.Linz("LINZ_API_KEY", bounding_polygon=polygon, verbose=True)
vector_layer_1 = vector_fetcher.run(layer_id_1)
vector_layer_2 = vector_fetcher.run(layer_id_2)

raster.Linz, raster.Lris, raster.StatsNz, raster.KoordinatesQuery

This returns unlimited raster tiles from either any Koordinates data service (using raster.KoordinatesQuery) or the LINZ, LRIS or Stats NZ data services. Call run for each layer you would like to be returned. The returned data is downloaded and a path to the download is returned. The raster.KoordinatesQuery class requires the netloc_url to be specified.

raster.Linz, raster.Lris, raster.StatsNz

import geoapis.raster

raster_fetcher = geoapis.raster.Linz("LINZ_API_KEY",
                                     cache_path=r"local/path/to/folder/to/save/files", 
                                     bounding_polygon=polygon)
raster_layer_path_1 = vector_fetcher.run(layer_id_1)
raster_layer_path_2 = vector_fetcher.run(layer_id_2)

raster.KoordinatesQuery

import geoapis.raster

raster_fetcher = geoapis.raster.KoordinatesQuery(key="LINZ_API_KEY",
                                                 cache_path=r"local/path/to/folder/to/save/files",
                                                 netloc_url="data.linz.govt.nz",
                                                 bounding_polygon=polygon)
raster_layer_path_1 = raster_fetcher.run(layer_id_1)
raster_layer_path_2 = raster_fetcher.run(layer_id_2)

Basic Documentation

lidar.OpenTopography()

This class will locally download all LiDAR tiles from datasets within the specified polygon at a specified local directory.

class OpenTopography:
    """ A class to manage fetching LiDAR data from Open Topography
    API details for querying datasets within a search rectangle at:
        https://portal.opentopography.org/apidocs/#/Public/getOtCatalog
    Information for making a `bulk download` of a dataset using the AWS S3 protocol can be found by clicking on bulk
    download under any dataset.
    """

    def __init__(self, cache_path: typing.Union[str, pathlib.Path],
                 search_polygon: geopandas.geodataframe.GeoDataFrame, redownload_files: bool = False,
                 download_limit_gbytes: typing.Union[int, float] = 100, verbose: bool = False)

        ...

    def run(self):
        """ Download LiDAR dataset(s) either within a search_polygon, by name, or both """

vector.WfsQuery(), vector.Linz(), vector.Lris(), and vector.StatsNz()

These classes share the same interface and will locally download all vectors from the specified LINZ Data Service layer within the specified polygon at a specified local directory. The vector.WfsQuery class can be used for any WFS based data service if the netloc_url and geometry_names are specified; while the vector.Linz, vector.Lris, and vector.StatsNz classes can be used for specific WFS data services without specifying the netloc_url or geometry_names.

vector.WfsQuery

class WfsQuery:
    """ An class to manage fetching Vector data using WFS.

    The specified vector layer is queried each time run is called, and any layer features passing though the
    optionally defined bounding_polygon are returned. If no bounding_polygon is specified all layer features 
    are returned.

    Flexibility exists in the inputs. Only the key is required. If no bounding_polygon is specified all features
    in a layer will be downloaded. If no crs is specified, the bounding_polygon will be used if the bounding_polygon
    is specified. If no CRS or bounding_polygon is specified the CRS of the downloaded features will be used. """

    def __init__(self, key: str, netloc_url: str, geometry_names: typing.Union[list, str], crs: int = None, 
                 bounding_polygon: geopandas.geodataframe.GeoDataFrame = None,
                 verbose: bool = False):
        """ Load in vector information from the specified data service. Specify the layer to import during run.
        """

        ...

    def run(self, layer: int, geometry_name: str = "") -> geopandas.GeoDataFrame:
        """ Query for a specified layer and return a geopandas.GeoDataFrame of the vector features. If a
        polygon_boundary is specified, only return vectors passing through this polygon. """

vector.Linz, vector.Lris, vector.StatsNz

class Linz/Lris/StatsNz:
    """ An class to manage fetching Vector data using WFS.

    API details at: https://www.ogc.org/standards/wfs or
    https://www.linz.govt.nz/data/linz-data-service/guides-and-documentation/wfs-spatial-filtering

    The specified vector layer is queried each time run is called, and any layer features passing though the
    optionally defined bounding_polygon are returned. If no bounding_polygon is specified all layer features 
    are returned.

    Flexibility exists in the inputs. Only the key is required. If no bounding_polygon is specified all features
    in a layer will be downloaded. If no crs is specified, the bounding_polygon will be used if the bounding_polygon
    is specified. If no CRS or bounding_polygon is specified the CRS of the downloaded features will be used. """

    def __init__(self, key: str, crs: int = None, bounding_polygon: geopandas.geodataframe.GeoDataFrame = None,
                 verbose: bool = False):
        """ Load in vector information from LINZ. Specify the layer to import during run.
        """

        ...

    def run(self, layer: int, geometry_name: str = "") -> geopandas.GeoDataFrame:
        """ Query for a specified layer and return a geopandas.GeoDataFrame of the vector features. If a
        polygon_boundary is specified, only return vectors passing through this polygon. """