Before we begin
Section titled “Before we begin”For exercises in this module, you will use the bnhr_qgis-architects-planners-urban-001.gpkg inside the data subfolder in the BNHR_QGIS-for-Architects-Planners-and-Urban-Practitioners folder.
This geopackage contains the barangay boundary layer. The population CSV (pop_brgy_quezon_city.csv) and the list of barangays per district (quezon-city-barangay-per-district.rtf) are in the same data subfolder.
What we want to achieve
Section titled “What we want to achieve”- Create a barangay-level layer with population data from 2000 to 2020.
- Create a district-level layer with population data from 2000 to 2020.
- Prepare both layers for mapping population density and the annual rate of population growth from 2000 to 2020 in Styling and symbology.
What we have
Section titled “What we have”-
bnhr_qgis-architects-planners-urban-001.gpkg that contains:
- adm_brgy_quezon_city - polygon layer containing the 142 barangays in Quezon City with the following attributes:
- barangay: name of the barangay
- municity: name of the city or municipality
- province: name of the province
- region: name of the region
- psgc_barangay: Philippine Standard Geographic Code (PSGC) of the barangay
- psgc_corr_barangay: PSGC Correspondence Code of the barangay,
- municity_income_class: income class of the city or municipality
- urban_rural: urban or rural classification of the barangay
- pop2020: population of the barangay in 2020
- adm_brgy_quezon_city - polygon layer containing the 142 barangays in Quezon City with the following attributes:
-
pop_brgy_quezon_city.csv - CSV file containing population data from 2000 to 2015 per barangay in Quezon City
-
quezon-city-barangay-per-district.rtf - text document listing down the barangays per district in Quezon City
Relevant QGIS knowledge/skills
Section titled “Relevant QGIS knowledge/skills”- Attribute table
- Selects and filters by attribute
- Attribute joins
- Field calculator
- Expressions
- Data-defined overrides
Exploring the data
Section titled “Exploring the data”First, let’s explore the data to see what we’re working with.
- Load the adm_brgy_quezon_city vector layer and pop_brgy_quezon_city.csv in QGIS.
For the CSV layer, make sure that the psgc and psgc_corr fields are loaded as strings and the pop2000, pop2007, pop2010, and pop2015 fields are loaded as integers.
You can ensure this by loading the CSV as a Delimited Text Layer or by using a .csvt file


1.1. Opening the attribute table
Section titled “1.1. Opening the attribute table”Level: Beginner
Let’s look at the attribute table of both layers.
- You can open the attribute table of a layer by:
- Right-click layer ‣ Open Attribute Table,
- Open Attribute Table in the Attributes Toolbar, or
- Clicking F6 while a layer is active/selected


What do you notice? What fields/attributes are similar?
1.2. Selecting or filtering the data
Section titled “1.2. Selecting or filtering the data”Level: Beginner
Let’s try to select and filter features based on their attributes.
To apply a selection, you can use the options on the attribute table or the Selection Toolbar.


-
Select the barangays with population in 2020 greater than 10000 using a Select Features by Value. You can open the Select Features by Value dialog by clicking the appropriate button (
) on the attribute table of the layer. Alternatively, you can go to Select Features by Value in the Selection Toolbar. -
On the Select Features by Value dialog, put 10000 and Greater than (>) in the pop2020 row.

- Your selection (65 barangays) should reflect in both the attribute table and the map canvas (i.e. the rows in the attribute table and the features in the map canvas will both be highlighted).


-
Deselect the features by clicking the Deselect all (CTRL + SHIFT + A) button (
) in the attribute table or in the Selection Toolbar. -
Now try to use a Select Features by Expression to select the barangays with population in 2020 greater than 50,000. Open the Select Features by Expression dialog by clicking the appropriate button (
) on the attribute table of the layer. Alternatively, you can go to Select Features by Expression in the Selection Toolbar. The Select by Expression dialog will appear. Input the expression below and click Select Features.
pop2020 > 50000
-
Your selection (20 barangays) should appear in the map canvas and attribute table.
-
Deselect the features.


