2

Hi I made classification map which you can see below. Because the original map had text in it and some borders etc that I didn't want to be included in the new map, these got their own class and afterwards I changed all pixels with this class to NULL (missing). It doesn't look that good though, because the map has many holes as you can see, and I want to fill these holes by the other classes. The best option would be to fill it with the most common neighbouring class or something, but I can't find this option anywhere. The methods should replace the missing pixels by an existing class and not calculate new values for the pixels.

enter image description here

I tried the method Close gaps with stepwise resampling with the nearest neighbour option, but this gave a very weird result as you can see below as well. Basically it created new random clumps of cells in areas that had no missing data before (like around the orange class). Additionally, it filled the long and thin missing value areas with many seperate pixels of different classes etc. Anybody know why this is happening and anybody know a solution?

I don't want to use the Fill gap tool because it can't replace with a class...it will calculate new values for missing pixels.

enter image description here

4
  • Interesting problem. Would it also be OK for you to interpolate the raster and then do a new classification? The results could be the same, but I think it can not be done in one step. Commented Jun 10, 2021 at 8:50
  • I want to try interpolation. I wanted to use a mask in the function (close gaps with spline) but it doesn't accept a vector as a mask. Does it not mean the outline of the area with a mask here?
    – Brandon
    Commented Jun 10, 2021 at 9:15
  • Couldn't say, for I don't know the function. I would post that problem as a separate question. Commented Jun 10, 2021 at 9:47
  • Try gdal.org/programs/gdal_sieve.html.
    – user30184
    Commented Jun 10, 2021 at 12:13

1 Answer 1

1

I would try r.fill.stats with a reasonably large value for the Distance threshold, depending on the size of your gaps. So let's say your maximum gap is 20 pixels wide, your Distance Threshold should be at least 10, better make that 11 to be on the safe side.

r.fill.stats Does not overwrite your original cell values, if you set this option, so your original map should not be affected. Gaps between two areas showing the same class (most of your cases) should be interpolated as the same class.

Now for values between two different classes: These should get be interpolated with new values. This is of course not what you wanted, but this should be only in small areas, if you set the Power Coefficient high enough this should not effect to many cells. These cells should be possible to get back into your original classification by running a second classification.

I did not try this out in detail, but it should technical work.

3
  • Hey! Thanks a lot for your answer. This actually gave quite a nice result!
    – Brandon
    Commented Jun 10, 2021 at 11:19
  • By the way I used median instead of mean and it made it so that none were interpolated.
    – Brandon
    Commented Jun 10, 2021 at 11:37
  • Glad that it worked. Thanks for the hint with the median. I forgot about that, but that is of course more sensible. Commented Jun 10, 2021 at 18:26

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.