Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions 06-raster-vector.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,18 @@ grid.text("B. Elevation along the line", vp = viewport(layout.pos.row = 1, layou
print(rast_poly_line, vp = viewport(layout.pos.row = 2, layout.pos.col = 1))
print(plot_transect, vp = viewport(layout.pos.row = 2, layout.pos.col = 2))
```
The previous method calculates straight-line distances from the starting point, which may not reflect the actual length of curved or winding paths. To compute true distances along a non-linear route, the coordinates of the segmented points can be used to calculate cumulative distances between successive points:

```r
zion_transect_coordinates = zion_transect |> group_by(id) |> st_coordinates()
point_distances = c(
0,
cumsum(sqrt(rowSums(diff(zion_transect_coordinates)^2)))
)
zion_transect = zion_transect |>
mutate(dist = point_distances)
```
This approach sums the Euclidean distance between each pair of consecutive points along the path, yielding a more realistic elevation profile for non-linear transects.

\index{raster!extraction polygons}
The final type of geographic vector object for raster extraction is **polygons**.
Expand Down