G Exercise 05
Last updated: 2020-09-28 17:50:20
G.1 Question 1
- Recall that the
focal2functions from Section 9.4, which we used to apply a focal filter. The
focal2function excludes the first and last rows and columns (Figure G.1).
- Modify the definitions of the
focal2functions from Section 9.4, so that the first and last rows and columns are also processed, even though they have incomplete neighbornoods. This means that for focal cells in the first or last row/column, the function shoud be applied on the available values plus
NAvalues for the “missing” neighbors. For example, for the pixel in row 8 column 1 of
dem.tif, the \(3\times 3\) neighborhood consists of five non-
NAvalues plus four
NAvalues (Figure G.2).
- Apply the modified filter with the
- Plot the resulting raster, including rounded values, as shown in the right panel of (Figure G.3).
- Hint: there are (at least) two ways to solve this exercise: (1) modify the
get_neighborsfunction so that if the position is on matrix edges then the values are only extracted from intact cells, or (2) temporarily add a “buffer” of
NAvalues on all sides of the matrix with the raster values, apply the filter on the expanded matrix, then discard the buffer.
G.2 Question 2
- Read the
MOD13A3_2000_2019.tifraster, with monthly NDVI values, into a
rto UTM with
st_warp(r, crs = 32636).
- Read the Shapefile named
nafot.shp, which includes polygons of “Nafa” administrative regions in Israel, and reproject it to UTM as well.
- Calculate the average NDVI for each of the polygons for each date (hint: use
- Plot the resulting time series of average NDVI for each of the “Nafot”, as shown in Figure G.4. (Hint: you can start from an empty plot using
plot(..., col=NA, then add the NDVI times series using
forloop; see Section 6.1.3 for an example)
- The “Nafa” that has the highest and lowest NDVI (on any date) needs to be highlighted in blue and red, respectively. The other “Nafot” should be displayed in grey. Don’t specific use “Nafa” indices (such as
6) or names (such as
"Golan"), instead calculate the required indices in your code.