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
introgis [2018/10/22 17:07]
qcbs [3 - Open Source GIS software]
introgis [2019/11/12 17:17]
qcbs [Exercice 4 - Downloading files, recap and challenge!]
Line 6: Line 6:
 Guillaume Larocque, Research Professional. (guillaume.larocque@mcgill.ca) Guillaume Larocque, Research Professional. (guillaume.larocque@mcgill.ca)
  
-October 23 and 242018. McGill University+November 12 and 132019. McGill University
  
 ===== Presentation ===== ===== Presentation =====
Line 86: Line 86:
 **Step 2**: Add a Google Hybrid layer by clicking on plugins and by installing the QuickMapServices plugin. Then go in web>​QuickMapServices>​Settings>​More services and click on Add contributed pack. Then, add the Google Hybrid layer to the canvas from the web>​QuickMapServices menu.  **Step 2**: Add a Google Hybrid layer by clicking on plugins and by installing the QuickMapServices plugin. Then go in web>​QuickMapServices>​Settings>​More services and click on Add contributed pack. Then, add the Google Hybrid layer to the canvas from the web>​QuickMapServices menu. 
  
-**Step 2 alternative**:​ Add a Google Satellite layer by clicking on the Browser>​XYZ tiles, right-click and select New connection. For the name, specify Google Satellite. For the URL, put http://​mt0.google.com/​vt/​lyrs=y&​hl=en&​x={x}&​y={y}&​z={z}&​s=Ga ​Note that the CRS of the canvas is now (WGS84/ Pseudo Mercator). Move this layer to the bottom in the Layers list. You can find other sources of tiles here (https://​leaflet-extras.github.io/​leaflet-providers/​preview/​)+**Step 2 alternative**:​ Add a Google Satellite layer by clicking on the Browser>​XYZ tiles, right-click and select New connection. For the name, specify Google Satellite. For the URL, put  
 + 
 +<​file>​ 
 +http://​mt0.google.com/​vt/​lyrs=y&​hl=en&​x={x}&​y={y}&​z={z}&​s=Ga 
 +</​file>​ 
 +Note that the CRS of the canvas is now (WGS84/ Pseudo Mercator). Move this layer to the bottom in the Layers list. You can find other sources of tiles here (https://​leaflet-extras.github.io/​leaflet-providers/​preview/​)
  
 **Step 3**: Click on the CRS modification button on the bottom right of your screen and change the CRS to NAD83/UTM Zone 18N.  **Step 3**: Click on the CRS modification button on the bottom right of your screen and change the CRS to NAD83/UTM Zone 18N. 
Line 96: Line 101:
 **Step 6**: From the Layer>​Properties>​Symbology menu, change the colors of the Two reserves, add the names of the reserves as labels, and put appropriate labels for the extensions of the reserves that you are proposing.  ​ **Step 6**: From the Layer>​Properties>​Symbology menu, change the colors of the Two reserves, add the names of the reserves as labels, and put appropriate labels for the extensions of the reserves that you are proposing.  ​
  
-**Step 7**: Assign appropriate colors for each layer in the Style tab of the Layer Properties menu. Add the roads (Routes.shp),​ other forested areas (region_boise.shp) and water bodies (Region_hydrique.shp) to the map canvas. ​ Then, using the Print layout dialog (>​Project>​New Print Layout), generate a map that shows the reserves you have digitized, complete with a title, a North Arrow, Labels, and a legend. Note: When you open the Print Layout, you are presented with an empty page. To add the map, you need to click on the "Adds new map to the layout"​ button and click-drag the area on the map where you want the map to appear. ​+**Step 7**: Assign appropriate colors for each layer in the Style tab of the Layer Properties menu. From the zip file downloaded above, add the roads (Routes.shp),​ other forested areas (region_boise.shp) and water bodies (Region_hydrique.shp) to the map canvas. ​ Then, using the Print layout dialog (>​Project>​New Print Layout), generate a map that shows the reserves you have digitized, complete with a title, a North Arrow, Labels, and a legend. Note: When you open the Print Layout, you are presented with an empty page. To add the map, you need to click on the "Add new map to the layout"​ button and click-drag the area on the map where you want the map to appear. ​
  
 **CHALLENGE**:​ Add the pipelines and powerlines to the map, that you will download from Open Street Maps using the Quick OSM plugin. ​ **CHALLENGE**:​ Add the pipelines and powerlines to the map, that you will download from Open Street Maps using the Quick OSM plugin. ​
Line 104: Line 109:
 **Objective:​ Find out the proportion of voters living within 500 m of a forested area larger than 10 hectares in the Jacques-Cartier provincial electoral district in the Montreal West Island.** **Objective:​ Find out the proportion of voters living within 500 m of a forested area larger than 10 hectares in the Jacques-Cartier provincial electoral district in the Montreal West Island.**
  
-**Step 1**: Start a new project and open the files named '​sections_vote_31h5.shp'​ and '​regions_boise.shp'​. Convert these files to the NAD83/UTM 18N CRS by saving them as new layers in the Geopackage ​you created above (right click on the layer name in the left menu Export>​Save feature as). +**Step 1**: Start a new project and open the files named '​sections_vote_31h5.shp'​ and '​regions_boise.shp'​. Convert these files to the NAD83/UTM 18N CRS by saving them as new layers in a new Geopackage (right click on the layer name in the left menu Export>​Save feature as). 
  
 **Step 2**: Start a new project again and set the project CRS to NAD83/UTM 18N. Add the two layers you just saved. ​ **Step 2**: Start a new project again and set the project CRS to NAD83/UTM 18N. Add the two layers you just saved. ​
Line 182: Line 187:
 **CHALLENGE 2**: Regenerate your interpolated raster maps for each time periods using the Multi-level B-Spline Interpolation tool in Saga. Use the Processing toolbox for this. Compare those maps with the ones you obtained with Inverse Distance Weighting. ​ **CHALLENGE 2**: Regenerate your interpolated raster maps for each time periods using the Multi-level B-Spline Interpolation tool in Saga. Use the Processing toolbox for this. Compare those maps with the ones you obtained with Inverse Distance Weighting. ​
 ====== Exercice 4 - Downloading files, recap and challenge! ====== ====== Exercice 4 - Downloading files, recap and challenge! ======
-For this exercise, you will need to extract the mean elevation and the land cover at occurence sites of the [[http://​www.gbif.org/​|Global Biodiversity Information Facility (GBIF)]] falling within the Wemindji aboriginal territory, in the James Bay area of Quebec. **You will want to work with the UTM Zone 17N / NAD83 reference system**. Note that to reproject a raster, the preferred way is to use Raster>​Projections>​Warp.To achieve the objective, you will need to complete the following steps: ​+For this exercise, you will need to extract the mean elevation and the land cover at occurence sites of the [[http://​www.gbif.org/​|Global Biodiversity Information Facility (GBIF)]] falling within the Wemindji aboriginal territory, in the James Bay area of Quebec. **You will want to work with the UTM Zone 17N / NAD83 reference system**. Note that to reproject a raster, the preferred way is to use Raster>​Projections>​Warp. To achieve the objective, you will need to complete the following steps: ​
  
-  * On the [[http://​open.canada.ca/​|Canada Open Government]] website, download raster [[http://​ftp.geogratis.gc.ca/​pub/​nrcan_rncan/​elevation/​cdem_mnec/​|elevation files]] for zones 33D and 33E at the 1:250,000 scale.+  * On the [[https://​open.canada.ca/​en/​open-data|Canada Open Government]] website, download raster [[http://​ftp.geogratis.gc.ca/​pub/​nrcan_rncan/​elevation/​cdem_mnec/​|elevation files]] for zones 33D and 33E at the 1:250,000 scale.
   * Download this {{::​qc_land_use_33de.zip|ZIP package}} containing a tif file with a recent land cover classification of the area and the associated style/​colormap in qml format. ​   * Download this {{::​qc_land_use_33de.zip|ZIP package}} containing a tif file with a recent land cover classification of the area and the associated style/​colormap in qml format. ​
-  * On Open Government ​website, download the shapefile ​of Aboriginal Lands of Canada Legislative Boundaries (al_ta_ca_shp_gdm_en.zip). The shapefile of interest is the one that ends with _MODIFIED ​+  * On the MERN website ​(https://​mern.gouv.qc.ca/​territoire/​portrait/​portrait-donnees-mille.jsp), download the "​Découpages administratifs",​ "​Municipalités,​ TNO et territoires autochtones"​ dataset as a shapefile. ​You will want the polygon layer. ​
   * Download {{::​occurrence.txt|this file}} containing the [[http://​www.gbif.org/​|GBIF]] species occurences in the Wemindji region. Note that this file is TAB delimited and the coordinates are in Latitude, longitude (WGS84). You can open it in a text editor to explore it's content. ​   * Download {{::​occurrence.txt|this file}} containing the [[http://​www.gbif.org/​|GBIF]] species occurences in the Wemindji region. Note that this file is TAB delimited and the coordinates are in Latitude, longitude (WGS84). You can open it in a text editor to explore it's content. ​
-  * Using the latitude, longitude coordinates,​ add the GBIF occurences to the map canvas. ​+  * Using the latitude, longitude coordinates,​ add the GBIF occurences to the map canvas ​(it is TAB delimited)
   * Merge the elevation raster layers (.tif) into one using Raster>​Miscellaneous>​Merge. Save the output as a .tif file.    * Merge the elevation raster layers (.tif) into one using Raster>​Miscellaneous>​Merge. Save the output as a .tif file. 
 +  * Use a filter to isolate the Wemindji territory (MUS_MN_MUN column)from the municipalities layer. ​
   * Clip the occurrences to obtain only those within the Wemindji territory. ​   * Clip the occurrences to obtain only those within the Wemindji territory. ​
   * Use the 'point sampling tool' plugin to extract the name of each species in latin, the land cover and the elevation at each occurrence location. Note that some locations contain a large number of occurrences. ​   * Use the 'point sampling tool' plugin to extract the name of each species in latin, the land cover and the elevation at each occurrence location. Note that some locations contain a large number of occurrences. ​
Line 231: Line 237:
 **CHALLENGE 2** **CHALLENGE 2**
 Use the Cluster Analysis for Grids function in Processing Toolbox>​SAGA to perform an unsupervised classification of your images using bands 3,4,5 and 7.  Use the Cluster Analysis for Grids function in Processing Toolbox>​SAGA to perform an unsupervised classification of your images using bands 3,4,5 and 7. 
-====== Exercise 6 - Using GRASS within ​QGIS ======+ 
 +====== Exercise 6 - Using GRASS with QGIS Processing toolbox ​======
  
 Objective: Isolate the largest contiguous patch of land that is not covered by water and that is at least 1km from roads. ​ Objective: Isolate the largest contiguous patch of land that is not covered by water and that is at least 1km from roads. ​
  
-**Step 1**: Start QGIS by clicking on "QGIS with GRASS support"​. Make sure that the GRASS extension is activated, that the GRASS icons bar is selected in >​View>​Toolbar,​ and that it is not hidden somewhere in your icons barClick on the Plugins>​GRASS>​ New mapset and define ​a new GRASS Database, a new Location (name it workshop2), choose ​the CRS NAD83 / UTM 18 N, specify ​the default GRASS Region by using the current QGIS extent and specify a name for the Mapset+**Step 1**: Save the file routes.shp as a new layer with the CRS NAD83 / UTM 18N. Do the same for the Region_Hydrique shapefile
  
-**Step 2**: Save the file routes.shp as a new layer with the CRS NAD83 / UTM 18N. Do the same for the Region_Hydrique shapefile+**Step 2**: Convert ​the routes ​and the Region_Hydrique files to raster format using the v.to.rast function. Choose the "​Source for raster values" ​as "​va",​ and put 1 in the "​Raster value (use=val)"​. Do the same for the regions hydriques.
  
-**Step 3**: You now need to import ​the files into GRASSClick on 'Open GRASS tools' (if the tab is not already active), click on the '​Module tree'>'​File management'>'​Import into GRASS'>'​Import ​vector into GRASS'>'​v.in.ogr.qgis'​. Select ​the route file you created in step 2 and specify a name for the output fileRepeat this step for the Region hydrique file. Add the newly created GRASS files to the map canvas. Using the QGIS Browser, you can add GRASS files by finding your GRASS Database folder, opening the desired mapset and location, and dragging and dropping files from the Browser to the Layers Panel+**Step 3**: Use the r.grow.distance function to create ​continuous raster map in which each pixel is assigned ​the distance from the closest ​route. ​Use the routes layer in raster format (Step 6) as the input 
  
-**Step 4**: Find the function called r.in.gdal and import the 31h05dem.tif file to GRASS. Add this new GRASS layer to the QGIS map canvas.  +**Step 4**: Use the r.null.to function to replace the value of NULL with 0 in the Region Hydrique raster file. Do the same for the r.grow.distance ​file
- +
-**Step 5**: Find the function g.region.multiple.raster and use the file imported in Step 4 to define the current region (specify the exact name of the raster layer in the box).  +
- +
-**Step 6**: Convert the routes file to raster format using the v.to.rast.constant function. Do the same for the regions hydriques. +
- +
-**Step 7**: Use the r.grow.distance function to create a continuous raster map in which each pixel is assigned the distance from the closest route. Use the routes layer in raster format (Step 6) as the input. ​  +
- +
-**Step 8**: Use the r.null.to function to replace the value of NULL with 0 in the Region Hydrique raster file.  +
- +
-**Step 9**: Use the r.mapcalculator function to remove the areas covered with water form the distance ​map you just createdSet layer A as the Region Hydrique raster layer and B as the File created in Step 7. Click on the "Use region of this map" icon beside layer A. In the formula box, type+
  
 +**Step 5**: Use the r.mapcalc.simple function to remove the areas covered with water form the distance map you just created. Set layer A as the Region Hydrique raster layer from step 4 and B as the distance file created in Step 4. 
  
 <​file>​ <​file>​
-r.mapcalc expression="​distance_nowater=((region_hydrique-1)*-1)*distance_routes" ​+r.mapcalc expression="​((A-1)*-1)*B" ​
 </​file>​ </​file>​
-(change the layer names accordingly) 
  
-**Step ​10**: To exclude areas closer than 1km from roads, ​create a text file (in text edit or Notepad) ​with the following ​content+**Step ​6**: To exclude areas closer than 1km from roads, ​run r.reclass on the distance map from step 5 with the following ​reclass rule
  
 <​file>​ <​file>​
Line 266: Line 263:
 </​file>​ </​file>​
  
-**Step ​11**: Use the r.reclass function to reclassify the raster you created in Step 9 and using the reclass rules file (Step 10).  +**Step ​7**: Use the r.clump function to give every isolated contiguous area a unique identifier. ​
- +
-**Step 12**: Use the r.clump function to give every isolated contiguous area a unique identifier. ​+
  
-**Step ​13**: Use the r.stats function to obtain the area of each contiguous area, or patch. ​You need to click on Advanced Options, select ​"Print area totals"​ and put "-" ​as the Name for output ​fileYou could also specify ​file name with a .txt extension if you want the output to be save in a text file+**Step ​8**: Use the r.stats function to obtain the area of each contiguous area, or patch. ​Unclick One cell (range) per line and click "Print area totals"​ and "Print category labels"​. Choose "desc" for Sort output ​statistics by cell countThen, click on the html file in the Results viewer and identify the patch ID with the second largest area (largest is the background).
  
-**Step ​14**: Identify ​the patch with the largest area. Find the GRASS Shell in the list of functions and write the following ​command: ​+**Step ​9**: Use r.reclass on the output from Step 8, with the following ​rule
 <​file>​ <​file>​
-r.mapcalc expression="​Largest_patch=if(Step_12 ​ == ID, 1, null())" ​+ID 
 +NULLL
 </​file>​ </​file>​
-where you replace ID with the ID of the largest patch, and Step_12 with the name that you gave to the raster in Step 12. This will have created a raster map named Largest_patch in which the largest patch is isolated with a value of 1. You can now display this raster and change the Symbology to view the isolated patch.+where you replace ID with the ID of the largest patch. This will have created a raster map named Largest_patch in which the largest patch is isolated with a value of 1. You can now display this raster and change the Symbology to view the isolated patch.
  
-**Step ​15**: Convert this file to vector by using the r.to.vect.area function and add it to the canvas. ​+**Step ​10**: Convert this file to vector by using the r.to.vect function and add it to the canvas. ​
 ====== GRASS Terminology====== ====== GRASS Terminology======