#1. Prepare NDVI tiff file and shapefile #2. Download R and RStudio #3. Open new RProject #4. Copy NDVI tiff file and shapefile into RProject folder #5. Open new R Notebook #6. Install packages install.packages("rmarkdown") install.packages("tidyverse", dependencies = TRUE) install.packages("raster", dependencies = TRUE) install.packages("sf", dependencies = TRUE) install.packages("landscapetools", dependencies = TRUE) install.packages("landscapemetrics", dependencies = TRUE) #7. Load required packages library(raster) library(landscapemetrics) library(landscapetools) library(sf) #8. Reload our saved landscape mosaic NDVI <- raster('SG/RECLASS2.tif') #9. Apply mask to crop out unnecessary areas sgshp <- st_read("SG/SGSHAPE.shp") sgshp <- st_transform(sgshp, crs = crs(NDVI)) NDVI2 <- mask(NDVI, sgshp) #10. View mosaic. check for 3 classifications show_landscape(NDVI2, discrete = TRUE) #11. Check if NDVI2 is in the right format check_landscape(NDVI2) #12. List all available metrics list_lsm() #13. Calculate multiple metrics by name calculate_lsm(NDVI2, what = c("lsm_l_ta", #total area of landscape "lsm_c_ca", #total area of each class "lsm_c_pland"), #proportional area of each class full_name = TRUE) #include info about metrics in results #14. Optional. To save image, #At top of chunk: #png('imagename.png', height =3600, width =3600, res=300) #show_landscape(NDVI2, discrete = TRUE) #At bottom of chunk: #dev.off() #15. Optional. To save table #n <- calculate_lsm(NDVI2, #what = c("lsm_l_ta", #total area of landscape #"lsm_c_ca", #total area of each class #"lsm_c_pland"), #proportional area of each class #full_name = TRUE) #include info about metrics in results #write.table(n, file='results.csv', sep = ',')