Using Python and OWSLib

OWSLib is a Python package which provides Pythonic access to OGC APIs and web services. Let’s see how easy it is to work with wis2box with standards-based tooling:

[13]:
from owslib.ogcapi.features import Features

import pandas as pd

def pretty_print(input):
    print(json.dumps(input, indent=2))


api = 'http://localhost:8999/pygeoapi'

Let’s load the wis2box API into OWSLib and inspect some data

[14]:
oafeat = Features(api)

collections = oafeat.collections()
print(f'This OGC API Features endpoint has {len(collections["collections"])} datasets')

for dataset in collections['collections']:
    print(dataset['title'])

malawi_obs = oafeat.collection_items('data.core.observations-surface-land.mw.FWCL.landFixed')
malawi_obs_df = pd.DataFrame(malawi_obs['features'])

# then filter by station
namitambo_obs = oafeat.collection_items('data.core.observations-surface-land.mw.FWCL.landFixed', wigos_station_identifier='0-454-2-AWSNAMITAMBO')
namitambo_obs_df = pd.DataFrame(namitambo_obs['features'])
print(malawi_obs_df.dtypes)
print(malawi_obs_df.head(3))
This OGC API Features endpoint has 3 datasets
Surface weather observations (hourly)
Stations
Discovery metadata
id            object
conformsTo    object
type          object
geometry      object
properties    object
dtype: object
                                        id  \
0  WIGOS_0-454-2-AWSBALAKA_20220114T075500
1  WIGOS_0-454-2-AWSBALAKA_20220114T085500
2  WIGOS_0-454-2-AWSBALAKA_20220114T095500

                                          conformsTo     type  \
0  [http://www.opengis.net/spec/ogcapi-features-1...  Feature
1  [http://www.opengis.net/spec/ogcapi-features-1...  Feature
2  [http://www.opengis.net/spec/ogcapi-features-1...  Feature

                                            geometry  \
0  {'type': 'Point', 'coordinates': [34.97, -14.9...
1  {'type': 'Point', 'coordinates': [34.97, -14.9...
2  {'type': 'Point', 'coordinates': [34.97, -14.9...

                                          properties
0  {'identifier': 'WIGOS_0-454-2-AWSBALAKA_202201...
1  {'identifier': 'WIGOS_0-454-2-AWSBALAKA_202201...
2  {'identifier': 'WIGOS_0-454-2-AWSBALAKA_202201...