Using the the shapefie "roi.shp" provided. Extract values from the Landsat image and plot the spectral profiles of the different materials i.e Water,Urban or built-up areas, roads, and vegetation.
I have the folowing piece of code:
##Load shape files samp <- readOGR(paste0(layer="roi.shp")) ##roi.shp is a shapefile for a region of interest ##Generate point samples ptsamp <- spsample(samp, 300, type='regular') ##Add land cover class ptsamp$class <- over(ptsamp, samp)$class # extract values with points df <- extract(s, ptsamp) # To see some of the reflectance values head(df)
The following error is given on the 'ptsamp$class <- over(ptsamp, samp)$class' line
Error in validObject(.Object) : invalid class “SpatialPointsDataFrame” object: number of rows in data.frame and SpatialPoints don't match