Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

GeoPython Exercises - A

👥 Population Analysis

  1. Create a Python script that iterates over the cities (municities) and prints:

    • The name of each city

    • The population in 2020

    • The change in population from 2015 to 2020

    • The population density in persons per 100 square meters

Assumptions/Data

  • You have a vector file containing municities and their respective attributes (name, pop2020, pop2015): data/ncr.gpkg.

  • The population data is stored as integers.

Expected Output

City: City1
Population in 2020: 100000
Change in population from 2015 to 2020: 5000
Population density: 10000.0 persons/100sqm

City: City2
Population in 2020: 200000
Change in population from 2015 to 2020: 10000
Population density: 20000.0 persons/100sqm

... (iterate over all cities)

👥👥 Population Analysis 2

  1. Compute for a simple annual average rate of change of the population from 1990 to 2020 for each municity.

  2. Map the results.

Assumptions/Data

  • You have a vector file containing municities and their respective attributes (name, pop2020, pop2015): data/ncr.gpkg.

  • The population data is stored as integers.

Expected Output

  1. A map showing the average rate of change of the population from 1990 to 2020 for each municity in NCR.

💧 Calculating NDWI

The formula for NDWI using a Landsat satellite image is: NDWI = (Green - NIR) / (Green + NIR)

For the Landsat image:

  • Band 2 is the Green band.

  • Band 4 is the Near-Infrared (NIR) band.

Tasks

  1. Use numpy to calculate the ndwi array.

  2. Create a plot of your results. Use cmap='Blues' so that water shows up as dark blue.

Expected Output

  1. A plot displaying the NDWI values across the study area.

  2. Water bodies (e.g., lakes, rivers) should appear as dark blue in the plot due to the Blues colormap.

  3. The plot should include a legend to interpret NDWI values.

BONUS

  1. Download your own Landsat data (e.g. from GEE) and try to run it on that data.

🌳 Finding dense forest pixels

Tasks

  1. Download Landsat imagery for your area of interest.

  2. Compute for the NDVI of the area.

  3. Apply a boolean mask called dense_forest or all pixels where the NDVI value is strictly greater than 0.7.

  4. Use np.sum() to count exactly how many pixels meet this criteria.

  5. Display the mask.

Expected Output

  1. The number of dense forest pixels.

  2. A map of dense forest pixels.

Tip

  1. If the area is too big or processing is taking too long, you can clip the image to a smaller AOI.