Skip to content

Commit

Permalink
some adjustments to CSW facade
Browse files Browse the repository at this point in the history
  • Loading branch information
matthesrieke committed Nov 18, 2024
1 parent 3bdeefe commit af33f6e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 197 deletions.
195 changes: 13 additions & 182 deletions pygeoapi-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ server:
# connection: /tmp/pygeoapi-process-manager.db
# output_dir: /tmp/
# ogc_schemas_location: /opt/schemas.opengis.net


components:
resource_registry: CrudConfigResourceRegistry

logging:
level: ERROR
level: INFO
#logfile: /tmp/pygeoapi.log

metadata:
Expand Down Expand Up @@ -101,202 +104,30 @@ metadata:
role: pointOfContact

resources:
obs:
type: collection
title: Observations
description: My cool observations
keywords:
- observations
- monitoring
linked-data:
context:
- datetime: https://schema.org/DateTime
- vocab: https://example.com/vocab#
stn_id: "vocab:stn_id"
value: "vocab:value"
links:
- type: text/csv
rel: canonical
title: data
href: https://github.com/mapserver/mapserver/blob/branch-7-0/msautotest/wxs/data/obs.csv
hreflang: en-US
- type: text/csv
rel: alternate
title: data
href: https://raw.githubusercontent.com/mapserver/mapserver/branch-7-0/msautotest/wxs/data/obs.csv
hreflang: en-US
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
temporal:
begin: 2000-10-30T18:24:39Z
end: 2007-10-30T08:57:29Z
providers:
- type: feature
name: CSV
data: tests/data/obs.csv
id_field: id
geometry:
x_field: long
y_field: lat

lakes:
eumetsat-catalogue:
type: collection
title:
en: Large Lakes
fr: Grands Lacs
en: EUMETSAT User Portal catalogue
description:
en: lakes of the world, public domain
fr: lacs du monde, domaine public
en: metadata records from user.eumetsat.int
keywords:
en:
- lakes
- water bodies
fr:
- lacs
- plans d'eau
links:
- type: text/html
rel: canonical
title: information
href: http://www.naturalearthdata.com/
hreflang: en-US
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
temporal:
begin: 2011-11-11T11:11:11Z
end: null # or empty (either means open ended)
providers:
- type: feature
name: GeoJSON
data: tests/data/ne_110m_lakes.geojson
id_field: id
title_field: name

mapserver_world_map:
type: collection
title: MapServer demo WMS world map
description: MapServer demo WMS world map
keywords:
- MapServer
- world map
links:
- type: text/html
rel: canonical
title: information
href: https://demo.mapserver.org
hreflang: en-US
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
providers:
- type: map
name: WMSFacade
data: https://demo.mapserver.org/cgi-bin/msautotest
options:
layer: world_latlong
style: default
format:
name: png
mimetype: image/png

gdps-temperature:
type: collection
title: Global Deterministic Prediction System sample
description: Global Deterministic Prediction System sample
keywords:
- gdps
- global
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
links:
- type: text/html
rel: canonical
title: information
href: https://eccc-msc.github.io/open-data/msc-data/nwp_gdps/readme_gdps_en
hreflang: en-CA
providers:
- type: coverage
name: rasterio
data: tests/data/CMC_glb_TMP_TGL_2_latlon.15x.15_2020081000_P000.grib2
options:
DATA_ENCODING: COMPLEX_PACKING
format:
name: GRIB
mimetype: application/x-grib2

test-data:
type: stac-collection
title: pygeoapi test data
description: pygeoapi test data
keywords:
- poi
- portugal
links:
- type: text/html
rel: canonical
title: information
href: https://github.com/geopython/pygeoapi/tree/master/tests/data
hreflang: en-US
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
providers:
- type: stac
name: FileSystem
data: tests/data
file_types:
- .gpkg
- .sqlite
- .csv
- .grib2
- .tif
- .shp

canada-metadata:
type: collection
title:
en: Open Canada sample data
fr: Exemple de donn\u00e9es Canada Ouvert
description:
en: Sample metadata records from open.canada.ca
fr: Exemples d'enregistrements de m\u00e9tadonn\u00e9es sur ouvert.canada.ca
keywords:
en:
- canada
- eumetsat
- open data
fr:
- canada
- donn\u00e9es ouvertes
links:
- type: text/html
rel: canonical
title: information
href: https://open.canada.ca/en/open-data
hreflang: en-CA
- type: text/html
rel: alternate
title: informations
href: https://ouvert.canada.ca/fr/donnees-ouvertes
hreflang: fr-CA
href: https://user.eumetsat.int/catalogue
hreflang: en-EN
extents:
spatial:
bbox: [-180,-90,180,90]
crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
providers:
- type: record
name: TinyDBCatalogue
data: tests/data/open.canada.ca/sample-records.tinydb
id_field: externalId
time_field: created
title_field: title
name: CSWFacade
data: https://user.eumetsat.int/catalogue/elastic-csw/service

