I have some code that returns a raster nested in a large list, I want to extract the raster from the list and save it as a tiff so that I can export it and use it in ArcGIS.




>layer       crs units   class n_classes OK

>1     1 projected     m integer         2  v

# get spatialized lsm
area_patch <- landscapemetrics::spatialize_lsm(my_raster, what = "lsm_p_area")


#This returns 

> area_patch



class      : RasterLayer 

dimensions : 598, 790, 472420  (nrow, ncol, ncell)

resolution : 33.54191, 33.54191  (x, y)

extent     : 5313077, 5339575, -2247065, -2227007  (xmin, xmax, ymin, ymax)

crs        : +proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs 

source     : memory

names      : value 

values     : 0.112506, 21099.15  (min, max)

So I want to get the raster 'lsm_p_area' out of the list and as a stand alone tiff.

rast<-area_patch$lsm_p_area returns as empty


You've got a bit more nesting going in I think.

This is trying to get an element called lsm_p_area of a list object called area_patch:


But this printout shows that area_patch is a list, and the first element ([[1]]) is also a list with an element called lsm_p_area:

> area_patch



So what I think would work is area_raster <- area_patch[[1]]$lsm_p_area

and then you can writeRaster(area_raster,etc...)

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.