Now let’s try a filter to show only the barangays with population in 2020 > 100,000.
- Open the query builder by right clicking on the layer and clicking Filter. Apply the filter below then click OK. You can click Test to check if your filter before applying it to the layer.
pop2020 > 100000
- You will notice that a layer has a filter applied because it will have a filter icon next to its name in the Layers Panel.

- Notice also that only the features that meet the specified criteria are visible in the map canvas and the attribute table of the layer.


- To undo a filter, remove the query or click Clear on the Query Builder then click OK.
What is the main difference between a select and a filter? What effects does this difference have?
Modifying the data
Section titled “Modifying the data”In the following exercises, we will modify our data in order to create a barangay-level layer with population data from 2000 to 2020 and a district-level layer with population data from 2000 to 2020. You will style both layers in Styling and symbology.
2.1. Adding population data from 2000 to 2015 using attribute joins
Section titled “2.1. Adding population data from 2000 to 2015 using attribute joins”Level: Beginner
First, let’s learn about attribute joins.
Attribute joins are used in QGIS to combine the attributes of two or more data sources based on a common field. This is useful when you have data that is related to each other but stored in separate files. It is also one of the most important functions of a GIS as it allows for non-spatial data to be made spatial.
In your case, you have a vector layer of barangay boundaries (adm_brgy_quezon_city) and a CSV file of population data (pop_brgy_quezon_city.csv) and you want to combine them to create a map of population density or population rate over time. You can do this by joining the attribute table of the CSV file with that of the vector layer.
There are two ways to perform attribute joins in QGIS. The first is via the Layer Properties ‣ Joins and the second is via the Join attributes by field value processing algorithm. The first one can be considered a soft join since it temporarily adds fields from the join table to the target table which can be removed/unjoined any time. The second option can be considered a hard join since it creates a new table from the joined attribute tables.
In order to successfully perform a join, the two attribute tables to be joined must have a common field present in both tables/layers.
The names of the common field between two layers to be joined need not be the same. What’s more important is that the values they contain correspond to one another. Think of a join similar to the matching-type activities we did in school.
There are other join processing algorithms such as Join attributes by nearest, Join attributes by location, and Join attributes by location (summary) but these perform joins using spatial relationships instead of comparing attributes. These join algorithms are discussed further in Spatial relationships and queries.
Now that we know about attribute joins, let’s apply it to our data.
- Load the adm_brgy_quezon_city vector layer and pop_brgy_quezon_city.csv in QGIS (if you haven’t yet).
For the CSV layer, make sure that the psgc and psgc_corr fields are loaded as strings and the pop2000, pop2007, pop2010, and pop2015 fields are loaded as integers.
You can ensure this by loading the CSV as a Delimited Text Layer or by using a .csvt file
- You can Right-click ‣ Properties ‣ Fields on a layer to double-check if its attributes/fields are of the correct type.


- Open the attribute table of the two layers again. What is/are common field/fields between the two? What can we use to join their attribute tables?


- Apply a soft join by going to the Layer Properties ‣ Joins tab of the adm_brgy_quezon_city layer. Click the green plus button (
) to add and join the pop_brgy_quezon_city layer.



Notice that the names of the Join field and Target field are not the same. This doesn’t matter because their values correspond to one another.
Under Joined fields, we unchecked barangay, psgc, and psgc_corr because the barangay names and codes already exist in the adm_brgy_quezon_city layer.
We left the Custom field name prefix blank. However, there are instances when adding a custom prefix would be useful—especially to avoid naming conflicts or duplication of field names in your layer. For example, if both the base layer and the join layer have a field named population, you may want to use a custom field name prefix so that you can identify which field came from the join layer and, more importantly, avoid conflicts and issues with your attribute table having two fields of the same name.
-
Click OK on the Add Vector Join dialog and OK again on the Joins tab.
-
Open the attribute table of the adm_brgy_quezon_city layer.

You should now be able to use the pop2015, pop2010, pop2007, and pop2000 fields as though they are part of the adm_brgy_quezon_city layer.
Because we did a soft join, we can easily remove the joined fields or edit what fields are joined from the Layer Properties of adm_brgy_quezon_city.
- Perform a hard join by using the Join attributes by Field Value algorithm with the parameters below.


- The output (Joined layer) should be loaded in the Layers panel. Open its attribute table and check if the population fields are there.

