6.2. Lesson: 벡터 분석

Vector data can also be analyzed to reveal how different features interact with each other in space. There are many different analysis-related functions, so we won’t go through them all. Rather, we will pose a question and try to solve it using the tools that QGIS provides.

이 강의의 목표: 문제를 제시하고, 분석 도구를 써서 해결하기

6.2.1. basic GIS 처리 과정

Before we start, it would be useful to give a brief overview of a process that can be used to solve a problem. The way to go about it is:

  1. 문제를 정의

  2. 데이터 획득

  3. 문제를 분석

  4. 결과를 표출

6.2.2. basic The Problem

해결해야 할 문제를 결정하는 것으로 처리 과정을 시작합시다. 예를 들어 여러분이 부동산 업자인데 다음 기준을 가진 고객을 위해 Swellendam 에 있는 거주지를 찾고 있다고 해봅시다.

  1. It needs to be in Swellendam

  2. It must be within reasonable driving distance of a school (say 1km)

  3. It must be more than 100m squared in size

  4. Closer than 50m to a main road

  5. Closer than 500m to a restaurant

6.2.3. basic The Data

To answer these questions, we are going to need the following data:

  1. The residential properties (buildings) in the area

  2. The roads in and around the town

  3. The location of schools and restaurants

  4. The size of buildings

These data are available through OSM, and you should find that the dataset you have been using throughout this manual also can be used for this lesson.

If you want to download data from another area, jump to the Introduction Chapter to read how to do it.

참고

OSM 다운로드는 일관된 데이터 항목을 가지고 있지만, 커버리지 및 세부 내용은 다를 수 있습니다. 예를 들어 여러분이 선택한 지역에 식당 정보가 없다면, 다른 지역을 선택해야 할 수도 있습니다.

6.2.4. basic Follow Along: Start a Project and get the Data

We first need to load the data to work with.

  1. Start a new QGIS project

  2. If you want, you can add a background map. Open the Browser and load the OSM background map from the XYZ Tiles menu.

    ../../../_images/osm_swellendam.png
  3. In the training_data.gpkg Geopackage database, you will find most the datasets we will use in this chapter:

    1. buildings

    2. roads

    3. restaurants

    4. schools

    Load them, and also landuse.sqlite.

  4. Zoom to the layer extent to see Swellendam, South Africa

    Before proceeding we will filter the roads layer, in order to have only some specific road types to work with.

    Some roads in OSM datasets are listed as unclassified, tracks, path and footway. We want to exclude these from our dataset and focus on the other road types, more suitable for this exercise.

    Moreover, OSM data might not be updated everywhere, and we will also exclude NULL values.

  5. Right click on the roads layer and choose Filter….

  6. In the dialog that pops up we filter these features with the following expression:

    "highway" NOT IN ('footway', 'path', 'unclassified', 'track') AND "highway" IS NOT NULL
    

    The concatenation of the two operators NOT and IN excludes all the features that have these attribute values in the highway field.

    IS NOT NULL combined with the AND operator excludes roads with no value in the highway field.

    Note the indicatorFilter icon next to the roads layer. It helps you remember that this layer has a filter activated, so some features may not be available in the project.

The map with all the data should look like the following one:

../../../_images/osm_swellendam_2.png

6.2.5. basic Try Yourself 레이어 CRS 변환

Because we are going to be measuring distances within our layers, we need to change the layers’ CRS. To do this, we need to select each layer in turn, save the layer to a new one with our new projection, then import that new layer into our map.

You have many different options, e.g. you can export each layer as an ESRI Shapefile format dataset, you can append the layers to an existing GeoPackage file, or you can create another GeoPackage file and fill it with the new reprojected layers. We will show the last option, so the training_data.gpkg will remain clean. Feel free to choose the best workflow for yourself.

참고

In this example, we are using the WGS 84 / UTM zone 34S CRS, but you should use a UTM CRS which is more appropriate for your region.

  1. Right click the roads layer in the Layers panel

  2. Click Export –> Save Features As…

  3. In the Save Vector Layer As dialog choose GeoPackage as Format

  4. Click on for the File name, and name the new GeoPackage vector_analysis

  5. Change the Layer name to roads_34S

  6. Change the CRS to WGS 84 / UTM zone 34S

  7. Click on OK:

    ../../../_images/save_roads_34S.png

    This will create the new GeoPackage database and add the roads_34S layer.

  8. Repeat this process for each layer, creating a new layer in the vector_analysis.gpkg GeoPackage file with _34S appended to the original name and removing each of the old layers from the project.

    참고

    When you choose to save a layer to an existing GeoPackage, QGIS will append that layer to the GeoPackage.

  9. Once you have completed the process for all the layers, right click on any layer and click Zoom to layer extent to focus the map to the area of interest.

Now that we have converted OSM data to a UTM projection, we can begin our calculations.

6.2.6. basic Follow Along: 문제 분석: 학교 및 도로부터의 거리

