Geoinformatics | Course Remote Sensing (1)
Schmitt | Ulloa
Summer Semester 2022
Objective: Creation of training polygons to train a supervised classification model
Data: For this practice, use the following files:
Tasks: Create training polygons for the following classes:
Use the assigned AOI as a working area, and the ortophotos as reference data
1. Load the rasters "S2A_L2A_T32UPU_rasterstack.tif" and "S2A_L2A_T32UPU_TCI.tif" on QGIS. What are the differences of both files in terms of number of bands, pixel size, pixel resolution, and pixel values?
2. For this practice you will work with a Sentinel 2 Bottom of Atmosphere product. To which processing level corresponds this?
3. Open the ortophoto provided for your area. Do you notice the difference with the Sentinel 2 image? What is the spatial resolution of this image?
4. Finally, load the shapefile corresponding to your working area (i.e. id_1.shp, id_2.shp, id_3.shp). If you want to have an overview of all the AOIs at once, you can load the shapefile AOIs.shp. Explore the properties of the shapefiles and under Right clik > Properties > Symbology > Simple fill
, change the filling of your shapefile to transparent. Change the color of the border of your shapefile, and if you want, also increase the thickness.
Your workspace should look something like this:
5. In order to be able to apreciate different features on a Sentinel-2 image, you can play around with bands combinations. In order to see an image, you have to assing all the bands of a Rasterstack into one of the three visualizations channels: Red, Green, Blue. Given the fact, that every element or feature from the landscape emits reflectance at different wavelengts, you can change the band for every RGB channel and be able to see these elements in different colors.
Right click on S2A_L2A_T32UPU_rasterstack.tif, Properties > Symbology
. Choose the following S2 band combination for all the channels: Red = Band 4, Green = Band 3, Blue = Band 2. If for creating the Rasterstack the Sentinel bands 2, 3, 4, 8 (BLUE, GREEN, RED, NIR) were chosen to fill the 1, 2, 3, 4 positions, can you tell which is the real band combination here chosen? For more information, visit this source.
6. Which features from the landscape are easier to see with this band combination?
7. Now change the visualization to True Color. Use the following bands: R[Band 1], G[Band 2], B[Band 3]. Which Sentinel-2 bands are actually being used here? For more information, visit this source.
8. Play around with the bands combinations. Which band combination allows you to distinguish urban areas better? Which band combination allows you to recognize healthy vegetation? Why do agricultural plots have differents colors on each band combination?
Students are divided in 3 groups. Each group works with one AOI subarea. Load the shapefile id_1.shp, id_2.shp, id_3.shp correspondingly. Right click > Zoom to Layer
and you will zoom into your working area.
Create polygons for every class you see on the image. Click on Layer > Create Layer > New Shapefile Layer
. A new window opens and you can define the attributes of the shapefile to create. Define name (for example, training_polygons.shp), geometry type (polygon), check that the CRS is the same as the one from raster file, and add a second attribute on the New Field
section. This new attribute is called "landclass". Click OK
.
For a start, create a shapefile for the landclass "deciduous_forest". Using the Ortophotos as a source of help, create a polygon that fits into a deciduous forest (Laubwald) area. Activate the shapefile by selecting it and then press Layer > Toggle Editing
. After this, the tool Add Polygon Feature
gets activated. You can find this tool under Edit > Add Polygon Feature
.Create 5-10 polygons for that class. Afterwards, create polygons for the other classes as indicated in the Practice Overview. Save your results by clicking on the Toggle Editing
tool.
Please follow these recomendations: create polygons that cover only one feature at a time. Do not make the polygons very big, since your working area is quite small. Always give the same id and landclass value to the polygon that belongs to the same class.Create the polygons inside of the borders of the shapefile of your AOI id.
import os
import rasterio
import numpy as np
import matplotlib.pyplot as plt
# Open the file:
src = r"C:\yourpath\data\p3"
s2_stack = rasterio.open(os.path.join(src, "boa_sentinel2\S2A_L2A_T32UPU_rasterstack.tif"))
# Normalize bands into 0.0 - 1.0 scale
def normalize(array):
array_min, array_max = array.min(), array.max()
return (array - array_min) / (array_max - array_min)
# Convert to numpy arrays
blue = s2_stack.read(1)
green = s2_stack.read(2)
red = s2_stack.read(3)
nir = s2_stack.read(4)
# Normalize band DN
blue_norm = normalize(blue)
green_norm = normalize(green)
red_norm = normalize(red)
nir_norm = normalize(nir)
# Stack bands
truecomp = np.dstack((blue_norm, green_norm, red_norm))
# View the true color composite
plt.imshow(truecomp)
<matplotlib.image.AxesImage at 0x209ac282fc8>
9. Using np.stack() create a false color composite called "falsecomp" with bands NIR, RED, and GREEN.