2

I have a layer in GeoServer based on a raster file (GEOTIFF) I can visualize the layer, but I want to apply dynamic filters. Before I used CQL for vector data, no problem. But not sure if the procedure is the same for raster data. First of all, I see that on the GeoServer layer preview, the option to apply a CQL Filter is not available. Bad sign I guess.

Clicking on the preview map, I can see we have 2 attributes: fid (empty) and GRAY_INDEX (from 0.0 to 10.0). GRAY_INDEX is used for layer symbolization, and no problem at all. But when I try to apply a cql_filter (with Leaflet, for example), trying all options below did not work not even one (and the error for sure is not on the JS)

cql_filter: 'GRAY_INDEX >2' cql_filter: 'GRAY_INDEX >2.0' cql_filter: 'GRAY_INDEX LIKE 2.0' cql_filter: 'GRAY_INDEX LIKE 2' cql_filter: "GRAY_INDEX >'2.0'"

There is GeoServer Raster WMS Layer update/filter like CQL, ECQL but that gives an internal error when trying to create a similar style.

1
  • can you add some detail as to what you actually want to achieve and what the SLD you tried was, and what went wrong
    – Ian Turton
    Commented Aug 25, 2021 at 10:03

2 Answers 2

5

CQL_FILTER can only work on attributes of vector data. When it comes to rasters, if the data source backing them is an image mosaic, it will be applied to the attributes in the mosaic index (e.g., time, elevation, whatever other metadata attribute collected for the single image in the mosaic).

For your use case, please have a look at the Jiffle map algebra instead: https://docs.geoserver.org/latest/en/user/styling/sld/extensions/rendering-transform.html#running-map-algebra-on-the-fly-using-jiffle

1

My solution has been creating a PHP file that dynamically creates an SLD. This php gets a list of codes to switch on/off.

In Leaflet we setup the layer:

layer.setParams({
   layers: 'store:my_layer_name',
   SLD: 'http://myserver/sld_generate.php?visible_code[]=3&visible_code[]=1',
});

If your PHP 'echoes' a correctly formatted SLD, it works :.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.