I have a GeoTIFF with cell values from 0.02 up to 0.75 and many nodata values (which are 0). When using GDAL Sieve with Threshold 1 or 100 (no difference in result) and pixel connection 4, my output layer is allover 0.

Anybody knows, what could be the problem?

Image size 2.7x2.7km and cell size 2x2m

  • Impossible to say without test data. If there is very much nodata then the largest neighbor polygon could always be a nodata polygon but somehow that feels unlikely. – user30184 Feb 9 '17 at 10:55
  • Yes I thought this too at first sight. But reducing threshold to 1, it shouldn't affect the big raster polygons as visible in the image. Or do I missunderstand this tool? – Kevin Feb 9 '17 at 12:37

I confirmed this issue with my dataset. I had a raster layer (cell values: 6.05~60.9) with which Sieve has worked nicely. Then I divided its cell values by 60 to reduce them down to approx. 0.10~1.01.

This new raster produced 0, 1 binary raster when I applied GDAL_sieve.

I do not know why, but this question Gdal_sieve not working? by AMK also suggests somewhat similar situation. (AMK's data was from -0.140351 to 0.780933).

So my suggestion is (1) Try to boost up cell values (let's say 100 *z) by Raster Calculator, (2) Sieve, and (3) turn back the cell values (z / 100).

Sorry this will not be a clear answer, just a workaround at best...Hope this works for your case.

  • thanks! I will try this but still hope to find another solution as I will need it to batch process multiple areas and therefore want to have my model as clean as possible. – Kevin Feb 9 '17 at 12:38
  • @Kevin Thanks for your reply. I myself want to see more clear answer and solution, as I feel uneasy not knowing its root cause. Good luck! – Kazuhito Feb 9 '17 at 12:42
  • thanks, I really came to an end. user30184 probably found the fact why it isn't working and I will try his way late ron. – Kevin Feb 9 '17 at 13:24

I think you are misunderstanding what gdal_sieve does. It merges connected regions smaller than a size threshold with their largest neighbors. For that to work, the values must be equal with a connected region.

With floats, equality is not well defined. If it is cast to integers under the hood, then everything in your image (values 0.2 to 0.75) will be cast to zero, and mixed in with your 0 NoData values. Even if you had values of 1, you say there are a lot of NoData areas, which means a portion of the 1 polygons will be merged with the zeros, unless you specify it as an excluded value.

As you say, when you have values greater than 1 in your dataset, it is able to proceed because you have ~60 (cast) integer values on which it can look for connected polygons.

The tool is usually used to clean up noisy categorical data (such as an 8-bit classification output, or a binary mask), not on float values. An alternative for you would be to set a threshold and produce a binary mask, then apply the sieve filter on the mask to get rid of small areas.

  • thank you so much for this very explanatory answer. As for me the float values aren't that important (I have a symbology of 5 classes), I will save the data as integer and define no data values as 0. then I should get better results. – Kevin Feb 12 '17 at 7:49

Documentation of gdal_sieve points to GDALSieveFilter documentation. From there continue to GDALRasterPolygonEnumerator

The process line of this method is

ProcessLine (GInt32 *panLastLineVal, GInt32 *panThisLineVal, GInt32 *panLastLineId, GInt32 *panThisLineId, int nXSize)

GInt32 makes me think that method is dealing with integers. Data range in your source file is from 0.02 up to 0.75. As integers your source data contains only values 0 and 1. I concur that multiplying the cell values feels like right thing to do. I believe you do not need to process the files physically but you can write a GDAL VRT file http://www.gdal.org/gdal_vrttut.html and make that to do the scaling for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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