QGIS allows you to calculate distances between any vector object.

  1. Make sure that only the roads_34S and buildings_34S layers are visible (to simplify the map while you’re working)

  2. Click on the Processing ► Toolbox to open the analytical core of QGIS. Basically, all algorithms (for vector and raster analysis) are available in this toolbox.

  3. We start by calculating the area around the roads_34S by using the Buffer algorithm. You can find it in the Vector Geometry group.

    ../../../_images/processing_buffer_1.png

    Or you can type buffer in the search menu in the upper part of the toolbox:

    ../../../_images/processing_buffer_2.png
  4. Double click on it to open the algorithm dialog

  5. Select roads_34S as Input layer, set Distance to 50 and use the default values for the rest of the parameters.

    ../../../_images/vector_buffer_setup.png
  6. The default Distance is in meters because our input dataset is in a Projected Coordinate System that uses meter as its basic measurement unit. You can use the combo box to choose other projected units like kilometers, yards, etc.

    참고

    If you are trying to make a buffer on a layer with a Geographical Coordinate System, Processing will warn you and suggest to reproject the layer to a metric Coordinate System.

  7. By default, Processing creates temporary layers and adds them to the Layers panel. You can also append the result to the GeoPackage database by:

    1. Clicking on the button and choose Save to GeoPackage…

    2. Naming the new layer roads_buffer_50m

    3. Saving it in the vector_analysis.gpkg file

    ../../../_images/buffer_saving.png
  8. Click on Run, and then close the Buffer dialog

    이제 여러분의 맵이 다음처럼 보일 것입니다.

    ../../../_images/roads_buffer_result.png

If your new layer is at the top of the Layers list, it will probably obscure much of your map, but this gives you all the areas in your region which are within 50m of a road.

Notice that there are distinct areas within your buffer, which correspond to each individual road. To get rid of this problem:

  1. Uncheck the roads_buffer_50m layer and re-create the buffer with Dissolve results enabled.

    ../../../_images/dissolve_buffer_setup.png
  2. Save the output as roads_buffer_50m_dissolved

  3. Click Run and close the Buffer dialog

Once you have added the layer to the Layers panel, it will look like this:

../../../_images/dissolve_buffer_results.png

이제 필요 없는 부분들이 사라졌습니다.

참고

The Short Help on the right side of the dialog explains how the algorithm works. If you need more information, just click on the Help button in the bottom part to open a more detailed guide of the algorithm.

6.2.7. basic Try Yourself 학교로부터의 거리

앞 단계와 동일한 방법으로 학교를 중심으로 하는 버퍼를 생성하십시오.

It shall be 1 km in radius. Save the new layer in the vector_analysis.gpkg file as schools_buffer_1km_dissolved.

6.2.8. basic Follow Along: 겹치는 구역

Now we have identified areas where the road is less than 50 meters away and areas where there is a school within 1 km (direct line, not by road). But obviously, we only want the areas where both of these criteria are satisfied. To do that, we will need to use the Intersect tool. You can find it in Vector Overlay group in the Processing Toolbox.

  1. Use the two buffer layers as Input layer and Overlay layer, choose vector_analysis.gpkg GeoPackage in Intersection with Layer name road_school_buffers_intersect. Leave the rest as suggested (default).

    ../../../_images/school_roads_intersect.png
  2. Run 을 클릭합니다.

    In the image below, the blue areas are where both of the distance criteria are satisfied.

    ../../../_images/intersect_result.png
  3. 이제 두 버퍼 레이어를 제거하고 겹치는 구역만 보여주는 레이어만 남겨도 됩니다. 원래 그 레이어만을 원했기 때문입니다.

    ../../../_images/final_intersect_result.png

6.2.9. basic Follow Along: Extract the Buildings

Now you’ve got the area that the buildings must overlap. Next, you want to extract the buildings in that area.

  1. Look for the menu entry Vector Selection ► Extract by location within the Processing Toolbox

  2. Select buildings_34S in Extract features from. Check intersect in Where the features (geometric predicate), select the buffer intersection layer in By comparing to the features from. Save to the vector_analysis.gpkg, and name the layer well_located_houses.

    ../../../_images/location_select_dialog.png
  3. Click Run and close the dialog

  4. You will probably find that not much seems to have changed. If so, move the well_located_houses layer to the top of the layers list, then zoom in.

    ../../../_images/select_zoom_result.png

    The red buildings are those which match our criteria, while the buildings in green are those which do not.

  5. Now you have two separated layers and can remove buildings_34S from the layer list.

6.2.10. moderate Try Yourself 한 번 더 건물을 필터링

이제 학교에서 1km, 도로에서 50m 이내에 있는 모든 건물들을 보여주는 레이어가 생성됐습니다. 다음으로 이 레이어에서 식당으로부터 500m 이내에 있는 건물들만 추려내야 합니다.

Using the processes described above, create a new layer called houses_restaurants_500m which further filters your well_located_houses layer to show only those which are within 500m of a restaurant.

6.2.11. basic Follow Along: 면적 기준을 만족하는 건물 선택

To see which buildings are of the correct size (more than 100 square meters), we need to calculate their size.

  1. Select the houses_restaurants_500m layer and open the Field Calculator by clicking on the calculateField Open Field Calculator button in the main toolbar or in the attribute table window

  2. Select Create a new field, set the Output field name to AREA, choose Decimal number (real) as Output field type, and choose $area from the Geometry group.

    ../../../_images/buildings_area_calculator.png

    The new field AREA will contain the area of each building in square meters.

  3. Click OK. The AREA field has been added at the end of the attribute table.

  4. Click the toggleEditing Toggle Editing button to finish editing, and save your edits when prompted.

  5. In the Source tab of the layer properties, set the Provider Feature Filter to "AREA >= 100.

    ../../../_images/buildings_area_query.png
  6. OK 를 클릭합니다.

Your map should now only show you those buildings which match our starting criteria and which are more than 100 square meters in size.

6.2.12. basic Try Yourself

Save your solution as a new layer, using the approach you learned above for doing so. The file should be saved within the same GeoPackage database, with the name solution.

6.2.13. In Conclusion

Using the GIS problem solving approach together with QGIS vector analysis tools, you were able to solve a problem with multiple criteria quickly and easily.

6.2.14. What’s Next?

In the next lesson, we will look at how to calculate the shortest distance along roads from one point to another.