- Save the output (Joined layer) and name it something like adm_brgy_quezon_city_pop2000_2020.
2.2. Fixing a mistake in the Attributes
Section titled “2.2. Fixing a mistake in the Attributes”Level: Beginner
If you check the attribute table for adm_brgy_quezon_city_pop2000_2020, you will notice that there is a mistake in the values. In particular, the province field has Quezon City in it. In practice, while the National Capital Region has no provinces, we commonly use the NCR districts in place of a province. In this case, let’s replace the values in the province field with the correct value: 'NCR District (2nd District)'
You can edit the attribute values of a layer’s features directly in the attribute table. To do this, you must first enable editing mode on the layer:
- On the layer panel: right click on the layer ‣ Toggle Editing
- On the attribute table: Toggle editing mode (CTRL+E)
Afterwards, you can edit the attributes by:
- Manually editing the values in the individual cells
- Updating an entire row
- Using Expressions
You can also add and remove fields while editing mode is enabled.
To add a new field, click on the New Field (CTRL + W) button (
) on the attribute table toolbar and provide the appropriate parameters.
To remove a field, click on the Delete Field (CTRL + L) button (
) on the attribute table toolbar and select the field you want to delete.
-
Open the Attribute table to apply edits to the province field.
-
Using the Attribute table:
- Toggle Editing ON
- Select province
- In the Expression field:
'NCR District (2nd District)'- Click Update All or Update Selected

-
Don’t forget to save your edits!
-
Open the attribute table of adm_brgy_quezon_city_pop2000_2020 to see the results.

What should I do if I want to add a psgc_province or psgc_region field?
- Check Update existing field
- Select province
- In the Expression tab:
'NCR District (2nd District)'- Click OK

2.3. Adding a district field to the barangay boundary data
Section titled “2.3. Adding a district field to the barangay boundary data”Level: Intermediate
Let’s learn more about the Field Calculator.
QGIS has a powerful Field Calculator that allows you to perform calculations on fields in a layer. You can use it to create new fields, update existing fields, or calculate values based on existing fields. The kinds of operations you can run in the field calculator range from basic mathematical operations such as addition, subtraction, multiplication, and division; boolean and conditional operations such as ifs and comparisons; as well as more complex calculations using the built-in functions and operators of the QGIS expression engine.
The Field calculator can be accessed by clicking the Open Field Calculator button (
) in the Attributes Toolbar or in the attribute table itself. This will open the Field Calculator dialog where you can input the parameters of the field you want to calculate, the expression or formula you want to use, and even be able to preview the results. You also have the option to use the Field Calculator to update an existing field.
When we perform calculations using the Field Calculator, it’s important to make sure that the data types of the fields we are working with match the requirements of the calculation. For example, we cannot perform arithmetic operations on text fields or concatenate numeric fields with text fields.
You can refer to the QGIS User Manual for more information about how to use expressions: https://docs.qgis.org/latest/en/docs/user_manual/expressions/expression.html
The list of functions that are available in QGIS are also available at: https://docs.qgis.org/latest/en/docs/user_manual/expressions/functions_list.html#functions-list
Take advantage of the Search function and information bar when creating your formulas or expressions.

