Importante

Translation is a community effort you can join. This page is currently translated at 51.96%.

12.1. Lesson: Configuración de GRASS

Using GRASS in QGIS requires you to think of the interface in a slightly different way. Remember that you’re not working in QGIS directly, but working in GRASS via QGIS. Hence, make sure you have installed QGIS Desktop with Grass support.

ganhar Para abrir uma sessão de QGIS com GRASS disponível no Windows você tem que clicar no ícone QGIS Desktop com GRASS.

El objetivo de esta lección: Comenzar un proyecto GRASS en QGIS.

12.1.1. básico Follow Along: Começando uma Nova Sessão GRASS

Para lançar GRASS de dentro do QGIS, você precisa ativá-lo como em qualquer outro plugin:

  1. Primeiro, abra um novo projeto QGIS.

  2. En el Adiministrador de Complementos, activa GRASS en la lista:

    ../../../_images/enable_grass.png

    The GRASS toolbar and the GRASS panel will appear:

    ../../../_images/grass_toolbar.png

    Fig. 12.30 Barra de ferramentas GRASS

    ../../../_images/grass_panel.png

    Fig. 12.31 Painel GRASS

O painel GRASS não está ativo porque, antes que você possa usar o GRASS, é necessário criar um Mapset. O GRASS sempre funciona em um ambiente de banco de dados, o que significa que você precisa importar todos os dados que deseja usar em um banco de dados GRASS.

The GRASS database has a straightforward structure, even if at a first look it seems very complicated. The most important thing you should know is that the upper level of the database is the Location. Each Location can contain different Mapset: in every Mapset you will find the PERMANENT Mapset because it is created by default by GRASS. Each Mapset contains the data (raster, vector, etc) in a particular structure, but don’t worry, GRASS will take care of this for you.

Just remember: Location contains Mapset that contains the data. For more information visit the GRASS website.

../../../_images/grass_database.png

Fig. 12.32 GRASS database structure (from GRASS docs)

12.1.2. básico Follow Along: Comienza un Nuevo Proyecto GRASS

  1. Click on the Plugins ► GRASS ► New Mapset menu:

    ../../../_images/grass_menu.png

    Você será solicitado a escolher a localização do banco de dados GRASS.

  2. Definelo como el directorio que será usado por GRASS para crear su base de datos:

    ../../../_images/grass_folder.png
  3. Haz clic en Siguiente.

GRASS needs to create a Location, which describes the maximum extent of the geographic area you’ll be working in, also known as Grass Region.

Nota

the Region is extremely important for GRASS because it describes the area in which all layers will be taken into account for GRASS. Everything that is outside will not be considered. Don’t worry, you can always change the extent of the GRASS Region after the Location has been created

  1. Chame o novo local ÁfricadoSul:

    ../../../_images/new_location.png
  2. Haz clic en Siguiente.

  3. Estaremos trabalhando com WGS 84, então procure e selecione este SRC:

    ../../../_images/wgs_84_selected.png
  4. Haz clic en Siguiente.

  5. Ahora, selecciona la región South Africa del menú desplegable y haz clic en Establecer:

    ../../../_images/set_south_africa.png
  6. Haz clic en Siguiente.

  7. Crea un directorio de mapa, que el archivo de mapa con el que estarás trabajando.

    ../../../_images/grass_mapset.png

    Uma vez terminado, você verá uma caixa de diálogo com um resumo de todas as informações inseridas.

    ../../../_images/grass_final.png
  8. Clic Terminar.

  9. Haz clic en Aceptar en el diálogo de éxito.

You will see that the GRASS Panel will become active and you can start to use all GRASS tools.

12.1.3. básico Follow Along: Cargando datos vector en GRASS

Agora você tem um mapa em branco e, antes de começar a usar todas as ferramentas GRASS, precisa carregar dados no banco de dados GRASS, especificamente no Mapset. Você não pode usar ferramentas GRASS com camadas que não são carregadas em um Mapset GRASS.

There are many different ways to load data in the GRASS database. Let’s start with the first one.

básico Follow Along: Carregar dados usando o Navegador do QGIS

In section O Painel do Navegador we saw that the easiest and quickest way to load the data in QGIS is the Browser Panel.

GRASS data are recognized from the QGIS Browser as real GRASS data and you can notice it because you will see the GRASS icon next to the GRASS Mapset. Moreover you will see the grassMapsetOpen icon next to the Mapset that is opened.

../../../_images/grass_browser.png

Nota

You will see a replication of the GRASS Location as normal folder: GRASS Mapset data are those within the logotipo de grass folder

You can easily drag and drop layers from a folder to the GRASS Mapset.

Let’s try to import the roads layer into the grass_mapset Mapset of the SouthAfrica Location.

Vá para o Navegador e simplesmente arraste a camada roads do arquivo GeoPackage training_data.gpkg para o Mapset grass_mapset.

../../../_images/grass_browser_import.png

That’s it! If you expand the Mapset you will see the imported roads layer. You can now load in QGIS the imported layer like all the other layers.

Dica

You can also load layers from the Layer Legend Panel to Mapset in the Browser Panel. This will speed up incredibly your workflow!

básico Follow Along: Load data using the GRASS Panel

