As a next step to my previous question "How to calculate where raster a is not equal to raster b?", I now want to sieve (using QGIS -> Raster -> Analysis -> Sieve, or gdal_sieve
in the shell) a raster which consists of the values 1
and NaN
.
The problem is: no matter what parameters I tell gdal_sieve
to use, it still returns the original raster, nothing happens.
Above you can see the raster (black pixels) that I want to sieve. Actually, this screenshot was taken immediately after the sieve algorithm ran through. You will find that nothing was sieved.
I guess this is because gdal_sieve cannot handle NaN
, so the nearest possible value always is 1
again, if it skips the NaN
s.
Because I want to use Zonal Statistics with this raster and some polygons afterwards, it is necessary that this raster consists just of 1
and NaN
, because I am interested in the total count of pixels with value 1
in a polygon. If I would use a raster with, say 0
and 1
, it would always accumulate these two in my count column.
Does anyone have an idea how to workaround this?
gdal_sieve -st 100 -8 -nomask not_sieved.sdat -of "GTIFF" sieved.tif
. Everything >100 connected pixel will be excluded with a treshold of 8.gdal_sieve
command is shown below there, I didn't think that typing it in a bash script would function differently. The-nomask
flag seems to make the difference, trying the same parameters via the GUI still does not work.