For this exercise, you want to add a district field on the adm_brgy_quezon_city_pop2000_2020 layer that pertains to the district that the barangay is part of.
The list of Quezon City barangays per district can be found in the table below or in the quezon-city-barangay-per-district.rtf file.
Quezon City Barangays by District
| District | Barangays |
|---|---|
| 1st District | Alicia, Bagong Pag-asa, Bahay Toro, Balingasa, Bungad, Damar, Damayan, Del Monte, Katipunan, Mariblo, Masambong, N.S. Amoranto, Nayong Kanluran, Paang Bundok, Pag-ibig Sa Nayon, Paltok, Paraiso, Phil-Am, Project 6, Ramon Magsaysay, Saint Peter, Salvacion, San Antonio, San Isidro Labrador, San Jose, Santa Cruz, Santa Teresita, Santo Cristo, Santo Domingo, Sienna, Talayan, Vasra, Veterans Village, West Triangle, Lourdes, Maharlika, Manresa |
| 2nd District | Bagong Silangan, Batasan Hills, Commonwealth, Holy Spirit, Payatas |
| 3rd District | Amihan, Bagumbuhay, Bagumbayan, Bayanihan, Blue Ridge A, Blue Ridge B, Camp Aguinaldo, Claro, Dioquino Zobel, Duyan-duyan, E. Rodriguez, East Kamias, Escopa I, Escopa II, Escopa III, Escopa IV, Libis, Loyola Heights, Mangga, Marilag, Masagana, Matandang Balara, Milagrosa, Pansol, Quirino 2-A, Quirino 2-B, Quirino 2-C, Quirino 3-A, Saint Ignatius, San Roque, Silangan, Socorro, Tagumpay, Ugong Norte, Villa Maria Clara, West Kamias, White Plains |
| 4th District | Bagong Lipunan Ng Crame, Botocan, Central, Kristong Hari, Damayang Lagi, Aurora, Doña Imelda, Doña Josefa, Don Manuel, Horseshoe, Immaculate Concepcion, Kalusugan, Kamuning, Kaunlaran, Krus Na Ligas, Laging Handa, Malaya, Mariana, Obrero, Old Capitol Site, Paligsahan, Pinyahan, Pinagkaisahan, Roxas, Sacred Heart, San Isidro, San Martin De Porres, San Vicente, Santo Niño, Santol, Sikatuna Village, South Triangle, Tatalon, Teachers Village East, Teachers Village West, U.P. Campus, U.P. Village, Valencia |
| 5th District | Bagbag, Capri, Fairview, Greater Lagro, Gulod, Kaligayahan, Nagkaisang Nayon, North Fairview, Novaliches Proper, Pasong Putik Proper, San Agustin, San Bartolome, Santa Lucia, Santa Monica |
| 6th District | Apolonio Samson, Baesa, Balong Bato, Culiat, New Era, Pasong Tamo, Sangandaan, Sauyo, Talipapa, Tandang Sora, Unang Sigaw |
Using the Field Calculator, we’re going to:
- create a new field called district
- set the value of the district field to the district that the barangay is a part of
-
Open the Field Calculator for the adm_brgy_quezon_city_pop2000_2020 layer that you created in the last exercise by clicking the Open field calculator (CTRL + I) button (
) . -
You can also open its attribute table to access the Field Calculator and organize the columns to make it less cluttered.
As discussed in QGIS Expressions, QGIS expressions follow a very SQL like syntax.
- field/attribute = inside “double quotes” or no quotes if there is no whitespace
- strings = inside ‘single quotes’
- numbers = no quotes
-
On the Field Calculator, add the following parameters:
- Check Create new field
- Output field name:
district - Output field type: Text (string)
- Output field length: 20
- On the Expression tab:
CASEWHEN "barangay" IN ('Alicia', 'Bagong Pag-asa', 'Bahay Toro', 'Balingasa', 'Bungad', 'Damar', 'Damayan', 'Del Monte', 'Katipunan', 'Mariblo', 'Masambong', 'N.S. Amoranto', 'Nayong Kanluran', 'Paang Bundok', 'Pag-ibig Sa Nayon', 'Paltok', 'Paraiso', 'Phil-Am', 'Project 6', 'Ramon Magsaysay', 'Saint Peter', 'Salvacion', 'San Antonio', 'San Isidro Labrador', 'San Jose', 'Santa Cruz', 'Santa Teresita', 'Santo Cristo', 'Santo Domingo', 'Sienna', 'Talayan', 'Vasra', 'Veterans Village', 'West Triangle', 'Lourdes', 'Maharlika', 'Manresa') THEN '1st District'WHEN "barangay" IN ('Bagong Silangan', 'Batasan Hills', 'Commonwealth', 'Holy Spirit', 'Payatas') THEN '2nd District'WHEN "barangay" IN ('Amihan', 'Bagumbuhay', 'Bagumbayan', 'Bayanihan', 'Blue Ridge A', 'Blue Ridge B', 'Camp Aguinaldo', 'Claro', 'Dioquino Zobel', 'Duyan-duyan', 'E. Rodriguez', 'East Kamias', 'Escopa I', 'Escopa II', 'Escopa III', 'Escopa IV', 'Libis', 'Loyola Heights', 'Mangga', 'Marilag', 'Masagana', 'Matandang Balara', 'Milagrosa', 'Pansol', 'Quirino 2-A', 'Quirino 2-B', 'Quirino 2-C', 'Quirino 3-A', 'Saint Ignatius', 'San Roque', 'Silangan', 'Socorro', 'Tagumpay', 'Ugong Norte', 'Villa Maria Clara', 'West Kamias', 'White Plains') THEN '3rd District'WHEN "barangay" IN ('Bagong Lipunan Ng Crame', 'Botocan', 'Central', 'Kristong Hari', 'Damayang Lagi', 'Aurora', 'Doña Imelda', 'Doña Josefa', 'Don Manuel', 'Horseshoe', 'Immaculate Concepcion', 'Kalusugan', 'Kamuning', 'Kaunlaran', 'Krus Na Ligas', 'Laging Handa', 'Malaya', 'Mariana', 'Obrero', 'Old Capitol Site', 'Paligsahan', 'Pinyahan', 'Pinagkaisahan', 'Roxas', 'Sacred Heart', 'San Isidro', 'San Martin De Porres', 'San Vicente', 'Santo Niño', 'Santol', 'Sikatuna Village', 'South Triangle', 'Tatalon', 'Teachers Village East', 'Teachers Village West', 'U.P. Campus', 'U.P. Village', 'Valencia') THEN '4th District'WHEN "barangay" IN ('Bagbag', 'Capri', 'Fairview', 'Greater Lagro', 'Gulod', 'Kaligayahan', 'Nagkaisang Nayon', 'North Fairview', 'Novaliches Proper', 'Pasong Putik Proper', 'San Agustin', 'San Bartolome', 'Santa Lucia', 'Santa Monica') THEN '5th District'WHEN "barangay" IN ('Apolonio Samson', 'Baesa', 'Balong Bato', 'Culiat', 'New Era', 'Pasong Tamo', 'Sangandaan', 'Sauyo', 'Talipapa', 'Tandang Sora', 'Unang Sigaw') THEN '6th District'END

