[R-sig-Geo] Fill NoData cells in a raster
Marine Regis
marine.regis at hotmail.fr
Fri Mar 18 19:10:04 CET 2016
Hello,
Thank you very much for your answers. To fill the noData cells, I have calculated the frequency of values of land cover types around a given noData cell and I have assigned the value of land cover type with maximum frequency to the noData cell. When there was more than one value of maximum frequency, I have used the function "sample". Here is my code with a reproducible example:
r2 <- raster(ncol=10, nrow=10) ## To check r2 <- raster(ncol=3, nrow=3)
values(r2) <- sample(1:8,ncell(r2),replace=T)
r2[c(5)] <- NA
plot(r2)
f2 <- focal(r2, w=matrix(1,nrow=3,ncol=3), fun=fillNoData, NAonly=T, pad=T)
plot(f2)
fillNoData <- function(x) {
feq_class <- as.data.frame(table(x))
colnames(feq_class) <- c("Class","Freq")
value_noData <- as.numeric(as.character(feq_class$Class[feq_class$Freq==max(feq_class$Freq)]))
value_noData <- sample(value_noData,1,replace=F)
return(value_noData)
}
Is the use of maximum frequency appropriate for filling the noData cells? In this case, when there is more than one value of maximum frequency, is it more correct to increase the moving window or to create a buffer around a given noData cell than to use the 8 neighbour cells?
Thank you very much for your time.
Marine
________________________________
De : Jefferson Ferreira-Ferreira <jecogeo at gmail.com>
Envoyé : vendredi 18 mars 2016 15:51
À : Zack Holden
Cc : Marine Regis; r-sig-geo at r-project.org
Objet : Re: [R-sig-Geo] Fill NoData cells in a raster
A bunch of options is given here too: http://rstudio-pubs-static.s3.amazonaws.com/1057_1f7e9ac569644689b7e4de78c1fece90.html
Map Algebra in R - Amazon Web Services<http://rstudio-pubs-static.s3.amazonaws.com/1057_1f7e9ac569644689b7e4de78c1fece90.html>
rstudio-pubs-static.s3.amazonaws.com
Map Algebra in R. Map Algebra is a framework used to manipulate field data that are stored as grid values. Though the gridded data can be stored in a vector form, map ...
2016-03-18 10:45 GMT-04:00 Zack Holden <zaholdenfs at gmail.com<mailto:zaholdenfs at gmail.com>>:
Marine,
The focal() function in the raster library should work. You should be able
to apply a custom function to only NA cells by setting NAonly=T.
require(raster)
?focal
Zack
On Thu, Mar 17, 2016 at 5:27 PM, Marine Regis <marine.regis at hotmail.fr<mailto:marine.regis at hotmail.fr>>
wrote:
> Hello,
>
> I am beginner in spatial statistics and I would need some advice. I have a
> raster that is based on a grid of 30 m resolution and in which each cell is
> assigned to one of ten land cover types (coded as 1, 2, 3, 4, ..., 10 in
> the raster). However, there are some NoData cells in the raster. Is there
> an efficient way to fill NoData cells with reasonable values of land cover
> types? Should I use an interpolation method?
>
> Thank you very much for your time.
>
> Marine
>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org<mailto:R-sig-Geo at r-project.org>
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
[[alternative HTML version deleted]]
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org<mailto:R-sig-Geo at r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Jefferson Ferreira-Ferreira
Geógrafo - GEOPROCESSAMENTO IDSM | Coordenadoria de TI
[https://imageshack.com/a/img924/3023/UGEtug.png]
Jefferson.ferreira at mamiraua.org.br<mailto:Jefferson.ferreira at mamiraua.org.br>
Instituto de Desenvolvimento Sustentável Mamirauá
Ministério da Ciência, Tecnologia e Inovação
Telefone: +55 97 3343-9710
[https://imageshack.com/a/img922/761/fPeXJi.png]Google Maps - Mapas deste e-mail:
[https://imageshack.com/a/img921/7894/xDTJEU.png]Exibir mapa ampliado<https://maps.google.com.br/maps?q=-3.355557,-64.731151&ll=-3.355471,-64.731145&spn=0.004632,0.006968&num=1&t=h&z=18>
Contatos particulares:
(55) 9615-0100
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list