We will use now the long method to load the rivers.shp layer into the same Mapset.

  1. Load data into QGIS as usual. Use the rivers.shp dataset (found in the exercise_data/shapefile/ folder)

  2. As soon as it is loaded, click on the Filter box of the GRASS Panel and find the vector import tool by entering the term v.in.ogr.qgis:

    Aviso

    There are 2 similar tools: v.in.ogr.qgis and v.in.ogr.qgis.loc. We are looking for the first one.

    ../../../_images/grass_panel_import.png

    O v significa vetor, in significa uma função para importar dados para o banco de dados GRASS, ogr é a biblioteca de software usada para ler dados vetoriais e qgis significa que a ferramenta procurará um vetor dentre os vetores já carregados no QGIS.

  3. Depois de encontrar essa ferramenta, clique nela para abrir a própria ferramenta. Escolha a camada rivers na caixa Camada Carregada e digite e nomeie-o g_rivers para evitar confusão:

    ../../../_images/grass_tool_selected.png

    Nota

    difícil Nota las opciones de importación extra dentro de Advanced Options. Éstas incluyen la habilidad de añadir expresiones WHERE para una consulta SQL utilizada al importar los datos.

  4. Haz clic en Ejecutar para comenzar la importación.

  5. Cuando termine, haz clic en el botón Ver salida para ver la capa recien importada a GRASS en el mapa.

  6. Fechar primeiro a ferramenta de importação (clique no botão Fechar imediatamente à direita de Ver saída), em seguida, feche a janela : guilabel: Ferramentas GRASS.

  7. Remove the original rivers layer.

Ahora tienes solamente la capa importada de GRASS visible en tu mapa de QGIS.

12.1.4. básico Follow Along: Cargando Datos Ráster en GRASS

Você pode importar uma camada raster da mesma maneira que importamos as camadas vetoriais.

We are going to import in the GRASS Mapset the layer srtm_41_19_4326.tif.

Nota

the raster layer is already in the correct CRS, WGS 84. If you have layers in different CRS you must reproject them in the same CRS of the GRASS Mapset

  1. Load the srtm_41_19_4326.tif layer in QGIS

  2. Abre el diálogo Herramientas GRASS de nuevo.

  3. Haz clic en la pestaña Lista de módulos.

  4. Search for r.in.gdal.qgis and double click the tool to open the tool’s dialog.

  5. Set it up so that the input layer is srtm_41_19_4326.tif and the output is g_dem.

    ../../../_images/g_dem_settings.png
  6. Haz clic en Run.

  7. Cuando el proceso termine, haz clic en Ver salida.

  8. Haz clic en Cerrar para cerrar la pestaña, y entonces haz clic en Cerrar para cerrar el cuadro de diálogo completo.

    ../../../_images/g_dem_result.png
  9. You may now remove the original srtm_41_19_4326.tif layer.

12.1.5. básico Try Yourself Adicionar Camadas ao Mapa

Try to import in the GRASS Mapset the vector layers water.shp and places.shp from the exercise_data/shapefile/ folder. As we did for rivers rename the imported layer as g_water and g_places to avoid confusion

12.1.6. básico Abrir um Mapa GRASS existente

If you have an existing GRASS Mapset you can easily reopen it in another session of QGIS.

You have several method to open a GRASS Mapset, let’s explore some of them.

Let’s close the Mapset by clicking on the Close Mapset button of the GRASS Tools window.

básico Follow Along: Usando o complemento GRASS

  1. Clique no menu Complements –> GRASS –> Abrir Mapset ao lado do menu Complementos –> GRASS –> Novo Mapset que vimos na seção anterior.

  2. Browse to the GRASS database folder: be careful! You must choose the parent folder, not the GRASS Mapset one. Indeed GRASS will read all the Locations of the database and all the Mapsets of each Location:

    ../../../_images/grass_open_mapset1.png
  3. Choose the Location SouthAfrica and the Mapset grass_mapset that we have created before.

That’s it! The GRASS Panel will become active meaning that the Mapset has been correctly opened.

básico Follow Along: Usando o Navegador do QGIS

Even faster and easier is opening a Mapset using the QGIS Browser:

  1. Close the Mapset (if it is open) by clicking on the Close Mapset button of the GRASS Tools window.

  2. In the QGIS Browser, browse to the folder of the GRASS database.

  3. Right click on the Mapset (remember, the Mapset has the logotipo de grass GRASS icon next to it). You will see some options.

  4. Clique em Abrir mapset:

    ../../../_images/grass_open_mapset_browser.png

The Mapset is now open and ready to use!

Dica

Right click on a GRASS Mapset offers you a lot of different settings. Try to explore them and see all the useful options.

12.1.7. In Conclusion

La cadena de trabajo en GRASS para procesar datos es diferente del método que QGIS utiliza porque GRASS carga sus datos en una estructura de base de datos espacial. Sin embargo, utilizando QGIS como interfaz, puedes hacer los ajustes de un directorio de mapas de GRASS más fácilmente utilizando capas existentes en QGIS como fuente de datos para GRASS.

12.1.8. What’s Next?

Ahora que los datos están importado a GRASS, podemos ver las operaciones de análisis avanzado que GRASS ofrece.