-
Click OK.
-
Open the attribute table of the adm_brgy_quezon_city_pop2000_2020 and check if a new district field is added.

Don’t forget to save your edits! Otherwise, they will not be reflected in your layer. To do this, you can:
- Right-click on the layer being edited on the Layers Panel ‣ Current Edits ‣ Save…
- Clicking the Save edits (CTRL + S) button (
) on the attribute table toolbar.
2.4. Creating a district-level admin boundary data with correct population values
Section titled “2.4. Creating a district-level admin boundary data with correct population values”Level: Intermediate
First, let’s learn about the Aggregate algorithm.
The Aggregate algorithm can be used to dissolve boundaries, remove overlaps, and merge adjacent polygons while aggregating the attributes associated with each feature. It is commonly used in data preprocessing for spatial analysis as well as for general data management tasks. With the Aggregate algorithm, you can easily summarize data for different levels of analysis such as administrative boundaries or land use types. Additionally, the algorithm can be used in combination with other processing tools, plugins, and scripts to create more advanced data workflows.
In your case, you can use the Aggregate algorithm to create a district-level administrative boundary layer while also calculating their total population by taking the sum of the population of each barangay within a district.
- Open the Aggregate algorithm from the Locator Bar or via Processing Toolbox.
- Remove other unnecessary fields by selecting them and clicking the
symbol.

- Apply the following parameters.
- Group by expression: district
- district, municity, province, region: first_value
- pop2020, pop2015, pop2010, pop2007, pop2000: sum
You can specify which attributes will be included in the resulting layer as well as the aggregate function to use for each attribute. Here, you used first_value for district, municity, province, and region because the features are grouped per district, so every barangay in a group has the same values for these fields as the first one.
For the population fields, we used sum so that the resulting value will be the sum of the individual values of the features to be aggregated.

- Click Run.
- You should see a layer named Aggregated added to the Layer panel. You can rename or save this layer to adm_dist_quezon_city_pop2000_2020.


Compare the results of the Aggregate and the Dissolve processing algorithms.