Practical Session: Geoprocessing, Table Operations, and Zonal Statistics
This hands-on session walks you through coordinate transformations, vector geoprocessing (buffering, clipping), calculating catchment stats using zonal statistics, and using the Field Calculator to compute geometric values.
1. Setting Up the Workspace and Data Inputs
Before beginning the analysis, establish your data links and workspace inside QGIS:
-
Open QGIS and create a new project. Save it as
Day3_Vector_Analysis.qgzin your project folder. -
In the Browser Panel, add a directory shortcut to your training folder.
-
Load the following input datasets:
-
river_network.gpkg(Linear stream network of study basin). -
sub_catchments.gpkg(Polygon boundaries of catchment sub-zones). -
elevation_dem.tif(Continuous elevation raster grid, e.g., Copernicus DEM).
2. Reprojecting Layers to a Projected Coordinate System
Before running proximity buffers or calculating polygon areas, datasets must use projected metric coordinates (meters) rather than spherical degrees (degrees).
-
Go to Processing > Toolbox and search for the Reproject Layer tool.
-
Run the tool on
river_network.gpkg: -
Input Layer:
river_network.gpkg. -
Target CRS: Select WGS 84 / UTM Zone 45N (EPSG:32645) (the appropriate projected system for Nepal).
-
Save the reprojected layer to
data/processed/vector/rivers_projected.gpkg. -
Repeat the reprojection steps for the
sub_catchments.gpkgboundaries and save the output asdata/processed/vector/catchments_projected.gpkg. -
Remove the original unprojected layers from the Layers Panel to prevent formatting mistakes.
3. Creating a Dissolved Riparian Buffer Corridor
Delineate a \(500\text{ meter}\) environmental protection buffer corridor surrounding all major rivers:
-
Navigate to Vector > Geoprocessing Tools > Buffer.
-
Input Layer:
rivers_projected.gpkg. -
Distance: Enter
500(make sure the unit dropdown is set to meters). -
Segments: Enter
5(determines roundness of buffer corners). -
Check the box for Dissolve result. This merges overlapping buffers from adjacent river sections into a single continuous polygon.
-
Buffered: Click
...> Save to GeoPackage. Naming: - File path:
data/processed/vector/catchment_analysis.gpkg -
Table name:
riparian_buffer_500m -
Click Run. Toggle the layer styling to a semi-transparent blue fill to verify the buffer corridor surrounds the rivers correctly.
4. Clipping Geoprocessing Outputs
Clip the river buffer corridors to the specific boundary of a target sub-catchment to limit our study scope:
-
Navigate to Vector > Geoprocessing Tools > Clip.
-
Input Layer:
riparian_buffer_500m(the layer to be cut). -
Overlay Layer:
catchments_projected.gpkg(the polygon boundary acting as the cookie-cutter). -
Clipped: Click
...> Save to GeoPackage insidecatchment_analysis.gpkg. Naming the table:study_corridor_clipped. -
Click Run. A new layer will appear showing only the buffers that fall inside the catchment boundary.
5. Zonal Statistics Laboratory
Extract topographic elevations for each sub-catchment polygon from the digital elevation grid:
-
Search for Zonal Statistics in the Processing Toolbox.
-
Set the tool parameters:
-
Raster Layer:
elevation_dem.tif. -
Vector Layer containing zones:
catchments_projected.gpkg. -
Output Column Prefix: Enter
dem_(this flags the generated columns). -
Click Statistics to calculate (
...) and check Mean, Min, and Max. -
Zonal Statistics (Output): Set to save the updated table to a new table
catchments_elev_statsinsidecatchment_analysis.gpkg. -
Click Run.
-
Right-click the newly created
catchments_elev_statslayer in the Layers panel and select Open Attribute Table. Scroll to the far right to verify that three new columns (dem_mean,dem_min,dem_max) contain the extracted elevations for each catchment.
6. Dynamic Area Calculations via the Field Calculator
Calculate the total area in square kilometers (\(km^2\)) for each catchment polygon using database equations:
-
Open the attribute table of the
catchments_elev_statslayer. -
Click the Toggle Editing Mode icon (the pencil icon, or press
Ctrl+E). -
Click the Open Field Calculator icon (the abacus icon, or press
Ctrl+I). -
Configure the Field Calculator parameters:
-
Check Create a new field.
-
Output field name: Enter
area_sqkm. -
Output field type: Select Decimal number (real).
-
Precision: Set to
2(places after the decimal). -
In the expression editor panel, enter the geometry calculation formula:
$area / 1000000 -
Click OK. QGIS will compute and add the area values to every row.
-
Click the Save Edits icon and press
Ctrl+Eto toggle editing mode off.
7. Practical Session Exercises (Basic to Advanced)
The following 10 exercises test your geoprocessing, attribute querying, data conversion, and neighborhood analysis skills. They utilize various scales (110m, 50m, 10m) of cultural, physical, vector, and raster datasets available in your project directory.
Basic Level
Exercise 1: Multi-Scale Layer Properties and Feature Counts
Analyze the effect of cartographic scale and generalization on vector geometries.
-
Load
ne_110m_admin_0_countries.shp(coarse scale) andne_50m_admin_0_countries.shp(medium scale) from 110m_cultural and 50m_cultural folders. -
Open the Layer Properties > Information for both layers and identify the difference in coordinates precision and file sizes.
-
Open their Attribute Tables. Report the exact feature count (number of countries) contained in the 110m layer vs. the 50m layer.
Exercise 2: Projected Metric Lake Area Calculation
Calculate lake areas in projected metric units rather than spherical degrees.
-
Load the physical polygon layer
ne_50m_lakes.shpfrom the 50m_physical folder. -
Use the Reproject Layer tool to project the lakes into a metric CRS: WGS 84 / UTM Zone 45N (EPSG:32645). Save the output as
lakes_utm.gpkg. -
Open the Field Calculator on
lakes_utm.gpkgand create a new decimal field namedlake_area_sqkm. Use the formula:$area / 1000000 -
Sort the table by
lake_area_sqkmin descending order to identify the largest lake feature in the region.
Exercise 3: Landlocked African Country Attribute Selection
Perform attribute-based queries to filter specific spatial subsets.
-
Load
ne_110m_admin_0_countries.shp. -
Open Select by Expression (
Ctrl+F3) and run the following query to select landlocked African countries with population over 10 million:(Hint: You can check the attribute table structure to identify which columns contain landlocked flags or filter boundaries)."continent" = 'Africa' AND "pop_est" > 10000000 AND "featurecla" = 'Admin-0 country' -
Save the selected features to a new layer named
large_landlocked_africa.shp.
Exercise 4: Continental Boundary Dissolve
Aggregate national political boundaries into global continental shapes.
-
Load
ne_50m_admin_0_countries.shpinto your canvas. -
Go to Vector > Geoprocessing Tools > Dissolve.
-
Set the parameters:
- Input Layer:
ne_50m_admin_0_countries.shp. - Dissolve field(s): Check the box for
continent. -
Dissolved: Save to database as
continents_dissolved. -
Click Run and verify that internal national border lines are merged, leaving only continental outlines.
Intermediate Level
Exercise 5: Riparian Buffer Corridors of Major Rivers
Create metric proximity buffers around primary stream centerlines.
-
Load
ne_50m_rivers_lake_centerlines_scale_rank.shpfrom 50m_physical. -
Select the major continental rivers where scale rank is highest:
"scalerank" <= 2. -
Use Reproject Layer to reproject the selected river segments to WGS 84 / UTM Zone 45N (EPSG:32645) and save as
major_rivers_projected.gpkg. -
Run the Buffer tool on
major_rivers_projected.gpkgwith a distance of20Kilometers, checking the box for Dissolve result. Save the output asriver_buffers_20km.
Exercise 6: Map Algebra Masking on Shaded Relief
Create a binary raster grid classifying shaded relief brightness values.
-
Load the shaded relief raster
NE1_50M_SR_W.tiffrom the 50m_raster folder. -
Open Raster > Raster Calculator.
-
Write an expression to isolate dark valley/shadow pixels (brightness value less than 100):
"NE1_50M_SR_W@1" < 100 -
Save the output as
dark_relief_mask.tif. Verify that the output pixels contain only \(1\text{s}\) (shadows) and \(0\text{s}\) (bright surfaces).
Exercise 7: Spatial Join of Cities and Countries
Transfer political attributes to point-based populated places by spatial location.
-
Load
ne_50m_populated_places.shp(points) andne_50m_admin_0_countries.shp(polygons). -
Go to Vector > Data Management Tools > Join Attributes by Location.
-
Set the parameters:
- Input Layer:
ne_50m_populated_places(features to be joined to). - Join Layer:
ne_50m_admin_0_countries. - Geometric predicate: Select within.
- Fields to add: Click
...and checknameandiso_a3. - Join type: Take attributes of the first matching feature.
-
Joined layer: Save as
cities_joined_countries. -
Open the attribute table of
cities_joined_countriesand verify that the country details are appended to each city point.
Advanced Level
Exercise 8: Zonal Statistics of Shaded Relief across South Asia
Calculate topographical texture summary statistics for South Asian countries.
-
Load the shaded relief raster
NE1_50M_SR_W.tifand the countries vectorne_50m_admin_0_countries.shp. -
Filter the countries layer to select South Asian countries: Open Select by Expression on the countries layer and run:
"subregion" = 'Southern Asia' -
Open Zonal Statistics in the Processing Toolbox.
-
Set the parameters:
- Raster Layer:
NE1_50M_SR_W.tif. - Vector Layer containing zones:
ne_50m_admin_0_countries(check Selected features only). - Output Column Prefix: Enter
sr_. - Statistics to calculate: Select Mean, Min, and Max.
-
Zonal Statistics: Save as
south_asia_relief_stats. -
Run the tool. Inspect the output table and identify which South Asian country contains the lowest minimum shaded brightness (indicating the deepest valleys/shadows).
Exercise 9: Vectorizing DEM Peaks and Clipping to Nepal
Extract high-altitude mountain peaks as vector polygons and clip them to national bounds.
-
Load the continuous DEM grid
output_hh.tiffrom the DEM folder and the high-resolution countries layerne_10m_admin_0_countries.shpfrom 10m_cultural. -
Open Raster Calculator and generate a binary mask of peaks higher than \(5500\text{ meters}\):
Save the output as"output_hh@1" > 5500peaks_mask_5500m.tif. -
Open Raster > Conversion > Polygonize (Raster to Vector). Run it on
peaks_mask_5500m.tifwith a field nameis_peakto create a polygon layer namedpeaks_vector. -
Filter
peaks_vectorto keep only peak polygons: Select features where"is_peak" = 1and save them to a new layerhigh_altitude_peaks_only. -
Filter
ne_10m_admin_0_countries.shpfor Nepal ("NAME" = 'Nepal'). -
Run Vector > Geoprocessing Tools > Clip to clip the
high_altitude_peaks_onlypolygons using the Nepal boundary polygon. Save the final output asnepal_peaks_clipped.
Exercise 10: Multi-Criteria Spatial Query and Proximity Matrix
Identify major cities located in close proximity to main continental river channels.
-
Load
ne_10m_populated_places.shp(points) andne_10m_rivers_lake_centerlines.shp(lines). -
Select major cities with population greater than 1 million: Open Select by Expression on the populated places layer and run:
Save the selected features to a new layer named"pop_max" > 1000000major_cities. -
Select major rivers where scale rank is high: Open Select by Expression on the rivers layer and run:
Save the selected segments to a new layer named"scalerank" <= 3primary_rivers. -
Search for the Distance to nearest hub (points) tool in the Processing Toolbox.
-
Set the parameters:
- Source points layer:
major_cities. - Destination hubs layer:
primary_rivers. - Hub layer name attribute: Select
name(the river name field). - Measurement unit: Select Kilometers.
-
Hub distance: Save the output points as
cities_to_rivers_proximity. -
Run the tool. Open the attribute table of
cities_to_rivers_proximity. Use Select by Expression to identify which major cities lie within \(15\text{ km}\) of these major rivers:"HubDist" <= 15
13. Guided Mini-Assignment: Building a Hydrological GIS Database
In this assignment, you will apply the skills learned during Day 3 to clean vector datasets, execute spatial joins, calculate catchment statistics, compute geometric attributes, and compile a formatted layout map. This assignment is designed to require approximately 1 hour to complete.
Objective
Build a structured, centralized hydrological database inside a single GeoPackage file. You will calculate sub-basin average elevations, stream network lengths, and riparian buffer corridors, and export a cartographically sound print layout map illustrating your analytical results.
Provided Datasets
The following raw layers are located in your project directory:
* /data/vector/raw_districts.shp (Administrative boundary polygons, EPSG:4326).
-
/data/vector/river_branches.gpkg(Polyline stream centerlines, EPSG:4326). -
/data/raster/terrain_elevation.tif(Digital elevation model raster grid, EPSG:4326).
Step-by-Step Requirements
Step 1: Database Initialization and Reprojection
-
In the QGIS Browser panel, right-click a local folder and create a new OGC GeoPackage database file named
Basin_Hydrology_Database.gpkg. -
Import the raw
raw_districts.shpandriver_branches.gpkglayers. -
Reproject both layers into the metric UTM Zone 45N projection (EPSG:32645) to ensure all calculations use meter units. Store the reprojected tables inside
Basin_Hydrology_Database.gpkgas: district_boundariesriver_centerlines
Step 2: Proximity Buffer Analysis
Delineate a riparian conservation corridor around the river network:
-
Run the Buffer tool on
river_centerlines. -
Set the buffer distance to \(250\text{ meters}\).
-
Check the box to Dissolve result to merge overlapping stream buffers.
-
Save the output table directly inside your GeoPackage database as
riparian_buffer_250m.
Step 3: Zonal Statistics and Attribute Calculations
Extract elevation statistics and calculate geographic metrics for the administrative districts:
- Run the Zonal Statistics tool:
- Raster Layer:
terrain_elevation.tif. - Vector Layer (Zones):
district_boundaries. - Output Prefix:
elev_. -
Statistics: Calculate
MeanandMax. -
Save the output table in your GeoPackage as
districts_elevation_summary. -
Open the attribute table of
districts_elevation_summary. Turn on editing mode (Ctrl+E) and open the Field Calculator (Ctrl+I): - Create a new field named
area_sqkm(Decimal number, Precision: 2). Formula:$area / 1000000 - Save changes and toggle editing mode off.
Step 4: Map Layout and Cartography
Create a publication-quality map of your study area:
-
Open a new Print Layout and set the page size to A4 Landscape.
-
Add a map frame rendering the following layers:
- Top Layer:
riparian_buffer_250mstyled in semi-transparent light blue (Hex#4a90e2) with a dashed border. - Middle Layer:
river_centerlinesstyled as thin blue lines. -
Bottom Layer:
districts_elevation_summarystyled using Graduated Symbology based on theelev_meanfield. Apply a Viridis or YlOrRd color ramp, classified into \(5\) bins using Jenks Natural Breaks. -
Add the following cartographic elements to the layout page:
- Title Block: "Administrative District Elevation and Riparian Buffer Map".
- Scale Bar: Dynamic metric scale bar (labeled in km).
- North Arrow: Placed in an open quadrant.
- Legend: Clear labels for each active layer. Clean up raw column name entries (e.g. rename
elev_meanrange bins to "Average Elevation (meters)"). - Map Grid (Graticule): Add coordinate lines displayed in UTM meter values along the map borders.
Submission Instructions
Export your layout map as a PDF. Compile a ZIP archive named Day3_Assignment_[YourName].zip containing:
-
The exported PDF map (
District_Elevation_Buffer_Map.pdf). -
The completed GeoPackage database container (
Basin_Hydrology_Database.gpkg) containing all four tables. -
The QGIS project configuration file (
Day3_Assignment.qgz) saved with relative data paths.