im trying to extract the mean from a satellite imagery. The point is, that when Im using this code (simplified for this example):
> semana21 <- raster("Semana21.tif")
> poly <- st_read("shapefile.shp")
Reading layer `shapefile' from data source `shapefile.shp' using driver `ESRI Shapefile'
Simple feature collection with 43 features and 2 fields
geometry type: MULTIPOLYGON
dimension: XYZ
bbox: xmin: -6.18 ymin: 38.89 xmax: -2.72 ymax: 42.90
epsg (SRID): NA
proj4string: NA
> extract(semana18, st_zm(poly), fun=sum, na.rm=TRUE, df=TRUE)
Extract seems to auto-generate ID in extract() output dataframe. So, extract() generate a new row for each polygon, but extract() row position does not correspond with the shapefile row position. So I dont have way to know which output corresponds to each element in the shapefile. So, Is there any way to keep "name" in the generated extract() dataframe? Or another way to know which result correspond to each polygon?
I want a dataframe output like: (name, extract_calculation) That way, I can then know which extract operation belong to each polygon in file
poly$max_semana <- extract(semana, poly, fun=sum, na.rm=TRUE)