| Title: | Perpendicular Line Transects for Geosciences |
|---|---|
| Description: | Toolset to create perpendicular profile graphs and swath profiles. Method are based on coordinate rotation algorithm by Schaeben et al. (2024) <doi:10.1002/mma.9823>. |
| Authors: | Tobias Stephan [aut, cre] (ORCID: <https://orcid.org/0000-0002-9290-014X>) |
| Maintainer: | Tobias Stephan <[email protected]> |
| License: | GPL (>= 3) |
| Version: | 0.0.3.9001 |
| Built: | 2026-05-18 09:11:33 UTC |
| Source: | https://github.com/tobiste/geoprofiler |
Opens a plot window showing the the map with the data, where the user can click profile coordinates.
get_coordinates(x, n = 1, type = "o", col = "#B63679FF", ...) draw_profile(x, n = 10, ...)get_coordinates(x, n = 1, type = "o", col = "#B63679FF", ...) draw_profile(x, n = 10, ...)
x |
|
n |
the maximum number of points to locate. Valid values start at 1. |
type |
One of |
col |
color of line or point |
... |
additional graphics parameters used if |
sf object of the profile.
Extract End Points of a Line
line_ends(x)line_ends(x)
x |
|
sf point object
p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line() |> line_ends()p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line() |> line_ends()
sf data setexample dataset
data('locations_example')data('locations_example')
An object of class sf
data("locations_example") head(locations_example)data("locations_example") head(locations_example)
This uses the haversine formula (by default) to calculate the great-circle distance between two points, i.e., the shortest distance over the earth's surface.
point_distance(a, b, ...)point_distance(a, b, ...)
a |
lon, lat coordinate of point 1 |
b |
lon, lat coordinate of point 2 |
... |
parameters passed to |
units object giving the distance
berlin <- c(13.4, 52.517) # lon, lat tokyo <- c(139.767, 35.7) # lon, lat point_distance(berlin, tokyo)berlin <- c(13.4, 52.517) # lon, lat tokyo <- c(139.767, 35.7) # lon, lat point_distance(berlin, tokyo)
Azimuth Between Profile Points
profile_azimuth(x)profile_azimuth(x)
x |
|
If only two points are given, the azimuth is calculated using triangulation
from the tectonicr package.
If more than two points are given, the azimuth is calculated using linear
interpolation in the coordinate reference frame given by profile.
Azimuth as units object
p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_azimuth()p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_azimuth()
Project points on a cross section given by a starting point and the direction
profile_coords(x, profile, azimuth = NULL, drop.units = TRUE)profile_coords(x, profile, azimuth = NULL, drop.units = TRUE)
x |
|
profile |
|
azimuth |
numeric. Direction (in degrees) emanating from starting point.
Is ignored when |
drop.units |
logical. Whether the return should show the units or not. |
tibble where X is the distance along the profile line.
Y is the distance across the profile line. (units of X and Y depend on
coordinate reference system).
Tobias Stephan
data(locations_example) p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_crds <- profile_coords(locations_example, profile = p1, azimuth = 135) head(profile_crds) # Plot the transformed coordinates plot(profile_crds)data(locations_example) p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_crds <- profile_coords(locations_example, profile = p1, azimuth = 135) head(profile_crds) # Plot the transformed coordinates plot(profile_crds)
Length of Profile
profile_length(x, ...)profile_length(x, ...)
x |
|
... |
(optional) passed on to |
units object when coordinate system is set.
p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line() |> profile_length()p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line() |> profile_length()
Combine Points to a Line
profile_line(x)profile_line(x)
x |
|
sf line object
p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line()p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = 10000, crs = sf::st_crs("EPSG:26915") ) |> profile_line()
Create a end point along a profile line starting at a point with a defined direction and length.
profile_points( start, profile.azimuth, profile.length, crs = st_crs(start), return.sf = TRUE )profile_points( start, profile.azimuth, profile.length, crs = st_crs(start), return.sf = TRUE )
start |
|
profile.azimuth |
numeric or |
profile.length |
numeric or |
crs |
Coordinate reference system. Should be parsed by |
return.sf |
logical. Should the profile points be returned as a |
class depends on return.sf.
Use metric values (meters, kilometers, etc) in case of a projected coordinate reference frame, and degree when geographical coordinate reference frame.
p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = units::set_units(10, "km"), crs = sf::st_crs("EPSG:26915") )p1 <- data.frame(lon = -90.8, lat = 48.6) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") profile_points(p1, profile.azimuth = 135, profile.length = units::set_units(10, "km"), crs = sf::st_crs("EPSG:26915") )
example dataset
data('raster_example')data('raster_example')
An object of class matrix
data("raster_example") head(raster_example)data("raster_example") head(raster_example)
Calculate swath-profile values perpendicular to a straight baseline.
The distance between samples and the number of samples can be
specified, see arguments k and dist. Values of the swath-profile are
extracted from a given raster file, see argument raster. CRS of raster
and points have to be the same.
swath_profile( profile, raster, k = 1, dist, crs = terra::crs(raster), method = c("bilinear", "simple") )swath_profile( profile, raster, k = 1, dist, crs = terra::crs(raster), method = c("bilinear", "simple") )
profile |
either a
|
raster |
Raster file ( |
k |
integer. number of lines on each side of the baseline |
dist |
numeric. distance between lines. Unit depends on reference system specified by |
crs |
character. coordinate reference system. Both the |
method |
character. method for extraction of raw data, see
|
The final width of the swath is: .
list.
swathmatrix. Statistics of the raster measured along the lines
datalist of numeric vector containing the data extracted from the raster along each line
linesswath lines as "sf" objects
The unit of dist depends on the coordinate reference system specified
in crs (which uses the coordinate system of raster by default). This means,
a geographic coordinates system (e.g. WGS84) assumes units in degrees,
while a projected coordinate system (e.g. UTM) assumes meters.
The algorithm is a modified version of "swathR" by Vincent Haburaj (https://github.com/jjvhab/swathR).
# Create a random raster r <- terra::rast(ncol = 10, nrow = 10, xmin = -150, xmax = -80, ymin = 20, ymax = 60, crs = "WGS84") terra::values(r) <- runif(terra::ncell(r)) # Create a random profile profile <- data.frame(lon = c(-140, -90), lat = c(55, 25)) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") swath_profile(profile, r, k = 2, dist = 1)# Create a random raster r <- terra::rast(ncol = 10, nrow = 10, xmin = -150, xmax = -80, ymin = 20, ymax = 60, crs = "WGS84") terra::values(r) <- runif(terra::ncell(r)) # Create a random profile profile <- data.frame(lon = c(-140, -90), lat = c(55, 25)) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") swath_profile(profile, r, k = 2, dist = 1)
Statistics of the elevation data across a swath profile.
swath_stats(x, profile.length = 1)swath_stats(x, profile.length = 1)
x |
list. The return object of |
profile.length |
numeric or |
data.frame
# Create a random raster r <- terra::rast(ncol = 10, nrow = 10, xmin = -150, xmax = -80, ymin = 20, ymax = 60) terra::values(r) <- runif(terra::ncell(r)) # Create a random profile profile <- data.frame(lon = c(-140, -90), lat = c(55, 25)) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") swath <- swath_profile(profile, r, k = 5, dist = 10) swath_stats(swath, profile.length = profile_length(profile_line(profile)))# Create a random raster r <- terra::rast(ncol = 10, nrow = 10, xmin = -150, xmax = -80, ymin = 20, ymax = 60) terra::values(r) <- runif(terra::ncell(r)) # Create a random profile profile <- data.frame(lon = c(-140, -90), lat = c(55, 25)) |> sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") swath <- swath_profile(profile, r, k = 5, dist = 10) swath_stats(swath, profile.length = profile_length(profile_line(profile)))