This is an old revision of the document!
GRASS
Étape 10: Assurez-vous que l'extension GRASS est activée et que la barre d'icônes GRASS est sélectionnée dans >Vue>Barre d'outils. Cliquez sur l'icône Nouveau jeu de données (New mapset) et définissez une nouvelle Géodatabase GRASS, un nouveau Secteur (donnez lui le nom Atelier2), choisissez le SCR UTM 18N (NAD83), spécifiez la région GRASS par défaut en fixant l'emprise courante de QGIS et spécifiez un nom pour le Jeu de données (mapset).
Étape 11: Vous devez maintenant importer les fichiers dans GRASS. Cliquez sur 'Ouvrir les outils GRASS', cliquez sur 'Arborescence des modules' 'Gestion des fichiers>Importer dans GRASS>Importer un vecteur dans GRASS'>v.in.ogr.qgis. Sélectionnez le fichier BBS_Routes_QC.shp et spécifiez un nom pour le fichier de sortie. Ajouter le fichier GRASS nouvellement créé au canevas en cliquant sur l'icône Ajouter une couche vectorielle GRASS.
Étape 12: Cliquez sur 'Afficher la région courante GRASS' et sur 'Éditer la région courante GRASS. Vous devez définir les propriétés de la région courante GRASS pour obtenir une résolution de 2km x 2km exactement.
Étape 13: Trouvez le module r.surf.idw dans la Boite à outils GRASS, choississez un nom pour le fichier de sortie et interpolez une carte pour les données de 1980-1995 et une autre pour 1995-2005.
Étape 14: Dans les propriétés de chacune des couches, développez une palette de couleur appropriée et attribuez la même palette pour les rasters des deux périodes.
DÉFI: Générez un nuage de points (en Excel ou R) montrant la relation entre la température moyenne annuelle (à partir de la couche Quebec_mat_tenths.txt en degrés Celcius x 10) et l'abondance des parulines couronnées aux sites de Relèves des oiseaux nicheurs (BBS). Vous aurez besoin de l'extension 'point sampling tool'.
Exercice 4
Objective: Create a 3D visualization of an elevation map created with elevation values from ground control points, excluding water bodies. Learn how to import layers into R, perform basic manipulations in GRASS within QGIS and GRASS standalone.
Step 1: If you haven't done so already, save the 'region_hydrique' in the UTM 18N (NAD83) CRS. Start a New project and set the CRS of the current canvas to UTM 18N (NAD83). Add the region_hydrique file (in UTM) and the 'Elevation_points.shp' file in QGIS (this file is already in UTM).
Step 2: Make sure that the GRASS plugin is activated and that the GRASS toolbar is selected under View > Toolbar. Click on the 'New Mapset' icon and define a new GRASS database folder, create new location (give it a name such as 'Workshop2', choose the UTM 18N (NAD83) CRS, set the region to the current QGIS extent, and choose a name for the mapset (e.g. 31h05).
Step 3: You now have to import the files into GRASS. Click on the 'Open GRASS tools icon', click on 'module tree', and find File management > import into GRASS > import vector into GRASS > v.in.ogr.qgis - Import loaded vector. Select the vector layer region hydrique (in UTM) and find name for the output vector map. Repeat these steps for the Elevation_points vector file. Load the newly created GRASS files into the canvas by clicking on the 'Add GRASS vector layer' icon.
Step 4: Click on the 'Display current GRASS region' icon and then on the 'Edit Current GRASS region' icon, and select a GRASS region that just encompasses all the elevation points. Set the Cell width and height to 30 m.
Step 5: Open GRASS tools and find the v.to.rast.constant module to convert the water bodies file to raster. Keep the raster value at 1.
Step 6: Close QGIS. We could decide to continue working within QGIS, but instead, we will move to GRASS outside of QGIS.
Step 7: Open GRASS and select the Database, Location and Mapset that you have created within QGIS.
Step 8: Load the Raster map you have created in Step 5, and the elevation points you have imported in Step 3 with the 'Add raster map layer' and 'Add vector layer' icons.
Step 9: Use the Raster > Mask module (r.mask) to create a mask layer for the next step. Select the 'Create inverse mask' and put 1 in 'Category Value to use for Mask'. Click the 'Run' button to run the module.
Step 10: Use the v.surf.rst module (Raster > interpolate surfaces) to create an interpolated elevation map using the Elevation_points layer. Specify a name for the output elevation map in the output tab and specify the ELEVATION column as the 'Name of the attribute column to be used for approximation'.
Step 11: Generate a slope map from this new elevation layer using the r.slope.aspect module (Raster > Terrain Analysis). Specify an output name for the slope layer.
Step 12: View the resulting map in three dimensions in the NVIZ module (File > NVIZ).
Terminologie GRASS
- DATABASE (Géodatabase): Répertoire principal de GRASS.
- LOCATION (Secteur): Répertoire de travail. SCR unique.
- MAPSET (Jeu de données): Sous-répertoires sous le secteur.
- REGION (Région): Définie par une étendue et une résolution spécifiques.
| prefix | Description | Example |
|---|---|---|
| d.* | display (graphical output) | d.rast: views raster map, d.vect: views vector map |
| db.* | database management | db.select: selects value(s) from table |
| g.* | general file operations | g.rename: renames map |
| r.* | raster data processing | r.buffer: buffer around raster features, r.mapcalc: map algebra |
| i.* | image processing | i.smap: image classifier |
| v.* | vector data processing | v.overlay: vector map intersections |
| ps.* | postscript map creation format | ps.map: map creation in Postscript, |
| r3.* | raster voxel data processing | r3.mapcalc: volume map algebra |
La liste complète des commandes GRASS est ici.
A few key functions
| g.list rast | lists available raster maps |
| g.list -c vect | lists available vector maps with attribute column names |
| g.proj -p | Print projection information |
| r.info raster_name | information about a raster |
| v.info vector_name | information about a vector |
| g.region | set current region |
| g.region rast=raster_name -p | set region based on an existing raster |
Using R with GRASS
On first use (within R):
install.packages('spgrass6', dependencies=TRUE)
For Mac users, run instead:
install.packages('spgrass6', type='source', dependencies=TRUE)
spgrass 6 commands:
execGRASS execute GRASS commands (when launched from R) system execute GRASS commands (when launched from GRASS) readRAST6 read GRASS raster files writeRAST6 write GRASS raster files readVECT6 read GRASS vector object files writeVECT6 write GRASS vector object files gmeta6 read GRASS metadata from the current LOCATION getLocationProj return a PROJ.4 string of projection information gmeta2grd create a GridTopology object from the GRASS region vInfo return vector geometry information vColumns return vector database columns information vDataCount return count of vector database rows vect2neigh return area neighbours with shared boundary length
