Skip to content

Commit e400f2f

Browse files
committed
Deploy commit: Add new bonus exercise #766 11da7b1
1 parent 9649dfd commit e400f2f

File tree

5 files changed

+42
-15
lines changed

5 files changed

+42
-15
lines changed

Diff for: 04-spatial-operations.md

+27-7
Original file line numberDiff line numberDiff line change
@@ -976,8 +976,7 @@ For a more detailed introduction to remote sensing with R, see @wegmann_remote_2
976976
```r
977977
library(sf)
978978
library(dplyr)
979-
data(nz, package = "spData")
980-
data(nz_height, package = "spData")
979+
library(spData)
981980
```
982981

983982
E1. It was established in Section \@ref(spatial-vec) that Canterbury was the region of New Zealand containing most of the 100 highest points in the country.
@@ -998,29 +997,50 @@ E3. Generalizing the question to all regions: how many of New Zealand's 16 regio
998997

999998

1000999

1001-
E4. Use `dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))`, and reclassify the elevation in three classes: low (<300), medium and high (>500).
1000+
E4. Test your knowledge of spatial predicates by finding out and plotting how US states relate to each other and other spatial objects.
1001+
1002+
The starting point of this exercise is to create an object representing Colorado state in the USA. Do this with the command
1003+
`colorado = us_states[us_states$NAME == "Colorado",]` (base R) or with with the `filter()` function (tidyverse) and plot the resulting object in the context of US states.
1004+
1005+
- Create a new object representing all the states that geographically intersect with Colorado and plot the result (hint: the most concise way to do this is with the subsetting method `[`).
1006+
- Create another object representing all the objects that touch (have a shared boundary with) Colorado and plot the result (hint: remember you can use the argument `op = st_intersects` and other spatial relations during spatial subsetting operations in base R).
1007+
- Bonus: create a straight line from the centroid of the District of Columbia near the East coast to the centroid of California near the West coast of the USA (hint: functions `st_centroid()`, `st_union()` and `st_cast()` described in Chapter 5 may help) and identify which states this long East-West line crosses.
1008+
1009+
1010+
1011+
1012+
1013+
1014+
1015+
1016+
1017+
1018+
1019+
1020+
1021+
E5. Use `dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))`, and reclassify the elevation in three classes: low (<300), medium and high (>500).
10021022
Secondly, read the NDVI raster (`ndvi = rast(system.file("raster/ndvi.tif", package = "spDataLarge"))`) and compute the mean NDVI and the mean elevation for each altitudinal class.
10031023

10041024

10051025

1006-
E5. Apply a line detection filter to `rast(system.file("ex/logo.tif", package = "terra"))`.
1026+
E6. Apply a line detection filter to `rast(system.file("ex/logo.tif", package = "terra"))`.
10071027
Plot the result.
10081028
Hint: Read `?terra::focal()`.
10091029

10101030

10111031

1012-
E6. Calculate the Normalized Difference Water Index (NDWI; `(green - nir)/(green + nir)`) of a Landsat image.
1032+
E7. Calculate the Normalized Difference Water Index (NDWI; `(green - nir)/(green + nir)`) of a Landsat image.
10131033
Use the Landsat image provided by the **spDataLarge** package (`system.file("raster/landsat.tif", package = "spDataLarge")`).
10141034
Also, calculate a correlation between NDVI and NDWI for this area.
10151035

10161036

10171037

