4  Exercises

4.1 Vector layers

Use the following code section to create a GeoSeries with one LINESTRING geometry, representing the route of bus line 911 along the route named "RONDO ŚRÓDKA - BIEDRUSKO PARK|BIEDRUSKO PARK - RONDO ŚRÓDKA", based on the shapes.txt file from the GTFS dataset:

import pandas as pd
import shapely
import geopandas as gpd
shapes = pd.read_csv('data/gtfs/shapes.txt')
shapes = shapes[shapes['shape_id'] == 779677]
geom = gpd.points_from_xy(
    shapes['shape_pt_lon'], 
    shapes['shape_pt_lat'], 
    crs=4326
)
geom = gpd.GeoSeries(geom)
line = shapely.geometry.LineString(geom)
line = gpd.GeoSeries(line, crs=4326)
line
0    LINESTRING (16.95448 52.40952, 16.95435 52.409...
dtype: geometry

Re-create the poi point layer, with three points of interest in Poznan (Section 2.3).

Use the gpd.overlay function to calculate the segments of the route which are within 750-\(m\) buffers of the points of interest. Then, plot the buffers and the route segments, with (Figure 4.1 (a)) and without (Figure 4.1 (b)) the entire bus route in the background.

(a) Bus 911 route (light grey), buffers (dark grey), and segments (red)

(b) Buffers (dark grey), and segments (red)

Figure 4.1: Segments of bus 911 route which are within 750 \(m\) of the points of interest

4.2 Rasters

Read the hls.tif multi-band image which we created in Section 3.5.

Apply the pre-processing steps to obtain an array with reflectance values in the valid range (Section 3.7, Section 3.8, Section 3.9, Section 3.10).

Calculate an Normalized Difference Vegetation Index (NDVI) image of the area of Poznan, based on the array of reflectance values and using Equation 4.1. Recall that the Red is B04 and the NIR band is B08 (Section 3.5).

\[ NDVI=\frac{NIR-Red} {NIR+Red} \tag{4.1}\]

Once you have the array (e.g., ndvi), plot it using rasterio.plot.show with transform=src.transform (i.e., using the origin and resolution setting of the source file) and cmap='Greens' (i.e., color map = green colors) (Figure 4.2):

rasterio.plot.show(ndvi, transform=src.transform, cmap='Greens');

Figure 4.2: NDVI in the area of Poznan