Practical 4 Rstudio Indices ST
Practical 4 Rstudio Indices ST
Open RStudio and create a new script. Begin by loading the necessary libraries.
install.packages("raster")
Ensure your working directory is set to the folder containing your Landsat data. Then,
load the Landsat bands into separate raster objects.
setwd("E:/download")
f1<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B1.tif"
B1 <- raster(f1)
# Plot Band 1
plot(B1)
f2<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B2.tif"
B2 <- raster(f2)
plot(B2)
f3<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B3.tif"
B3 <- raster(f3)
plot(B3)
f4<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B4.tif"
B4 <- raster(f4)
plot(B4)
f5<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B5.tif"
B5 <- raster(f5)
plot(B5)
f6<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B6.tif"
B6 <- raster(f6)
plot(B6)
f7<-"E:/download/reprojected/reproj_RT_LC09_L1TP_168065_20231002_20231002_02_T1_B7.tif"
B7 <- raster(f7)
plot(B7)
layout(t(1:2))
# Plot Bands 1 and 2
windows()
layout(t(1:2))
Combine all bands into a single brick object and examine its properties.
?brick
?stack
names(landsat_brick)
res(landsat_brick)
nlayers(landsat_brick)
xres(landsat_brick)
res(landsat_brick)
yres(landsat_brick)
?plotRGB
plotRGB(landsat_brick)
getwd()
?writeRaster
stacked
plot(stacked[[2]])
s_stacked
c_stacked
c1_stacked
Calculate the Normalized Difference Vegetation Index (NDVI) from the Landsat data,
plot it, and save it as a raster file.
# Calculate NDVI
ndvi
# Plot NDVI
plot(ndvi)
Perform a classification based on the NDVI values to identify different land use and
land cover types.
# Plot NDVI
plot(ndvi)
# Plot RGB image
plot(forest)
Plot the final land use and land cover classification with a legend.
legend("topright",
text.font = 2,
bty = "o",
pt.cex = 2,
cex = 1.2,
text.col = "black",
horiz = FALSE,