중요

번역은 여러분이 참여할 수 있는 커뮤니티 활동입니다. 이 페이지는 현재 27.00% 에서 번역되고 있습니다.

12.1. Lesson: GRASS Setup

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.

win To open a QGIS session with GRASS available on Windows you have to click on the QGIS Desktop with GRASS icon.

이 강의의 목표: QGIS에서 GRASS 프로젝트를 시작하기.

12.1.1. ★☆☆ Follow Along: Start a New GRASS Session

To launch GRASS from within QGIS, you need to activate it as with any other plugin:

  1. First, open a new QGIS project.

  2. Plugin Manager 의 목록에서, GRASS 를 활성화하십시오.

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

    The GRASS toolbar and the GRASS panel will appear:

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

    그림 12.30 GRASS toolbar

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

    그림 12.31 GRASS Panel

The GRASS panel is not active because, before you can use GRASS, you need to create a Mapset. GRASS always works in a database environment, which means that you need to import all the data you want to use into a GRASS database.

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

그림 12.32 GRASS database structure (from GRASS docs)

12.1.2. ★☆☆ Follow Along: Start a New GRASS Project

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

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

    You’ll be asked to choose the location of the GRASS database.

  2. GRASS의 데이터베이스를 설정하는 데 다음과 같이 이 디렉터리를 설정하십시오.

    ../../../_images/grass_folder.png
  3. Next 를 클릭합니다.

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.

참고

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. Call the new location SouthAfrica:

    ../../../_images/new_location.png
  2. Next 를 클릭합니다.

  3. We’ll be working with WGS 84, so search for and select this CRS:

    ../../../_images/wgs_84_selected.png
  4. Next 를 클릭합니다.

  5. 이제 드롭다운 목록에서 South Africa 를 선택한 다음 Set 을 클릭하십시오.

    ../../../_images/set_south_africa.png
  6. Next 를 클릭합니다.

  7. 여러분이 작업하게 될 맵 파일인 맵셋을 생성하십시오.

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

    Once you’re done, you’ll see a dialog asking with a summary of all the information entered.

    ../../../_images/grass_final.png
  8. Finish 를 클릭합니다.

  9. 이어지는 대화 창의 OK 를 클릭합니다.

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

12.1.3. ★☆☆ Follow Along: Loading Vector Data into GRASS

You have now a blank map and before you can start to use all the GRASS tools you have to load data into the GRASS database, specifically into the Mapset. You cannot use GRASS tools with layer that are not loaded into a GRASS Mapset.

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

★☆☆ Follow Along: Load data using the QGIS Browser

In section ★☆☆ The Browser Panel 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

참고

You will see a replication of the GRASS Location as normal folder: GRASS Mapset data are those within the grassLogo 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.

Go to the Browser, and simply drag the roads layer from the training_data.gpkg GeoPackage file into the grass_mapset 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.

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

★☆☆ 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:

    경고

    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

    The v stands for vector, in means a function to import data into the GRASS database, ogr is the software library used to read vector data, and qgis means that the tool will look for a vector from among the vectors already loaded into QGIS.

  3. Once you’ve found this tool, click on it to bring up the tool itself. Choose the rivers layer in the Loaded Layer box and type and name it g_rivers to prevent confusion:

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

    참고

    ★★★ Note the extra import options provided under Advanced Options. These include the ability to add a WHERE clause for the SQL query used for importing the data.

  4. Run 을 클릭해서 가져오기를 시작합니다.

  5. 가져오기가 끝나면 View output 버튼을 클릭해서 맵에 새로 가져온 GRASS 레이어를 살펴보십시오.

  6. 첫 번째 가져오기 도구를 ( View output 바로 옆에 있는 Close 버튼을 클릭해서) 닫은 다음, GRASS Tools 창을 닫으십시오.

  7. Remove the original rivers layer.

이제 사용자의 QGIS 맵에 가져온 GRASS 레이어만 보이게 됩니다.

12.1.4. ★☆☆ Follow Along: Loading Raster Data into GRASS

You can import a raster layer in the same ways we imported vector layers.

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

참고

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. GRASS Tools 대화 창을 다시 여십시오.

  3. Modules List 탭을 선택합니다.

  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. Run 을 클릭합니다.

  7. 처리가 끝나면 View output 을 클릭하십시오.

  8. 현재 탭의 Close 를 클릭한 다음, 전체 대화 창의 Close 를 클릭하십시오.

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

12.1.5. ★☆☆ Try Yourself: Add Layers to Mapset

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. ★☆☆ Open an existing GRASS Mapset

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.

★☆☆ Follow Along: Using the GRASS plugin

  1. Click on the Plugins –> GRASS –> Open Mapset menu next to the Plugins –> GRASS –> New Mapset menu that we saw in the previous section.

  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.

★☆☆ Follow Along: Using the QGIS Browser

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 grassLogo GRASS icon next to it). You will see some options.

  4. Click on Open mapset:

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

The Mapset is now open and ready to use!

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

GRASS는 데이터를 공간 데이터베이스 구조로 불러온다는 점에서 GRASS의 데이터 획득 작업 흐름은 QGIS의 방법과 약간 다릅니다. 하지만 QGIS를 프론트엔드로 사용하면, QGIS의 기존 레이어를 GRASS를 위한 데이터소스로 이용할 수 있기 때문에 GRASS 맵셋을 더 쉽게 설정할 수 있게 됩니다.

12.1.8. What’s Next?

이제 GRASS에 데이터를 가져왔으니, GRASS가 제공하는 고급 분석 작업을 해볼 차례입니다.