Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
spatialspecial [2019/04/15 20:21]
qcbs [Exercice 7]
spatialspecial [2019/04/15 20:58] (current)
qcbs [Exercice 7]
Line 237: Line 237:
 \\ \\
 \\ \\
-===== Using PostgreSQL/​PostGIS and GRASS in R =====+===== Using PostgreSQL/​PostGIS, GDAL, sf and GRASS in R =====
  
 {{::​spatial_special_r_code.r|Download the R file containing the code for this part of the workshop}} {{::​spatial_special_r_code.r|Download the R file containing the code for this part of the workshop}}
 +
  
   * Package [[http://​cran.r-project.org/​web/​packages/​rpostgis/​index.html|rpostgis]]   * Package [[http://​cran.r-project.org/​web/​packages/​rpostgis/​index.html|rpostgis]]
Line 269: Line 270:
 To create a new R Processing script, click on the R logo on the top of the processing toolbox pane, and select Create New R Script. When you are done typing the script, give it an appropriate name and save it in the default folder that opens. ​ To create a new R Processing script, click on the R logo on the top of the processing toolbox pane, and select Create New R Script. When you are done typing the script, give it an appropriate name and save it in the default folder that opens. ​
 ===== Exercice 5 ===== ===== Exercice 5 =====
-Open the Processing Toolbox. Make sure that R is activated as a provider in the Toolbox options. Find "R Scripts > Create a new R script" ​in the toolbox. Copy and past this Processing/​R script that creates 100 points distributed randomly on the earth in the latitude/​longitude reference system (EPSG 4326) and that are imported as a QGIS layer. ​+Create a new R script in the toolbox ​by copying ​and pasting ​this Processing/​R script that creates 100 points distributed randomly on the earth in the latitude/​longitude reference system (EPSG 4326) and that are imported as a QGIS layer. ​
  
 Overlay the result on top of the TM_World_Borders shapefile. ​ Overlay the result on top of the TM_World_Borders shapefile. ​
Line 311: Line 312:
 ##​Layer=vector ##​Layer=vector
 ##showplots ##showplots
-data2=tapply(Layer$new_area,​Layer$IHO_Sea,​mean)+#data2=tapply(Layer$new_area,​Layer$IHO_Sea,​mean
 +library('​dplyr'​) 
 +Layer=data.frame(Layer) 
 +data2=Layer%>​%group_by(IHO_Sea)%>​%summarize(mean=mean(new_area))
 par(mar=c(10,​4,​4,​2)) par(mar=c(10,​4,​4,​2))
-barplot(data2,​ las=2)+barplot(data2$mean, names.arg=data2$IHO_Sea, las=2)
 </​file>​ </​file>​
  
Line 338: Line 342:
 Your model should look like this one:  Your model should look like this one: 
  
-{{::screenshot_from_2017-04-19_11-54-37.png?​direct&​200|}}+{{::screenshot_from_2019-04-15_16-51-00.png?​direct&​200|}}
  
 13 - You are now ready to run the model! First, save the model and name it Country_seas. Then, close the "​Graphical Modeler"​ and double-click on your model in the Toolbox under Models. Specify TM_World_Borders as the Country layer and EEZ_IHO_union_v2 for the zones. Specify the name of a country of your choice (ex. Canada). 13 - You are now ready to run the model! First, save the model and name it Country_seas. Then, close the "​Graphical Modeler"​ and double-click on your model in the Toolbox under Models. Specify TM_World_Borders as the Country layer and EEZ_IHO_union_v2 for the zones. Specify the name of a country of your choice (ex. Canada).