0

How does raster::resample handle NA values with the method ngb (or mean but I am most interested in ngb)? I had thought that NA values were ignored within a larger resolution cell-grid and the values from the grid cells with values were used so that a greater proportion of cells in the resampled raster would have values than in the original smaller-resolution raster. However, it seems that NA values have as much "weight" in the resampling as values when I ran a few tests. See example with random sample data. I can't find any information in the help file nor am I adept at understanding the code behind the function. I would like to confirm that NAs are included before proceeding.

enter image description here

EDIT: Running trials with my real dataset, I am finding that NAs are not treated in the same way as any other value. I did a trial where I ran with the raw values (including NAs) and another trial where I substituted all NA values with a dummy value prior to resample (and then substituted NA back for all dummy values). The result is a lot more grid cells with values using the NA-ridden raw data vs. the dummy variable data.

enter image description here

I have a large raster file of forest fires for which I need to convert 30m x 30m resolution to 250m x 250m resolution. I need to keep the distribution of the data intact. Part of my raster has NA values outside of the forested areas (lakes, oceans, etc), but some of the NA values are important because they are forest that has not had forest fires. I would need the resulting raster to have the same proportion of the forest without forest fires as in the original finer-resolution data.

  • 1
    I suspect that method="ngb" is doing what it says its doing, ie taking the output cell value from the nearest input cell value. When doing a resampling like this where four cells seem to be equally "near" to the input cells its either going to take one arbitrarily, always take the Nth one, or take the one that is numerically closest because of arithmetic precision. It doesn't care if the cell value is NA or -9999 or "monkey brains" - it copies the nearest cell to the output. – Spacedman Feb 1 at 12:18

Your Answer

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

Browse other questions tagged or ask your own question.