Skip to content

Commit

Permalink
sf update to rsx script
Browse files Browse the repository at this point in the history
  • Loading branch information
Taylor Suzanne Nelsen committed Mar 31, 2021
1 parent b59946b commit 59855bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
4 changes: 2 additions & 2 deletions 04-high-throughput-data-extraction.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ This is used to calculate the angle the field is at the distance the plots are f
## 5. Open an R script in QGIS

1. Click the R icon and `Create New R Script...` in the `Processing Toolbox`
2. Open the *small_plot_trial_extraction_0.0.3.rsx* file in the downloaded *Drone-Data-in_Agricultural-Research-data/R_scripts*
2. Open the *small_plot_trial_extraction_0.0.4.rsx* file in the downloaded *Drone-Data-in_Agricultural-Research-data/R_scripts*
3. Click `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)

## 6. Run an R script in QGIS

1. Open the script by right clicking the *small_plot_trial_extraction_0.0.3* under the R icon in the `Processing Toolbox`
1. Open the script by right clicking the *small_plot_trial_extraction_0.0.4* under the R icon in the `Processing Toolbox`
2. Choose `Execute...`
3. Set the `Origin` to the origin point shapefile
4. Set the correct number of rows and ranges (the default for both is 10 but in this case there are 20 rows and 10 ranges)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
##small_plot_trial_extraction_0.0.3=name
##small_plot_trial_extraction_0.0.4=name
##Origin=vector
##Rows=number 10
##Ranges=number 10
##Length = number
##Width = number
##Radius = number
##Rectangular = boolean
##Output= output vector
##Length=number
##Width=number
##Radius=number
##Rectangular=boolean
##Output=output vector

library(sp)
library(geosphere)
library(raster)
library(rgeos)

origin_wgs84 <- spTransform(Origin, "+proj=longlat +datum=WGS84 +no_defs")
print("starting script")
print(class(Origin))
Origin <- as(Origin, 'Spatial')
print(class(Origin))
origin_wgs84 <- sp::spTransform(Origin, CRS("+proj=longlat +datum=WGS84 +no_defs"))
print("test1")

rows <- Rows - 1
ranges <- Ranges - 1
Expand Down Expand Up @@ -115,7 +120,7 @@ if (Rectangular == TRUE){
plots_spdf <- SpatialPolygonsDataFrame(spolys, plot_ids)
crs(plots_spdf) <- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84")

Output <- spTransform(plots_spdf, crs(Origin))
Output <- st_as_sf(spTransform(plots_spdf, crs(Origin)))
} else {
r <- ifelse(Radius > 0, Radius, plot_width*0.3)
pts2 <- spTransform(pts, CRS( "+proj=utm +zone=10 +datum=WGS84 +units=m +no_defs"))
Expand Down

0 comments on commit 59855bf

Please sign in to comment.