Skip to content

Commit

Permalink
Add Support for WCS Probe - WcsGetCoverage (#422)
Browse files Browse the repository at this point in the history
* Create wcs.py

Hello, I would like to support this project and I made a sample for checking (OGC) Web Coverage Service. 
I hope it can be included in the project. 

Kind regards.

* add plugins/probe/wcs.py to config_main.py, add resource (PDOK AHN WCS) & probe_vars (DOK AHN WCS - GetCaps and PDOK AHN WCS - GetCoverage v2.0.1) to tests/data/resources.json and update wcs.py

* update wcs.py
  • Loading branch information
Maretius committed Mar 24, 2022
1 parent 1469111 commit 56f65dc
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 0 deletions.
1 change: 1 addition & 0 deletions GeoHealthCheck/config_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
GHC_PLUGINS = [
# Probes
'GeoHealthCheck.plugins.probe.owsgetcaps',
'GeoHealthCheck.plugins.probe.wcs',
'GeoHealthCheck.plugins.probe.wms',
'GeoHealthCheck.plugins.probe.wmts',
'GeoHealthCheck.plugins.probe.wfs',
Expand Down
130 changes: 130 additions & 0 deletions GeoHealthCheck/plugins/probe/wcs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
from GeoHealthCheck.probe import Probe
from owslib.wcs import WebCoverageService


class WcsGetCoverage(Probe):
"""
Get WCS coverage image using the OGC WCS GetCoverage v2.0.1 Operation.
"""

NAME = 'WCS GetCoverage v2.0.1'
DESCRIPTION = """
Do WCS GetCoverage v2.0.1 request with user-specified parameters
for single Layer.
"""
RESOURCE_TYPE = 'OGC:WCS'

REQUEST_METHOD = 'GET'
REQUEST_TEMPLATE = '?SERVICE=WCS&VERSION=2.0.1' + \
'&REQUEST=GetCoverage&COVERAGEID={layers}' + \
'&FORMAT={format}' + \
'&SUBSET=x({subset[0]},{subset[2]})' + \
'&SUBSET=y({subset[1]},{subset[3]})' + \
'&SUBSETTINGCRS={subsetting_crs}' + \
'&WIDTH={width}&HEIGHT={height}'

PARAM_DEFS = {
'layers': {
'type': 'stringlist',
'description': 'The WCS Layer ID, select one',
'default': [],
'required': True,
'range': None
},
'format': {
'type': 'string',
'description': 'Image outputformat',
'default': [],
'required': True,
'range': None
},
'subset': {
'type': 'bbox',
'description': 'The WCS subset of x and y axis',
'default': ['-180', '-90', '180', '90'],
'required': True,
'range': None
},
'subsetting_crs': {
'type': 'string',
'description': 'The crs of SUBSET and also OUTPUTCRS',
'default': '',
'required': True,
'range': None
},
'width': {
'type': 'string',
'description': 'The image width',
'default': '10',
'required': True
},
'height': {
'type': 'string',
'description': 'The image height',
'default': '10',
'required': True
}
}
"""Param defs"""

CHECKS_AVAIL = {
'GeoHealthCheck.plugins.check.checks.HttpStatusNoError': {
'default': True
},
'GeoHealthCheck.plugins.check.checks.NotContainsOwsException': {
'default': True
},
'GeoHealthCheck.plugins.check.checks.HttpHasImageContentType': {
'default': True
}
}
"""
Checks for WCS GetCoverage Response available.
Optionally override Check PARAM_DEFS using set_params
e.g. with specific `value` or even `name`.
"""
def __init__(self):
Probe.__init__(self)
self.layer_count = 0

def get_metadata(self, resource, version='2.0.1'):
"""
Get metadata, specific per Resource type.
:param resource:
:param version:
:return: Metadata object
"""
return WebCoverageService(resource.url, version=version)

# Overridden: expand param-ranges from WCS metadata
def expand_params(self, resource):

# Use WCS Capabilities doc to get metadata for
# PARAM_DEFS ranges/defaults
try:
wcs = self.get_metadata_cached(resource, version='2.0.1')
layers = wcs.contents
self.layer_count = len(layers)

# Layers to select
self.PARAM_DEFS['layers']['range'] = list(layers.keys())

# Take random layer to determine generic attrs
for layer_name in layers:
layer_entry = layers[layer_name]
break

# Image Format
self.PARAM_DEFS['format']['range'] = layer_entry.supportedFormats

# SRS
bbox = layer_entry.boundingboxes
subsetting_crs = bbox[0]['nativeSrs']
self.PARAM_DEFS['subsetting_crs']['default'] = subsetting_crs

# BBOX
self.log('bbox: %s' % str(bbox[0]['bbox']))
self.PARAM_DEFS['subset']['default'] = bbox[0]['bbox']

except Exception as err:
raise err
32 changes: 32 additions & 0 deletions tests/data/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
"pdok": "pdok"
},
"resources": {
"PDOK AHN WCS": {
"owner": "admin",
"resource_type": "OGC:WCS",
"active": true,
"title": "PDOK AHN Web Coverage Service",
"url": "https://geodata.nationaalgeoregister.nl/ahn1/wcs",
"tags": [
"ows",
"pdok"
]
},
"PDOK BAG WMS": {
"owner": "admin",
"resource_type": "OGC:WMS",
Expand Down Expand Up @@ -97,6 +108,27 @@
}
},
"probe_vars": {
"PDOK AHN WCS - GetCaps": {
"resource": "PDOK AHN WCS",
"probe_class": "GeoHealthCheck.plugins.probe.owsgetcaps.WcsGetCaps",
"parameters": {
"service": "WCS",
"version": "2.0.1"
}
},
"PDOK AHN WCS - GetCoverage v2.0.1": {
"resource": "PDOK AHN WCS",
"probe_class": "GeoHealthCheck.plugins.probe.wcs.WcsGetCoverage",
"parameters": {
"layers": ["ahn1_100m"],
"format": "image/png",
"subset": ["10000", "300000", "280000", "619700"],
"subsetting_crs": "http://www.opengis.net/def/crs/EPSG/0/28992",
"height": "256",
"width": "256",
"exceptions": "application/vnd.ogc.se_xml"
}
},
"PDOK BAG WMS - GetCaps": {
"resource": "PDOK BAG WMS",
"probe_class": "GeoHealthCheck.plugins.probe.owsgetcaps.WmsGetCaps",
Expand Down

0 comments on commit 56f65dc

Please sign in to comment.