-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Band math expressions for client-side rendering #8
Comments
The Python code parsing and applying the expressions in TiTiler / rio-tiler is here: https://github.com/cogeotiff/rio-tiler/blob/741acc3596d908db1755c82f18e2f4fd3711c49c/rio_tiler/expression.py#L80-L88 Basically, after a bit of parsing / splitting into blocks (defining output bands), the expressions are passed to numexpr.evaluate(bloc.strip(), local_dict=dict(zip(bands, data))) with a mapping from But that all said - I'd say the Not sure there is any standard and if it would help anyone to follow that - QGIS has raster calculator expressions, Sentinel Hub has custom scripts / Evalscript... |
👋 @ddohler - thanks for opening up this discussion! I was very focused on titiler when we discussed this at FOSS4GNA this week, but @j08lue is right - you can put whatever kind of expression syntax that you want in the However, the spec says that the @j08lue's idea for a separate renderer is a good one. I can imagine a collection with a set of renderers that could be used in different applications that would all yield consistent results. e.g. NDVI from Landsat for {
"renders": {
"ndvi-titiler": {
"title": "Normalized Difference Vegetation Index",
"assets": ["B04", "B05"],
"expression": "(B05 – B04) / (B05 + B04)",
"resampling": "average",
"colormap_name": "ylgn"
},
"ndvi-openlayers": {
"title": "Normalized Difference Vegetation Index",
"assets": ["B04", "B05"],
"expression": [
"/",
["-", ["band", 2], ["band", 1]],
["+", ["band", 2], ["band", 1]],
],
"resampling": "average",
"colormap_name": "ylgn"
}
},
} I have not used OpenLayers so I don't know what the colormap parameters would actually be, but you would do whatever you need to do to have a common visualization output from each application. |
Thanks for the follow-up 🙇 It is such a great idea to centralize the style expression. As @hrodmn detailed, the type of the |
Thanks all! It sounds like either of these two options (expand the type of the Just to clarify, @hanbyul-here what I think you are suggesting is something like this, is this correct? {
"renders": {
"ndvi": {
"title": "Normalized Difference Vegetation Index",
"assets": ["B04", "B05"],
"expression": "(B05 – B04) / (B05 + B04)",
"expression-openlayers": [
"/",
["-", ["band", 2], ["band", 1]],
["+", ["band", 2], ["band", 1]],
],
"resampling": "average",
"colormap_name": "ylgn"
},
},
} The advantages I see of this approach are that it doesn't require repeating the I think between the two I would probably prefer expanding the allowed types for But that's only a slight preference; I think either option would work. If y'all choose to keep Thanks for the good discussion, I'm cool with either path! |
PR #9 |
Hello! I enjoyed the presentation of this extension at FOSS4G NA yesterday. I wanted to follow up on the conversation about band math expressions that was started there.
My use case is that I'm styling rasters on the frontend using OpenLayers and would be interested in using this extension to store style information. The OpenLayers style expressions look like this (for NDVI):
['/', ['-', ['band', 2], ['band', 1]], ['+', ['band', 2], ['band', 1]]]
. MapBox GL and MapLibre would look similar, if not exactly identical. Looking at the definition ofexpression
for this extension, it looks like the equivalent would be"(B02–B01)/(B02+B01)"
. I'm not sure what library is being used to parse the formulas in Titiler, but an equivalent would need to be available in Javascript in order for someone to make use of these styling expressions on the frontend.So that's basically the crux of it -- in order for this to be usable on the frontend, there should be a way to convert the band-math expressions into the style expressions expected by frontend mapping libraries and I'm not sure whether there is. If you can provide guidance, that would be great--thank you!
The text was updated successfully, but these errors were encountered: