[gdal-dev] Using bitwise & with muparser VRT expressions
Hugh Graham
hugh.a.graham at gmail.com
Wed Dec 3 11:57:57 PST 2025
Hi,
I am using VRT muparser expressions for bitwise operations when creating
masks and wanted to understand why I can't get the *bitwise & *operator
working? My current solution is to use fmod which is fine (and I think
equivalent) but using "&" would be convenient and a bit easier to read...
To illustrate, the following file works:
https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-fmodmask-vrt
the expression used here is:"(fmod(Fmask, 16) >= 8) || (fmod(Fmask, 8) >=
4) ? 0 : 1"
```
gdal convert "/vsicurl/
https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-fmodmask.vrt"
"test.tif"
```
However, the following file fails:
https://gist.github.com/h-a-graham/6db16e70e064ae8173f1052537c59761#file-fmask-bitmask-vrt
the expression parsed as: "((Fmask & 8) > 0 || (Fmask & 4) >
0) ? 0 : 1" in the XML but provided as (to my xml parser):
"((Fmask & 8) > 0 || (Fmask & 4) > 0) ? 0 : 1"
```
gdal convert "/vsicurl/
https://gist.githubusercontent.com/h-a-graham/6db16e70e064ae8173f1052537c59761/raw/c48b15852bcc7c5252cae4b906c14b9a3205a33d/fmask-bitmask.vrt"
"test.tif"
0...10...20..ERROR 1: Unexpected token "& 8) > 0 || (Fmask & 4) > 0) ? 0 :
1 " found at position 8.
```
So, is using "&" possible, or should I just stick with fmod and not worry
about it?
Any help would be much appreciated.
Hugh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20251203/92dc902e/attachment-0001.htm>
More information about the gdal-dev
mailing list