Vector analysis with QGIS
In this module, we will do a simple exercise to explore QGIS basic analysis capabilities.
For this exercise, we will play with data from Beijing area. Downloaded the required data from http://mapmaking.info/images/files/beijing.gpkg.zip.
Unzip the file, and drag the geopackage file on top of a new QGIS project.
Without take too much time, do some styling to improve the map visualization:
- Arrange the layers order, to make sure that areas (polygons) are below other layers (points)
beijing natural anygreen
beijing waterways anyblue and larger (pen width >= 2)
beijing roads anyblack
To handle the growing traffic in Beijing, the city authorities decided to enlarge the 知春路 (Zhīchūn lù) street. That is the street in front of the hotel Park Plaza Beijing Science Park.
They decided to enlarge the street by 50 meters (for each side).
This is a decision with great impact. There are buildings facing the street. The owners would like to receive a fair price for their buildings.
We need to identify the building affected by this decision. We also need to estimate the price to pay to building owners, knowing that that city will pay 5000 元 (Yuán) for each square meter.
Identify and select the street Zhīchūn
To search for this road, open the attribute table of the
beijing roads any layer.
On the left bottom corner, create a new filter based on the name field.
Copy and paste the chinese name to the filter field: 知春路
The result will not just one, but several road segments.
Identify and select the Zhīchūn street
From the total of 59589 road segments, 18 are filtered. Only the filtered segments are shows in the attribute table.
Use the left upper corner to select all filtered segments. There should be 18 features select and 18 selected as well.
Click on the zoom to the selection button on the toolbar.
To calculate the 50 m area around Zhīchūn street, we will use the buffer calculator, available from: Vector → Geoprocessing Tools → Buffer(s)...
Adjust the buffer visualization
The new buffer polygon is added to the map.
To improve the buffer visualization, drag this layer on top of the others. Change the stype, to make around 50% transparent.
Calculating affected buildings
We use the buffer area to cut out the buildings. Select Vector → Geoprocessing Tools → Clip.
Fill in the Clip dialog with the following values:
A new layer with only the buildings within the buffer are included (48 buildings were affected). Adjust your style if necessary to distinguish the clipped buildings from the others.
Now that we have one layer with all the buildings affected, to calculate the cost to pay to each owner is quite simple: we need to multiply the area by 5000. To do so, we use the QGIS field calculator. We will compute the area and the value to pay to the owners in two separated steps.
We start by opening the attribute table of the layer with the affected buildings (layer buildingaffected). On the top bar, we can see that 48 building were within or partially within the 50 m of the Zhīchūn street.
Click on the field calculator. The field calculator dialog will open.
Add a field area, of type Decimal number (real), with 2 decimal places for the precision. Fill that new field with the expression: $area.
Add another field value, of type Decimal number (real), with 2 decimal places for the precision. Fill that new field with the expression: "area" * 5000.
The layer was changed by the field calculator. Toggle the editing mode to save (or discard) the changes.
Obliviously, we really don't need the area column and we could calculate the payment in just one step, with the expression:
$area * 5000