Home > front end >  Raster to ASCII export in R- ASCII full of NA's
Raster to ASCII export in R- ASCII full of NA's

Time:12-01

I am trying to export a raster file (.tif) as an ascii in R for subsequent analysis. The goal is to replicate enter image description here

Most of the image is light blue, that is, covered with cells that are NA

You can remove most NAs with trim

y <- trim(x)
plot(y, colNA="light blue")

enter image description here

You are not saying why you are creating an ascii file. I assume that you want to read the values with some other tool that does not know about spatial data file formats. In that case you might consider as.data.frame with na.rm=TRUE instead.

d <- as.data.frame(x, na.rm=TRUE, cells=TRUE)
head(d)
#       cell      ntl
#44592 44592 3.615484
#44593 44593 6.819953
#45010 45010 2.256919
#45011 45011 3.350195
#45012 45012 9.617457
#45013 45013 8.812189
 

And then save it to file, for example with

write.csv(d, "test.csv", row.names=FALSE)
  • Related