` `
L’integrazione di GRASS fornisce l’accesso ai database e alle funzionalità di GRASS GIS (vedi GRASS-PROJECT in Letteratura e riferimenti web). L’integrazione consiste di due parti: sorgente e plugin. Il sorgente consente di sfogliare, gestire e visualizzare i layer raster e vettoriali GRASS. Il plugin può essere utilizzato per creare nuove posizioni e gruppi di GRASS, modificare la regione di GRASS, creare e modificare i livelli vettoriali e analizzare i dati GRASS 2D e 3D con più di 400 moduli GRASS. In questa sezione, introdurremo le funzionalità del sorgente e del plug-in e forniremo alcuni esempi di gestione e utilizzo dei dati GRASS.
ll sorgente supporta GRASS versione 6 e 7, il plugin supporta GRASS 6 e 7 (a partire da QGIS 2.12). La distribuzione QGIS può contenere sorgente/plugin per GRASS 6, GRASS 7 o per entrambe le versioni contemporaneamente (i file binari hanno nomi dei file diversi). Tuttavia, solo una versione del sorgente/plugin può essere caricata durante l’esecuzione.
As an example, we will use the QGIS Alaska dataset (see section Sample Data). It includes a small sample GRASS LOCATION with three vector layers and one raster elevation map. Create a new folder called grassdata, download the QGIS ‘Alaska’ dataset qgis_sample_data.zip from http://qgis.org/downloads/data/ and unzip the file into grassdata.
More sample GRASS LOCATIONs are available at the GRASS website at http://grass.osgeo.org/download/sample-data/.
If the provider is loaded in QGIS, the location item with GRASS icon is added in the browser tree under each folder item which contains GRASS location. Go to the folder grassdata and expand location alaska and mapset demo.
Puoi caricare raster e vettori GRASS come qualsiasi altro layer dal browser facendo doppio clic sul layer o trascinando e rilasciando sulla mappa o sulla legenda.
Suggerimento
Caricare dati GRASS
Se non vedi la location GRASS, verifica in Guida ‣ Informazioni ‣ Sorgente dati se il sorgente dei vettori GRASS è caricato.
Questa sezione da un esempio di come importare dati raster e vettoriali in un mapset di GRASS. 76
Nel browser QGIS accedi al mapset in cui desideri importare i dati.
Nel browser QGIS trova un layer che vuoi importare in GRASS, nota che puoi aprire un’altra finestra del browser (Browser Panel (2)) se i dati sorgente sono troppo lontani dal mapset nell’albero.
Trascina un layer e rilascialo sul mapset di destinazione. L’importazione potrebbe richiedere del tempo per i layer più grandi, vedrai un icona animata |importazione| di fronte al nuovo oggetto del layer fino al termine dell’importazione.
Quando i raster sono in CRS diversi, possono essere riproiettati utilizzando un Approximate (veloce) o Exact (esatta). Se viene creato un collegamento al raster sorgente (utilizzando `` r.external``), i dati di origine sono nello stesso CRS e il formato è noto a GDAL, verranno utilizzati i dati di origine CRS. Puoi impostare queste opzioni nella scheda Browser in: ref:` grass_options`.
Se un raster ha più bande, viene creata una nuova mappa GRASS per ogni raster con .<band number> suffisso e tutto viene raggruppato in . I raster esterni hanno un’icona diversa .
Copia delle mappe: le mappe GRASS possono essere copiate tra i mapset all’interno della stessa location mediante trascinamento della selezione.
Eliminazione delle mappe: fai clic con il tasto destro su una mappa GRASS e seleziona Elimina dal menu contestuale.
Rinominare le mappe: fare clic con il tasto destro su una mappa GRASS e seleziona :guilabel:`Rinomina’ dal menu contestuale.
Le opzioni GRASS possono essere impostate nella finestra di dialogo Opzioni di GRASS, che può essere aperta facendo clic con il pulsante destro del mouse sulla posizione o sull’elemento mapset nel browser e quindi scegliendo Opzioni di GRASS.
To use GRASS functionalities in QGIS, you must select and load the GRASS plugin using the Plugin Manager. To do this, go to the menu Plugins ‣ Manage and Install Plugins..., select GRASS and click [OK].
Le seguenti funzioni principali sono fornite con il menu GRASS (Plugins -> GRASS) quando si avvia il plugin GRASS:
Per accedere a strumenti GRASS devi aprire un mapset di GRASS nel plugin (gli strumenti sono disabilitati se nessun mapset è aperto). Puoi aprire un mapset dal browser: fai clic con il pulsante destro del mouse sull’elemento mapset e quindi scegli Apri mapset dal menu contestuale.
I dati GRASS sono memorizzati in una cartella indicata come GISDBASE. Questa cartella, spesso chiamata grassdata, deve essere creata prima di iniziare a lavorare con il plugin GRASS in QGIS. All’interno di questa cartella, i dati GIS GRASS sono organizzati per progetti memorizzati in sottocartelle chiamate LOCATION. Ogni LOCATION è definito dal suo sistema di coordinate, dalla proiezione e dai confini geografici. Ciascun LOCATION può avere diversi MAPSET (sottocartella di LOCATION) che vengono utilizzati per suddividere il progetto in diversi argomenti o sottoregioni o come aree di lavoro per i singoli membri del team (vedere Neteler & Mitasova 2008 in: ref: literature_and_web). Per analizzare i vettori e i raster con i moduli GRASS, devi generalmente importarli in una LOCATION GRASS. (Questo non è sempre vero - con i moduli GRASS r.external e :file:` v.external` è possibile creare collegamenti di sola lettura a insieme di dati esterni supportati da GDAL/OGR senza importarli. Questo non è un modo perchi inizia a lavorare con GRASS, quindi questa funzionalità non sarà descritta qui.)
See section Importare dati nelle LOCATION GRASS tramite trascina e rilascia. to find how data can be easily imported by dragging and dropping in the browser.
This section gives an example of how to import raster and vector data into the ‘alaska’ GRASS LOCATION provided by the QGIS ‘Alaska’ dataset in traditional way, using standard GRASS modules. Therefore, we use the landcover raster map landcover.img and the vector GML file lakes.gml from the QGIS ‘Alaska’ dataset (see Sample Data).
Avvia QGIS e assicurati che il plugin GRASS sia caricato
Scorri la cartella raster nell’insieme di dati ‘Alaska’ di QGIS e seleziona il file landcover.img.
Scorri la cartella gml nell’insieme di dati ‘Alaska’ di QGIS e selezionare il file lakes.gml come file OGR.
As an example, here is the sample GRASS LOCATION alaska, which is projected in the Albers Equal Area projection using feet as units. This sample GRASS LOCATION alaska will be used for all examples and exercises in the following GRASS-related sections. It is useful to download and install the dataset on your computer (see Sample Data).
Avvia QGIS e assicurati che il plugin GRASS sia caricato
Si noti che alcuni strumenti della barra di GRASS precedentemente disabilitati sono ora attivi.
If that seemed like a lot of steps, it’s really not all that bad and a very quick way to create a LOCATION. The LOCATION ‘alaska’ is now ready for data import (see section Importare dati nelle LOCATION GRASS). You can also use the already-existing vector and raster data in the sample GRASS LOCATION ‘alaska’, included in the QGIS ‘Alaska’ dataset Sample Data, and move on to section Il modello dati vettoriale di GRASS.
A user has write access only to a GRASS MAPSET which he or she created. This means that besides access to your own MAPSET, you can read maps in other users’ MAPSETs (and they can read yours), but you can modify or remove only the maps in your own MAPSET.
All MAPSETs include a WIND file that stores the current boundary coordinate values and the currently selected raster resolution (see Neteler & Mitasova 2008 in Letteratura e riferimenti web, and section Lo strumento Regione di GRASS).
Avvia QGIS e assicurati che il plugin GRASS sia caricato
It is important to understand the GRASS vector data model prior to digitizing. In general, GRASS uses a topological vector model. This means that areas are not represented as closed polygons, but by one or more boundaries. A boundary between two adjacent areas is digitized only once, and it is shared by both areas. Boundaries must be connected and closed without gaps. An area is identified (and labelled) by the centroid of the area.
Besides boundaries and centroids, a vector map can also contain points and lines. All these geometry elements can be mixed in one vector and will be represented in different so-called ‘layers’ inside one GRASS vector map. So in GRASS, a layer is not a vector or raster map but a level inside a vector layer. This is important to distinguish carefully. (Although it is possible to mix geometry elements, it is unusual and, even in GRASS, only used in special cases such as vector network analysis. Normally, you should prefer to store different geometry elements in different layers.)
It is possible to store several ‘layers’ in one vector dataset. For example, fields, forests and lakes can be stored in one vector. An adjacent forest and lake can share the same boundary, but they have separate attribute tables. It is also possible to attach attributes to boundaries. An example might be the case where the boundary between a lake and a forest is a road, so it can have a different attribute table.
The ‘layer’ of the feature is defined by the ‘layer’ inside GRASS. ‘Layer’ is the number which defines if there is more than one layer inside the dataset (e.g., if the geometry is forest or lake). For now, it can be only a number. In the future, GRASS will also support names as fields in the user interface.
Attributes can be stored inside the GRASS LOCATION as dBase, SQLite3 or in external database tables, for example, PostgreSQL, MySQL, Oracle, etc.
Gli attributi contenuti nelle tabelle del database sono collegati alla geometria per il tramite di un valore ’category’.
’Category’ (key, ID) è un valore intero collegato alle primitive geometriche ed è usato come collegamento ad una colonna chiave nella tabella del database.
Suggerimento
Conoscere il modello dati vettoriale di GRASS
The best way to learn the GRASS vector model and its capabilities is to download one of the many GRASS tutorials where the vector model is described more deeply. See http://grass.osgeo.org/documentation/manuals/ for more information, books and tutorials in several languages.
To create a new GRASS vector layer, select one of following items from mapset context menu in the browser:
and enter a name in the dialog. A new vector map will be created and layer will be added to canvas and editing started. Selecting type of the layer does not restrict geometry types which can be digitized in the vector map. In GRASS, it is possible to organize all sorts of geometry types (point, line and polygon) in one vector map. The type is only used to add the layer to the canvas, because QGIS requires a layer to have a specific type.
It is also possible to add layers to existing vector maps selecting one of the items described above from context menu of existing vector map.
In GRASS, it is possible to organize all sorts of geometry types (point, line and area) in one layer, because GRASS uses a topological vector model, so you don’t need to select the geometry type when creating a new GRASS vector. This is different from shapefile creation with QGIS, because shapefiles use the Simple Feature vector model (see section Creating new vector layers).
GRASS vector layers can be digitized using the standard QGIS digitizing tools. There are however some particularities, which you should know about, due to
The particularities are discussed in the following sections.
Save, discard changes, undo, redo
Avvertimento
All the changes done during editing are immediately written to vector map and related attribute tables.
Changes are written after each operation, it is however, possible to do undo/redo or discard all changes when closing editing. If undo or discard changes is used, original state is rewritten in vector map and attribute tables.
There are two main reasons for this behaviour:
Barra degli strumenti di digitalizzazione
The ‘Digitizing Toolbar’ has some specific tools when a GRASS layer is edited:
Table GRASS Digitizing: GRASS Digitizing Tools
Suggerimento
Digitalizzare poligoni in GRASS
If you want to create a polygon in GRASS, you first digitize the boundary of the polygon. Then you add a centroid (label point) into the closed boundary. The reason for this is that a topological vector model links the attribute information of a polygon always to the centroid and not to the boundary.
Category
Category, often called cat, is sort of ID. The name comes from times when GRASS vectors had only singly attribute “category”. Category is used as a link between geometry and attributes. A single geometry may have multiple categories and thus represent multiple features in different layers. Currently it is possible to assign only one category per layer using QGIS editing tools. New features have automatically assigned new unique category, except boundaries. Boundaries usually only form areas and do not represent linear features, it is however possible to define attributes for a boundary later, for example in different layer.
New categories are always created only in currently being edited layer.
It is not possible to assign more categories to geometry using QGIS editing, such data are properly represented as multiple features, and individual features, even from different layers, may be deleted.
Attributes
Attributes of currently edited layer can only be modified. If the vector map contains more layers, features of other layers will have all attributes set to ‘<not editable (layer #)>’ to warn you that such attribute is not editable. The reason is, that other layers may have and usually have different set of fields while QGIS only supports one fixed set of fields per layer.
If a geometry primitive does not have a category assigned, a new unique category is automatically assigned and new record in attribute table is created when an attribute of that geometry is changed.
Suggerimento
If you want to do bulk update of attributes in table, for example using ‘Field Calculator’ (Using the Field Calculator), and there are features without category which you don’t want to update (typically boundaries), you can filter them out by setting ‘Advanced Filter’ to cat is not null.
Editing style
The topological symbology is essential for effective editing of topological data. When editing starts, a specialized ‘GRASS Edit’ renderer is set on the layer automatically and original renderer is restored when editing is closed. The style may be customized in layer properties ‘Style’ tab. The style can also be stored in project file or in separate file as any other style. If you customize the style, do not change its name, because it is used to reset the style when editing is started again.
Suggerimento
Do not save project file when the layer is edited, the layer would be stored with ‘Edit Style’ which has no meaning if layer is not edited.
The style is based on topological information which is temporarily added to attribute table as field ‘topo_symbol’. The field is automatically removed when editing is closed.
Suggerimento
Do not remove ‘topo_symbol’ field from attribute table, that would make features invisible because the renderer is based on that column.
Snapping
To form an area, vertices of connected boundaries must have exactly the same coordinates. This can be achieved using snapping tool only if canvas and vector map have the same CRS. Otherwise, due conversion from map coordinates to canvas and back, the coordinate may become slightly different due to representation error and CRS transformations.
Suggerimento
Use layer’s CRS also for canvas when editing.
Limitations
Simultaneous editing of multiple layers within the same vector at the same time is not supported. This is mainly due to the impossibility of handling multiple undo stacks for a single data source.
On Linux and macOS only one GRASS layer can be edited at time. This is due to a bug in GRASS which does not allow to close database drivers in random order. This is being solved with GRASS developers.
Suggerimento
Permessi di modifica in GRASS
You must be the owner of the GRASS MAPSET you want to edit. It is impossible to edit data layers in a MAPSET that is not yours, even if you have write permission.
The region definition (setting a spatial working window) in GRASS is important for working with raster layers. Vector analysis is by default not limited to any defined region definitions. But all newly created rasters will have the spatial extension and resolution of the currently defined GRASS region, regardless of their original extension and resolution. The current GRASS region is stored in the $LOCATION/$MAPSET/WIND file, and it defines north, south, east and west bounds, number of columns and rows, horizontal and vertical spatial resolution.
It is possible to switch on and off the visualization of the GRASS region in the QGIS canvas using the Display current GRASS region button.
The region can be modified in ‘Region’ tab in ‘GRASS Tolls’ dock widget. Type in the new region bounds and resolution, and click [Apply]. If you click on [Select the extent by dragging on canvas] you can select a new region interactively with your mouse on the QGIS canvas dragging a rectangle.
The GRASS module g.region provides a lot more parameters to define an appropriate region extent and resolution for your raster analysis. You can use these parameters with the GRASS Toolbox, described in section The GRASS Toolbox.
The Open GRASS Tools box provides GRASS module functionalities to work with data inside a selected GRASS LOCATION and MAPSET. To use the GRASS Toolbox you need to open a LOCATION and MAPSET that you have write permission for (usually granted, if you created the MAPSET). This is necessary, because new raster or vector layers created during analysis need to be written to the currently selected LOCATION and MAPSET.
The GRASS shell inside the GRASS Toolbox provides access to almost all (more than 300) GRASS modules in a command line interface. To offer a more user-friendly working environment, about 200 of the available GRASS modules and functionalities are also provided by graphical dialogs within the GRASS plugin Toolbox.
A complete list of GRASS modules available in the graphical Toolbox in QGIS version 2.18 is available in the GRASS wiki at http://grass.osgeo.org/wiki/GRASS-QGIS_relevant_module_list.
It is also possible to customize the GRASS Toolbox content. This procedure is described in section Personalizzare gli strumenti GRASS.
As shown in figure_grass_toolbox, you can look for the appropriate GRASS module using the thematically grouped Modules Tree or the searchable Modules List tab.
By clicking on a graphical module icon, a new tab will be added to the Toolbox dialog, providing three new sub-tabs: Options, Output and Manual.
Opzioni
The Options tab provides a simplified module dialog where you can usually select a raster or vector layer visualized in the QGIS canvas and enter further module-specific parameters to run the module.
The provided module parameters are often not complete to keep the dialog simple. If you want to use further module parameters and flags, you need to start the GRASS shell and run the module in the command line.
A new feature since QGIS 1.8 is the support for a Show Advanced Options button below the simplified module dialog in the Options tab. At the moment, it is only added to the module v.in.ascii as an example of use, but it will probably be part of more or all modules in the GRASS Toolbox in future versions of QGIS. This allows you to use the complete GRASS module options without the need to switch to the GRASS shell.
Output
The Output tab provides information about the output status of the module. When you click the [Run] button, the module switches to the Output tab and you see information about the analysis process. If all works well, you will finally see a Successfully finished message.
Manuale
The Manual tab shows the HTML help page of the GRASS module. You can use it to check further module parameters and flags or to get a deeper knowledge about the purpose of the module. At the end of each module manual page, you see further links to the Main Help index, the Thematic index and the Full index. These links provide the same information as the module g.manual.
Suggerimento
Mostrare i risultati immediatamente
Se si desidera visualizzare il risultato di un’analisi immediatamente nella vista mappa, è possibile cliccare sul pulsante Visualizza Output nella porzione inferiore della scheda.
Gli esempi che seguono mostrano le potenzialità di alcuni moduli GRASS.
The first example creates a vector contour map from an elevation raster (DEM). Here, it is assumed that you have the Alaska LOCATION set up as explained in section Importare dati nelle LOCATION GRASS.
Inserire in Nome del vettoriale in output il nome ctour_100.
Dal momento che la regione è pittosto estesa, il comando richiede del tempo. Una volta terminata l’operazione è possibile modificare le proprietà del nuovo layer vettoriale come descritto in Proprietà dei vettori.
Next, zoom in to a small, mountainous area in the center of Alaska. Zooming in close, you will notice that the contours have sharp corners. GRASS offers the v.generalize tool to slightly alter vector maps while keeping their overall shape. The tool uses several different algorithms with different purposes. Some of the algorithms (i.e., Douglas Peuker and Vertex Reduction) simplify the line by removing some of the vertices. The resulting vector will load faster. This process is useful when you have a highly detailed vector, but you are creating a very small-scale map, so the detail is unnecessary.
Suggerimento
Semplifica geometrie
Note that QGIS has a Vector ‣ Geometry Tools ‣ Simplify geometries tool that works just like the GRASS v.generalize Douglas-Peuker algorithm.
However, the purpose of this example is different. The contour lines created by r.contour have sharp angles that should be smoothed. Among the v.generalize algorithms, there is Chaiken’s, which does just that (also Hermite splines). Be aware that these algorithms can add additional vertices to the vector, causing it to load even more slowly.
Controllare che ‘ctour_100’ appaia come Nome della mappa vettoriale in input.
È possibile modificare il colore del layer vettoriale in modo da renderlo ben visibile sul raster si sfondo. Si potrà notare come le curve di livello ora appaiano meno spigolose.
Suggerimento
Altri usi di r.contour
The procedure described above can be used in other equivalent situations. If you have a raster map of precipitation data, for example, then the same method will be used to create a vector map of isohyetal (constant rainfall) lines.
Several methods are used to display elevation layers and give a 3-D effect to maps. The use of contour lines, as shown above, is one popular method often chosen to produce topographic maps. Another way to display a 3-D effect is by hillshading. The hillshade effect is created from a DEM (elevation) raster by first calculating the slope and aspect of each cell, then simulating the sun’s position in the sky and giving a reflectance value to each cell. Thus, you get sun-facing slopes lighted; the slopes facing away from the sun (in shadow) are darkened.
Cliccare r.shaded.relief per aprire il modulo.
Quando il processo sarà completato, aggiungere il raster ombreggiatura alla vista mappa.
Si dovrebbe vedere gtopo30 sopra la mappa di ombreggiatura in scala di grigi. Per riuscire a visualizzare appieno gli effetti dell’ombreggiatura, deselezionare gtopo30_shade.
Usare la shell di GRASS
The GRASS plugin in QGIS is designed for users who are new to GRASS and not familiar with all the modules and options. As such, some modules in the Toolbox do not show all the options available, and some modules do not appear at all. The GRASS shell (or console) gives the user access to those additional GRASS modules that do not appear in the Toolbox tree, and also to some additional options to the modules that are in the Toolbox with the simplest default parameters. This example demonstrates the use of an additional option in the r.shaded.relief module that was shown above.
The module r.shaded.relief can take a parameter zmult, which multiplies the elevation values relative to the X-Y coordinate units so that the hillshade effect is even more pronounced.
Il prossimo esempio tratta di un modulo GRASS che può aggregare dati raster ed aggiungere colonne di statistiche per ogni poligono di una mappa vettoriale.
Inserire come Nome del vettoriale in output ‘forest_areas’ e lanciare il modulo.
Nearly all GRASS modules can be added to the GRASS Toolbox. An XML interface is provided to parse the pretty simple XML files that configure the modules’ appearance and parameters inside the Toolbox.
Un esempio di file XML che genera il modulo v.buffer (v.buffer.qgm) ha il seguente aspetto:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE qgisgrassmodule SYSTEM "http://mrcc.com/qgisgrassmodule.dtd">
<qgisgrassmodule label="Vector buffer" module="v.buffer">
<option key="input" typeoption="type" layeroption="layer" />
<option key="buffer"/>
<option key="output" />
</qgisgrassmodule>
The parser reads this definition and creates a new tab inside the Toolbox when you select the module. A more detailed description for adding new modules, changing a module’s group, etc., can be found on the QGIS wiki at http://hub.qgis.org/projects/quantum-gis/wiki/Adding_New_Tools_to_the_GRASS_Toolbox.