I have a raster GeoTIFF of a digital elevation model and a polygon shapefile with spatial boundaries of the raster. Here is a snapshot of raster and polygon layer:
The shapefile has one attribute named "plot #". My ultimate goal is to extract individual pixel values in the raster that fall under the polygons and join them onto the new shapefile that has plot# field. Currently, my workflow does this: In Qgis, export raster to point file (huge file) >> perform spatial join over the plot boundaries using custom programs in R. The final output table should look like (bonus if it is a shapefile!):
Plot# height
1 60
1 30
1 40
1 .
1 .
2 20
2 30
. .
Now the above workflow has a few issues. First, to me, the raster-to-point file export seems unnecessary and a slow process. Second, the spatial join is painfully slow for 1800 polygons on a dataframe. I wonder if: 1. there is any way to bypass the raster-to-point conversion step and directly apply the spatial join on raster pixels similar to what 'zonal statistics' plugin in this does but for all individual raster points within the polygon. I find zonal statistics to be very efficient and fast but it outputs only summary stats, not individual points. 2. If there is no other alternative, is it possible to do the same steps i.e. raster-to-point >> spatial join all in R instead of going back and forth in this and R?
How should I tackle the issue?