* add support for OGC API - Coverages * fix coverage CRS ref * fix ref to OACov schemas for testing * move spectral testing to after_success * update docs * add mask param to rasterio provider
This commit is contained in:
+63
-12
@@ -38,22 +38,22 @@ pygeoapi for easier maintenance of software updates.
|
||||
updates and package management
|
||||
|
||||
|
||||
Example: custom pygeoapi data provider
|
||||
--------------------------------------
|
||||
Example: custom pygeoapi vector data provider
|
||||
---------------------------------------------
|
||||
|
||||
Lets consider the steps for a data provider plugin (source code is located here: :ref:`data Provider`).
|
||||
Lets consider the steps for a vector data provider plugin (source code is located here: :ref:`data Provider`).
|
||||
|
||||
Python code
|
||||
^^^^^^^^^^^
|
||||
|
||||
The below template provides a minimal example (let's call the file ``mycooldata.py``:
|
||||
The below template provides a minimal example (let's call the file ``mycoolvectordata.py``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pygeoapi.provider.base import BaseProvider
|
||||
|
||||
class MyCoolDataProvider(BaseProvider):
|
||||
"""My cool data provider"""
|
||||
class MyCoolVectorDataProvider(BaseProvider):
|
||||
"""My cool vector data provider"""
|
||||
|
||||
def __init__(self, provider_def):
|
||||
"""Inherit from parent class"""
|
||||
@@ -91,7 +91,7 @@ The below template provides a minimal example (let's call the file ``mycooldata.
|
||||
|
||||
|
||||
For brevity, the above code will always return the single feature of the dataset. In reality, the plugin
|
||||
developer would connect to a data source with capabilities to run queries and return relevant a result set,
|
||||
developer would connect to a data source with capabilities to run queries and return a relevant result set,
|
||||
as well as implement the ``get`` method accordingly. As long as the plugin implements the API contract of
|
||||
its base provider, all other functionality is left to the provider implementation.
|
||||
|
||||
@@ -104,23 +104,23 @@ The following methods are options to connect the plugin to pygeoapi:
|
||||
|
||||
**Option 1**: Update in core pygeoapi:
|
||||
|
||||
- copy ``mycooldata.py`` into ``pygeoapi/provider``
|
||||
- copy ``mycoolvectordata.py`` into ``pygeoapi/provider``
|
||||
- update the plugin registry in ``pygeoapi/plugin.py:PLUGINS['provider']`` with the plugin's
|
||||
shortname (say ``MyCoolData``) and dotted path to the class (i.e. ``pygeoapi.provider.mycooldata.MyCoolDataProvider``)
|
||||
shortname (say ``MyCoolVectorData``) and dotted path to the class (i.e. ``pygeoapi.provider.mycoolvectordata.MyCoolVectorDataProvider``)
|
||||
- specify in your dataset provider configuration as follows:
|
||||
|
||||
.. code-block:: yaml
|
||||
|
||||
providers:
|
||||
- type: feature
|
||||
name: MyCoolData
|
||||
name: MyCoolVectorData
|
||||
data: /path/to/file
|
||||
id_field: stn_id
|
||||
|
||||
|
||||
**Option 2**: implement outside of pygeoapi and add to configuration (recommended)
|
||||
|
||||
- create a Python package of the ``mycooldata.py`` module (see `Cookiecutter`_ as an example)
|
||||
- create a Python package of the ``mycoolvectordata.py`` module (see `Cookiecutter`_ as an example)
|
||||
- install your Python package onto your system (``python setup.py install``). At this point your new package
|
||||
should be in the ``PYTHONPATH`` of your pygeoapi installation
|
||||
- specify in your dataset provider configuration as follows:
|
||||
@@ -129,10 +129,61 @@ The following methods are options to connect the plugin to pygeoapi:
|
||||
|
||||
providers:
|
||||
- type: feature
|
||||
name: mycooldatapackage.mycooldata.MyCoolDataProvider
|
||||
name: mycooldatapackage.mycoolvectordata.MyCoolVectorDataProvider
|
||||
data: /path/to/file
|
||||
id_field: stn_id
|
||||
|
||||
BEGIN
|
||||
|
||||
Example: custom pygeoapi raster data provider
|
||||
---------------------------------------------
|
||||
|
||||
Lets consider the steps for a raster data provider plugin (source code is located here: :ref:`data Provider`).
|
||||
|
||||
Python code
|
||||
^^^^^^^^^^^
|
||||
|
||||
The below template provides a minimal example (let's call the file ``mycoolrasterdata.py``:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pygeoapi.provider.base import BaseProvider
|
||||
|
||||
class MyCoolRasterDataProvider(BaseProvider):
|
||||
"""My cool raster data provider"""
|
||||
|
||||
def __init__(self, provider_def):
|
||||
"""Inherit from parent class"""
|
||||
|
||||
BaseProvider.__init__(self, provider_def)
|
||||
self.num_bands = 4
|
||||
self.axes = ['Lat', 'Long']
|
||||
|
||||
def get_coverage_domainset(self):
|
||||
# return a CIS JSON DomainSet
|
||||
|
||||
def get_coverage_rangetype(self):
|
||||
# return a CIS JSON RangeType
|
||||
|
||||
def query(self, bands=[], subsets={}, format_='json'):
|
||||
# process bands and subsets parameters
|
||||
# query/extract coverage data
|
||||
if format_ == 'json':
|
||||
# return a CoverageJSON representation
|
||||
return {'type': 'Coverage', ...} # trimmed for brevity
|
||||
else:
|
||||
# return default (likely binary) representation
|
||||
return bytes(112)
|
||||
|
||||
For brevity, the above code will always JSON for metadata and binary or CoverageJSON for the data. In reality, the plugin
|
||||
developer would connect to a data source with capabilities to run queries and return a relevant result set,
|
||||
As long as the plugin implements the API contract of its base provider, all other functionality is left to the provider
|
||||
implementation.
|
||||
|
||||
Each base class documents the functions, arguments and return types required for implementation.
|
||||
|
||||
END
|
||||
|
||||
Example: custom pygeoapi formatter
|
||||
----------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user