1018-
E7. A StackOverflow [post](https://stackoverflow.com/questions/35555709/global-raster-of-geographic-distances) shows how to compute distances to the nearest coastline using `raster::distance()`.
1038+
E8. A StackOverflow [post](https://stackoverflow.com/questions/35555709/global-raster-of-geographic-distances) shows how to compute distances to the nearest coastline using `raster::distance()`.
10191039
Try to do something similar but with `terra::distance()`: retrieve a digital elevation model of Spain, and compute a raster which represents distances to the coast across the country (hint: use `geodata::elevation_30s()`).
10201040
Convert the resulting distances from meters to kilometers.
10211041
Note: it may be wise to increase the cell size of the input raster to reduce compute time during this operation.
10221042

10231043

10241044

1025-
E8. Try to modify the approach used in the above exercise by weighting the distance raster with the elevation raster; every 100 altitudinal meters should increase the distance to the coast by 10 km.
1045+
E9. Try to modify the approach used in the above exercise by weighting the distance raster with the elevation raster; every 100 altitudinal meters should increase the distance to the coast by 10 km.
10261046
Next, compute and visualize the difference between the raster created using the Euclidean distance (E7) and the raster weighted by elevation.
Loading
0 Bytes
Loading

Diff for: search.json

+1-1
Large diffs are not rendered by default.

Diff for: spatial-operations.html

+14-7
Original file line numberDiff line numberDiff line change
@@ -916,8 +916,7 @@ <h2>
916916
<div class="sourceCode" id="cb157"><pre class="downlit sourceCode r">
917917
<code class="sourceCode R"><span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://r-spatial.github.io/sf/">sf</a></span><span class="op">)</span>
918918
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://dplyr.tidyverse.org">dplyr</a></span><span class="op">)</span>
919-
<span class="fu"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op">(</span><span class="va">nz</span>, package <span class="op">=</span> <span class="st">"spData"</span><span class="op">)</span>
920-
<span class="fu"><a href="https://rdrr.io/r/utils/data.html">data</a></span><span class="op">(</span><span class="va">nz_height</span>, package <span class="op">=</span> <span class="st">"spData"</span><span class="op">)</span></code></pre></div>
919+
<span class="kw"><a href="https://rdrr.io/r/base/library.html">library</a></span><span class="op">(</span><span class="va"><a href="https://jakubnowosad.com/spData/">spData</a></span><span class="op">)</span></code></pre></div>
921920
<p>E1. It was established in Section <a href="spatial-operations.html#spatial-vec">4.2</a> that Canterbury was the region of New Zealand containing most of the 100 highest points in the country.
922921
How many of these high points does the Canterbury region contain?</p>
923922
<p><strong>Bonus:</strong> plot the result using the <code><a href="https://r-spatial.github.io/sf/reference/plot.html">plot()</a></code> function to show all of New Zealand, <code>canterbury</code> region highlighted in yellow, high points in Canterbury represented with black dots and</p>
@@ -926,19 +925,27 @@ <h2>
926925
<ul>
927926
<li>Bonus: create a table listing these regions in order of the number of points and their name.</li>
928927
</ul>
929-
<p>E4. Use <code>dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))</code>, and reclassify the elevation in three classes: low (&lt;300), medium and high (&gt;500).
928+
<p>E4. Test your knowledge of spatial predicates by finding out and plotting how US states relate to each other and other spatial objects.</p>
929+
<p>The starting point of this exercise is to create an object representing Colorado state in the USA. Do this with the command
930+
<code>colorado = us_states[us_states$NAME == "Colorado",]</code> (base R) or with with the <code><a href="https://dplyr.tidyverse.org/reference/filter.html">filter()</a></code> function (tidyverse) and plot the resulting object in the context of US states.</p>
931+
<ul>
932+
<li>Create a new object representing all the states that geographically intersect with Colorado and plot the result (hint: the most concise way to do this is with the subsetting method <code>[</code>).</li>
933+
<li>Create another object representing all the objects that touch (have a shared boundary with) Colorado and plot the result (hint: remember you can use the argument <code>op = st_intersects</code> and other spatial relations during spatial subsetting operations in base R).</li>
934+
<li>Bonus: create a straight line from the centroid of the District of Columbia near the East coast to the centroid of California near the West coast of the USA (hint: functions <code><a href="https://r-spatial.github.io/sf/reference/geos_unary.html">st_centroid()</a></code>, <code><a href="https://r-spatial.github.io/sf/reference/geos_combine.html">st_union()</a></code> and <code><a href="https://r-spatial.github.io/sf/reference/st_cast.html">st_cast()</a></code> described in Chapter 5 may help) and identify which states this long East-West line crosses.</li>
935+
</ul>
936+
<p>E5. Use <code>dem = rast(system.file("raster/dem.tif", package = "spDataLarge"))</code>, and reclassify the elevation in three classes: low (&lt;300), medium and high (&gt;500).
930937
Secondly, read the NDVI raster (<code>ndvi = rast(system.file("raster/ndvi.tif", package = "spDataLarge"))</code>) and compute the mean NDVI and the mean elevation for each altitudinal class.</p>
931-
<p>E5. Apply a line detection filter to <code>rast(system.file("ex/logo.tif", package = "terra"))</code>.
938+
<p>E6. Apply a line detection filter to <code>rast(system.file("ex/logo.tif", package = "terra"))</code>.
932939
Plot the result.
933940
Hint: Read <code>?terra::focal()</code>.</p>
934-
<p>E6. Calculate the Normalized Difference Water Index (NDWI; <code>(green - nir)/(green + nir)</code>) of a Landsat image.
941+
<p>E7. Calculate the Normalized Difference Water Index (NDWI; <code>(green - nir)/(green + nir)</code>) of a Landsat image.
935942
Use the Landsat image provided by the <strong>spDataLarge</strong> package (<code>system.file("raster/landsat.tif", package = "spDataLarge")</code>).
936943
Also, calculate a correlation between NDVI and NDWI for this area.</p>
937-
<p>E7. A StackOverflow <a href="https://stackoverflow.com/questions/35555709/global-raster-of-geographic-distances">post</a> shows how to compute distances to the nearest coastline using <code><a href="https://rdrr.io/pkg/raster/man/distance.html">raster::distance()</a></code>.
944+
<p>E8. A StackOverflow <a href="https://stackoverflow.com/questions/35555709/global-raster-of-geographic-distances">post</a> shows how to compute distances to the nearest coastline using <code><a href="https://rdrr.io/pkg/raster/man/distance.html">raster::distance()</a></code>.
938945
Try to do something similar but with <code><a href="https://rdrr.io/pkg/terra/man/distance.html">terra::distance()</a></code>: retrieve a digital elevation model of Spain, and compute a raster which represents distances to the coast across the country (hint: use <code><a href="https://rdrr.io/pkg/geodata/man/elevation.html">geodata::elevation_30s()</a></code>).
939946
Convert the resulting distances from meters to kilometers.
940947
Note: it may be wise to increase the cell size of the input raster to reduce compute time during this operation.</p>
941-
<p>E8. Try to modify the approach used in the above exercise by weighting the distance raster with the elevation raster; every 100 altitudinal meters should increase the distance to the coast by 10 km.
948+
<p>E9. Try to modify the approach used in the above exercise by weighting the distance raster with the elevation raster; every 100 altitudinal meters should increase the distance to the coast by 10 km.
942949
Next, compute and visualize the difference between the raster created using the Euclidean distance (E7) and the raster weighted by elevation.</p>
943950

944951
</div>

0 commit comments

Comments
 (0)