hello-world:
type: process
Expand Down
35 changes: 20 additions & 15 deletions pygeoapi/provider/csw_facade.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def __init__(self, provider_def):
'title': ('dc:title', 'title'),
'description': ('dct:abstract', 'abstract'),
'keywords': ('dc:subject', 'subjects'),
'date': ('dc:date', 'date'),
'date': ('gmd:dateStamp', 'datetimestamp'),
'created': ('dct:created', 'created'),
'updated': ('dct:modified', 'modified'),
'rights': ('dc:rights', 'rights'),
Expand Down Expand Up @@ -179,7 +179,7 @@ def query(self, offset=0, limit=10, resulttype='results',
csw = self._get_csw()
try:
csw.getrecords2(esn='full', maxrecords=limit, startposition=offset,
constraints=constraints, sortby=sortby2,
constraints=constraints, sortby=sortby2, outputschema="http://www.isotc211.org/2005/gmd", typenames="gmd:MD_Metadata",

Check failure on line 182 in pygeoapi/provider/csw_facade.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/provider/csw_facade.py#L182

[E501] line too long
resulttype=resulttype)
except ExceptionReport as err:
msg = f'CSW error {err}'
Expand All @@ -192,6 +192,7 @@ def query(self, offset=0, limit=10, resulttype='results',
LOGGER.debug(f"Returned {response['numberReturned']} records")

LOGGER.debug('Building result set')
LOGGER.warn(len(csw.records))
for record in csw.records.values():
response['features'].append(self._owslibrecord2record(record))

Expand Down Expand Up @@ -227,7 +228,9 @@ def _get_csw(self) -> CatalogueServiceWeb:
"""

try:
return CatalogueServiceWeb(self.data)
result = CatalogueServiceWeb(self.data, skip_caps=True)
LOGGER.warn(result.url)
return result
except Exception as err:
err = f'CSW connection error: {err}'
LOGGER.error(err)
Expand Down Expand Up @@ -259,42 +262,44 @@ def _gen_getrecordbyid_link(self, identifier: str,
}

def _owslibrecord2record(self, record):
LOGGER.debug(f'Transforming {record.identifier}')
LOGGER.warn(f'Transforming {record}')
feature = {
'id': record.identifier,
'type': 'Feature',
'geometry': None,
'time': record.date or None,
'time': record.datetimestamp or None,
'properties': {},
'links': [
self._gen_getrecordbyid_link(record.identifier)
]
}

LOGGER.debug('Processing record mappings to properties')
LOGGER.warn(record.identification[0].bbox)
for key, value in self.record_mappings.items():
prop_value = getattr(record, value[1])
if prop_value not in [None, [], '']:
feature['properties'][key] = prop_value
if hasattr(record, value[1]):
prop_value = getattr(record, value[1])
if prop_value not in [None, [], '']:
feature['properties'][key] = prop_value

if record.bbox is not None:
if hasattr(record, "identification") and len(record.identification) > 0 and record.identification[0].bbox is not None:

Check failure on line 285 in pygeoapi/provider/csw_facade.py

View workflow job for this annotation

GitHub Actions / flake8_py3

pygeoapi/provider/csw_facade.py#L285

[E501] line too long
LOGGER.debug('Adding bbox')
bbox = [
get_typed_value(record.bbox.minx),
get_typed_value(record.bbox.miny),
get_typed_value(record.bbox.maxx),
get_typed_value(record.bbox.maxy)
get_typed_value(record.identification[0].bbox.minx),
get_typed_value(record.identification[0].bbox.miny),
get_typed_value(record.identification[0].bbox.maxx),
get_typed_value(record.identification[0].bbox.maxy)
]
feature['geometry'] = bbox2geojsongeometry(bbox)

if record.references:
if hasattr(record, "references"):
LOGGER.debug('Adding references as links')
for link in record.references:
feature['links'].append({
'title': link['scheme'],
'href': link['url']
})
if record.uris:
if hasattr(record, "uris"):
LOGGER.debug('Adding URIs as links')
for link in record.uris:
feature['links'].append({
Expand Down

0 comments on commit af33f6e

Please sign in to comment.