Backward Mapping
============================
When performing queries, using CQL filters, against layers that support a templated output, it will be possible to reference the template attributes in the CQL expressions. The plugin will take care of interpreting the CQL filter and translate it, when possible, to a data source native filter. For example, if that data source is a relational database, the CQL filter will be translated to one or multiple SQL queries that will be used to retrieve only the needed data.
Consider the following GML output example:
.. code-block:: xml
Station_BOL
Bologna
11.34 44.5
2016-12-19T11:28:31.000Z
35.0
2016-12-19T11:28:55.000Z
25.0
2016-12-19T11:30:26.000Z
1019.0
2016-12-19T11:30:51.000Z
1015.0
2016-12-19T11:29:24.000Z
80.0
Station_ALS
Alessandria
8.63 44.92
2016-12-19T11:26:40.000Z
20.0
2016-12-19T11:27:13.000Z
155.0
Station_ROV
Rovereto
11.05 45.89
The following are valid CQL_FILTERS
* :code:`st:name = 'Station_BOL'`.
* :code:`st:temperature.st:Temperature.st:value < 25`.
Given this underlying GML template:
.. code-block:: xml
$${strConcat('Station_',st:code)}
${st:common_name}
${st:position}
${st:time}
${st:value}
${st:time}
${st:value}
${st:time}
${st:value}
The above cql_filter will be internally translated to:
* :code:`strConcat('Station_',st:code) = 'Station_BOL'`.
* :code:`st:meteoObservations/st:MeteoObservationsFeature/st:MeteoParametersFeature/st:value < 25 AND st:meteoObservations/st:MeteoObservationsFeature/st:MeteoParametersFeature/st:param_name = 'temperature'`.
As it is possible to see from the second example, if a template filter is defined for the value we want to filter by, the filter will be automatically included in the query.
Backwards mapping capability is available for all the output formats. Consider the following JSON-LD output example:
The following are example of valid CQL filters:
* gsml:GeologicUnit.description = 'some string value'
* name in ("MERCIA MUDSTONE", "UKNOWN")
* gsml:positionalAccuracy.valueArray1 = "100"
.. code-block:: json
{
"@context": {
"gsp": "http://www.opengis.net/ont/geosparql#",
"sf": "http://www.opengis.net/ont/sf#",
"schema": "https://schema.org/",
"dc": "http://purl.org/dc/terms/",
"Feature": "gsp:Feature",
"FeatureCollection": "schema:Collection",
"Point": "sf:Point",
"wkt": "gsp:asWKT",
"features": {
"@container": "@set",
"@id": "schema:hasPart"
},
"geometry": "sf:geometry",
"description": "dc:description",
"title": "dc:title",
"name": "schema:name"
},
"type": "FeatureCollection",
"features": [
{
"@id": "mf2",
"@type": [
"Feature",
"gsml:MappedFeature",
"http://vocabulary.odm2.org/samplingfeaturetype/mappedFeature"
],
"name": "MERCIA MUDSTONE GROUP",
"gsml:positionalAccuracy":{
"value":"100",
"valueArray": ["100","someStaticVal"]
},
"gsml:GeologicUnit": {
"@id": "gu.25678",
"description": "Olivine basalt, tuff, microgabbro, minor sedimentary rocks",
"gsml:geologicUnitType": "urn:ogc:def:nil:OGC::unknown",
"gsml:composition": [
{
"gsml:compositionPart": [
{
"gsml:role": {
"value": "interbedded component",
"@codeSpace": "urn:cgi:classi..."
},
"proportion": {
"@dataType": "CGI_ValueProperty",
"CGI_TermValue": {
"@dataType": "CGI_TermValue",
"value": {
"value": "significant",
"@codeSpace": "some:uri"
}
}
},
"lithology": [
{
"@id": "cc.3",
"name": {
"value": "name_cc_3",
"@lang": "en"
},
"vocabulary": {
"@href": "urn:ogc:def:nil:OGC::missing"
}
}
]
}
]
},
{
"gsml:compositionPart": [
{
"gsml:role": {
"value": "interbedded component",
"@codeSpace": "urn:cgi:class..."
},
"proportion": {
"@dataType": "CGI_ValueProperty",
"CGI_TermValue": {
"@dataType": "CGI_TermValue",
"value": {
"value": "minor",
"@codeSpace": "some:uri"
}
}
},
"lithology": [
{
"@id": "cc.4",
"name": {
"value": "name_cc_4",
"@lang": "en"
},
"vocabulary": {
"@href": "urn:ogc:def:nil:OGC::missing"
}
}
]
}
]
}
],
"geometry": {
"@type": "Polygon",
"wkt": "POLYGON ((52.5 -1.3, 52.6 -1.3, 52.6 -1.2,...))"
}
}
}
]
}
The following are example of valid CQL filters:
* gsml:GeologicUnit.description = 'some string value'
* name in ("MERCIA MUDSTONE", "UKNOWN")
* gsml:positionalAccuracy.valueArray1 = "100"
As the last example shows, to refer to elements in arrays listing simple attributes, the index of the attribute is needed, starting from 1, in the form ``{attributeName}{index}``, as in ``features.gsml:positionalAccuracy.valueArray1.``