In R raster package i write an image in tiff format after certain raster processing but the spatial information is missing of new image. That's why i have to geo-reference the image again. How this can be avoided? For example, i want to get relative normalization image of landsat data. The code is
library(landsat)
library(raster)
library(lmodel2)
library(rgdal)
a<-raster("D:/Paper/test/1997-137-b3.tif")
x<-as.matrix(a)
b<-raster("D:/Paper/test/2007-137-b3.tif")
y<-as.matrix(b)
z<-relnorm(master = x, tofix = y, nperm=100, method="MA")
RMA was not requested: it will not be computed.
image(z$newimage)
m<-raster(z$newimage)
writeRaster(m, filename="D:/Paper/test/2007-b3-rd.tif", format="GTiff", options="INTERLEAVE=BAND", overwrite=TRUE)
But after processing the file i write in raster format missing spatial information.
Answer
You can try:
# Set up a new "empty" raster inheriting the geo-information from `a`
m<-raster(a)
# Set the values of the new raster
setValues(m, z$newimage)
writeRaster(m, filename="D:/Paper/test/2007-b3-rd.tif", format="GTiff", options="INTERLEAVE=BAND", overwrite=TRUE)
HTH
No comments:
Post a Comment