3

In QGIS 3.16.2, I have a binary raster layer in which I would like to decrease map resolution without losing any value = 1 pixels (white in the example).

I have tried exporting and changing the pixel size manually, but the layer will lose the value = 1 data. I have also tried progressively reducing the map resolution to keep the value = 1 data, but this also didn't work (see red areas in the attached image).

Is there another raster function that is able to do this? Maybe something from SAGA or GRASS? I have looked at r.resample and fuzzify, but these seem to not fit what I am trying to achieve

The below image shows the original high-resolution layer, with the lower resolution layer as an overlay. The red areas show the value = 1 data lost in the process.

On the graphic below, the original image is shown with decreased map resolution overlay. Red areas indicate data losses in process.

example

5
  • 1
    If this is your whole map, why decrease resolution? If this is only a minor area of your map, why bother?
    – Erik
    Commented Jan 7, 2021 at 7:33
  • 3
    Am I right in thinking that you want to assign 1 to the coarser cells if any one of finer cells within it is 1? If yes, it looks like an Aggregate operation with maximum option.
    – Kazuhito
    Commented Jan 7, 2021 at 8:11
  • Yes Kazuhito, that is exactly the process I would like to carry out. I will try the 'Aggregate' operation and let you know how it goes?
    – Snowy
    Commented Jan 7, 2021 at 22:42
  • 1
    Hi Kazuhito, the GDAL aggregate within gdalwarp did the trick, using the max option. I found that using -ts worked with defining the output pixel size. If you want to enter an answer I will mark it as correct?
    – Snowy
    Commented Jan 8, 2021 at 0:31
  • Hi Snowy. Glad to know you have successfully worked it out. I think you are in the best position to post an answer with your solution - for future visitors. Please also do not forget to mark it answered (green tick).
    – Kazuhito
    Commented Jan 8, 2021 at 2:30

3 Answers 3

1

I found the best solution for me was to use the gdalwarpfunction as suggested by Kazuhito.

gdalwarp documentation can be found here

I used the -r max aggregate option. This will assign a value of 1 to a pixel in the output layer if any of the pixels in the input layer are a value of 1.

I also used the -ts option for setting the pixel height and width to achieve my lower resolution output layer. Thanks to all who replied, much appreciated.

0

I see no way of decreasing raster's resolution (spatial or radiometric) without losing data since, in decreasing raster resolution, a bigger raster pixel (one value) is computed out of n smaller pixel (n values) by the mean of some best fitting alghoritm. If your goal, indeed, is to decrease raster's file size (without losing data) try to change data format and/or apply some loseless compression alghoritm to original data.

0

A workaround could be using the raster calculator:

  1. Create a new (binary) raster based on your_value = 1 - thus you will get a new raster with only white (when value = 1) and black pixels (in any other case).

  2. Then decrease the resolution of the original raster as you already tried. You will lose the value=1 pixels.

  3. Now again use raster calculator to add the white pixels of step 1 to the output raster of step 2. You could use the SAGA raster calculator, accessible in QGIS Menu Processing / Toolbox / SAGA raster calculator, because it has an ifelse conditional - so you could somehow build a condition like (pseudocode) if raster_2 = 1 than raster_2, else raster_1.

In SAGA raster calculator, the formula is: ifelse(gt(a,0), a,b), where you have to define a (Main input layer) as the raster from step 1 and b (Additional layers) as the raster from step 2. gt(a,0) evaluates if the first value (a) is bigger than the second (0) and in this case returns true. There seems to be no equality sign (=) to be available in the SAGA raster calculator syntax.

However, you should reflect how to deal with the different resolutions of the outputs of 1 and 2. You could use some filter to increase the size of your zones of value=1 so that they will remain visible even with a lower resolution. What filter is suitable depends on your data and use case (and could be another question here on GIS SE).

Just for demonstration purpose I show it here with SAGA Morphological filter, accessible in QGIS: Menu Processing / Toolbox / Morphological filter. See the screenshot, including the result of the process in the second picture:

enter image description here

enter image description here

1
  • I will give this a try and let you know the outcome
    – Snowy
    Commented Jan 7, 2021 at 22:43

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.