This notebook gives a short introduction to the Open Geospatial Consortium (OGC) standard WCS (Web Coverage Service) and WCPS (Web Coverage Processing Service). It provides small examples help you to get started retrieving data from https://inspire.rasdaman.org/rasdaman/ows which hosts Rasdaman (Multidimensional Raster Database Manager) - http://rasdaman.org to process OGC standarized requests from data cubes.
Data cube's terminology (multidimensional array)
OGC Web Coverage Service (WCS, http://www.opengeospatial.org/standards/wcs) is a standarized data access protocol. There are 3 core requests (GetCapabilities, DescribeCoverage) in order to discover available data (coverages) on a server (and GetCoverage) to get them to your local system.
Petascope endpoint
Any OGC requests should go to this URL.
The WCS request can access to Rasdaman demo server via the url below - by specifying either one of the core requests or the WCS extension.
https://inspire.rasdaman.org/rasdaman/ows?service=WCS&version=2.0.1&request=...
GetCapabilities
Returns XML-encoded description of service properties and all data (coverages) available on the server.
The "Capabilities document" is returned and contains information e.g. service provider, to format encodings, supported interpolation methods, coverages on the server,...
Example: https://inspire.rasdaman.org/rasdaman/ows?service=WCS&version=2.0.1&request=GetCapabilities
Describe Coverage
Returns XML-encoded description of a specific coverage, to check axes resolutions, dimensions etc.
Returns the "Coverage description document" that contains information to spatial and temporal dimension and general information to the type of coverage.
GetCoverage
Returns a full coverage or a subset by spatial / temporal dimensions of the coverage (slicing and trimming on coverage's axes)
Returns a subset coverage from a 3D original coverage to 2D coverage by slicing on time axis and encode result in image/png.
Trimming / Slicing on 3D data cube to get a subset coverage
You can install required Python libraries for demos with pip tool https://pypi.org/project/pip/.
# Install required libraries
pip install requests
pip install owslib
pip install numpy
# Using requests library to send GET request to server
import requests
result = requests.get("https://inspire.rasdaman.org/rasdaman/ows?service=WCS&version=2.0.1&request=GetCapabilities")
# Result is XML text (you need to parse it manually to extract valuable information
# such as: coverage Id, dimensions, axis labels,...)
print result.text
# Get result of GetCapabilities request from Rasdaman demo server
from owslib.wcs import WebCoverageService
my_wcs = WebCoverageService("https://inspire.rasdaman.org/rasdaman/ows", version="2.0.1")
# Print all available coverages
print my_wcs.contents.keys()
# Select a coverage (3D irregular coverage) to describe and set it to a reference variable
cov = my_wcs.contents["AvgTemperatureColorScaled"]
# Get number of dimensions of coverage
print cov.grid.dimension
# Get coverage axis labels with order according to coverage's Coordinate Reference System (CRS)
print cov.grid.axislabels
# Get coverage's time axis's domain (as this coverage is 3D with time axis)
print cov._getTimeLimits()
# Get coverage's grid lower limits
print cov.grid.lowlimits
# Get coverage's grid upper limits
print cov.grid.highlimits
# Get offset vectors of coverage (axes' resolutions are non-zero values, respectively)
print cov.grid.offsetvectors
# Get the list of coefficients for irregular axis (time is an irregular axis of this coverage)
print cov.timepositions
import requests
from IPython.display import Image
# Get a subset coverage by slicing on time axis, trimming on Lat and Long axes, then encode result in image/png.
request = "&REQUEST=GetCoverage"
coverage_id = "&COVERAGEID=AvgTemperatureColorScaled"
subset_time = "&SUBSET=ansi(\"2002-09-01T00:00:00.000Z\")"
subset_lat = "&SUBSET=Lat(-81.7242,81.7825)"
subset_long = "&SUBSET=Lon(-122.1420,122.2185)"
encode_format = "&FORMAT=image/png"
response = requests.get("http://inspire.rasdaman.org/rasdaman/ows?&SERVICE=WCS&VERSION=2.0.1"
+ request + coverage_id + subset_time + subset_lat + subset_long + encode_format, verify=False)
# Display result directly (sea coastnear by Fiucimino)
Image(data=response.content)
OGC Web Coverage Processing Service (WCPS, http://www.opengeospatial.org/standards/wcps) is an extension of OGC WCS standard which allows extraction, analysis and processing of multi-dimensional coverages. WCPS syntax tentatively has been crafted close to the XQuery language. It establishes a protocol to send a query string to a server and obtain, as a result of the server's processing, a set of coverages.
The so-called "processing expression" is applied on each of the coverages specified in the given list (coverageList), given that the optional boolean expression returns true when evaluated on the coverage. Each coverage is referred to in the query by the correspondent identifier variableName in the processing expression. A processing expression branches down to a miscellanea of possible sub-expressions that are able to return either scalars (scalar expressions) or encoded marrays (coverage expressions) and operate on both the data and metadata of a coverage. More details at http://tutorial.rasdaman.org/rasdaman-and-ogc-ws-tutorial/#ogc-web-services-web-coverage-processing-service.
Queries can be executed by using following request (ProcessCoverages is an extension of WCS request):
https://inspire.rasdaman.org/rasdaman/ows?service=WCS&version=2.0.1&request=ProcessCoverages&query=
With query parameter is a WCPS query with valid syntax for server to process, example of subsetting a 3D coverage to 2D coverage and encode result in image/png as same as the previous demo for WCS GetCoverage request:
# NOTE: for GET requests, WCPS query cannot contain new lines character (below query is just for brevity)
for $c in (AvgTemperatureColorScaled) return encode(
$c[Lat(-81.7242:81.7825),
Lon(-122.1420:122.2185),
ansi("2002-09-01T00:00:00.000Z")],
"png")
WCPS enables for much more complex processing requests than WCS can offer. For example, time-series processing to findout the difference between 2 date-time slices ("2002-09-01T00:00:00.000Z" (reference) and "2009-05-01T00:00:00.000Z") of coverage AvgTemperatureColorScaled.
NOTE: In case of using WCPS queries with special characters like '[', ']', '{', '}', it must use POST requests.
import requests
query = '''
for $c in (AvgTemperatureColorScaled) return encode(
($c[Lat(-81.7242:81.7825), Lon(-122.1420:122.2185), ansi("2002-09-01T00:00:00.000Z")]
- $c[Lat(-81.7242:81.7825), Lon(-122.1420:122.2185), ansi("2009-05-01T00:00:00.000Z")])
* 200, "png")
'''
# Send a WCPS with special characters to server in POST request
response = requests.post('https://inspire.rasdaman.org/rasdaman/ows', data = {'query': query}, verify=False)
# Display result directly
Image(data=response.content)
Output data from rasdaman can be used for other Python libraries to process / visualize such as Numpy. Select the proper encode format which fits with your application in advanced scenarios.
%matplotlib inline
import requests
import numpy as np
import matplotlib.pyplot as pp
# Select a 1D subset coverage result encoded in JSON
query = '''for $c in (AvgLandTemp) return encode(
$c[Lat(41.7242:45.7352),
Long(12.1420),
ansi("2000-02-01T00:00:00.000Z")]
, "json")
'''
response = requests.post('https://inspire.rasdaman.org/rasdaman/ows', data = {'query': query}, verify=False)
# Convert 1D result in JSON to Numpy 1D array
array = np.array(eval(response.text))
# Display the raw values of 1D Numpy 1D array in a plot
pp.plot(array)
pp.show()