0

I am working on change detection and have been able to visualize the results that I have created through levelplot. Previously I used to use Writeraster for storing my plots as tif files which did not manipulated my data in terms of pixel width or height. With levelplot, I am unable to use this function,as it throws error missing trellis, character function.

How can I save a levelpot as a TIFF imagery without legends to be opened in QGIS so that I can overlay it over basemaps?

Here is how I am creating levelplot:

changeDet1 <- calc(stack(lc1,lc2), fun = change)
codes_ <- data.frame(ID = grid_$code,value = paste0('from ',grid_[,1],' to ',grid_[,2]))
logical_test <- which(grid_$change == T) # remove no change classes
codes_ <- codes_[logical_test,]
codes_
a<-subset(codes_, ID %in% c(2,10,12,13,14,15,16,17,18,20,29,38,47,56,65,74))
rat <- levels(changeDet1)[[1]]
rat[["Changes"]] <- codes_
levels(changeDet1) <- rat
levelplot(changeDet1, par.settings=PuOrTheme(), xlab="", ylab="")
0

From documentation:

writeRaster

Write Raster Data To A File

Write an entire Raster* object to a file, using one of the many supported formats.

When writing a file to disk, the file format is determined by the 'format=' argument if supplied, or else by the file extension (if the extension is known). If other cases the default format is used.

This function is used over raster objects, not plot results. So if you wanna save the closest result seeing in plot function, use the same approach to mask non-desired values:

changeDet1 <- calc(stack(lc1,lc2), fun = change)
finalRaster <- mask(changeDet1, changeDet1 %in% c(2,10,12,13,14,15,16,17,18,20,29,38,47,56,65,74), maskvalue = 0)
class(finalRaster)
## [1] "RasterLayer"
## attr(,"package")
## [1] "raster"
writeRaster(finalRaster, 'output.tif')

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.