This lesson builds on the content in Multispectral Data Extraction (Low throughput).
Learning Objectives
- Create a shapefile with R script (for high throughput)
- Use a shapefile layer to extract data from a raster image
Often in a research setting there are many uniform experimental units that are being measured. This example show how to create and extract data from a uniform set of experimental plots - in this case of wheat and triticale - with an R script in QGIS.
For this section to work, make sure you have the geosphere, rgdal, raster, and rgeos packages installed in R. - For ease of access, open the package_install.R file in the Drone-Data-in_Agricultural-Research-data/R-scripts folder - Run the entire script by pressing the run button at the top (Ctrl + Shift + Enter)
Note that if you have run R in QGIS before you will have to update the packages in QGIS as well as R when there are new versions of the packages.
This is used to calculate the angle the field is at the distance the plots are from each other.
Layer
» Create Layer
» New Shapefile Layer…
...
to name and save the file to a folderPoint
as the geometryOK
to create the blank shapefile
Add Point Feature
tool (Ctrl + .)
Plugins
» Manage and Install Plugins…
Processing R Provider
by scrolling or searchingInstall plugin
if the plugin is not already installed
Note that the first time the plugin is downloaded it is a good idea to restart QGIS to make sure that it is loaded fully.
Create New R Script...
in the Processing Toolbox
Save As..
to save the script into the “QGIS3\profiles\default\processing\rscripts” folder so that the script can always be used in QGIS3 (otherwise click the play button to execute)Processing Toolbox
Execute...
Origin
to the origin point shapefileRun
Check-in
The shapefile output should look something like the image below.
Export
> Save Feature As…
ESRI Shapefile
as the output formatIn some cases the shapefile will need to be adjusted to make sure that it is accurately within all the plots.
For more information about editing a shapefile see Edit the shapefile in Multispectral Data Extraction
For step-by-step instructions on the Zonal Statistics
tool see Zonal Statistics in Multispectral Data Extraction
For detailed instructions on how to export a shapefile with data to a csv file see Export as csv in Multispectral Data Extraction
This is the end of the lessons so far! Please reach out if you have questions, comments or suggestions.