Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiste committed Dec 4, 2024
1 parent 55d189c commit e4f71e7
Show file tree
Hide file tree
Showing 14 changed files with 29,122 additions and 41 deletions.
12 changes: 7 additions & 5 deletions R/profile_points.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
#' @param profile.azimuth numeric. Direction of profile in degrees.
#' @param profile.length units object.
#' @param crs Coordinate reference system. Should be readable by [sf::st_crs()].
#' @param return.sf logical. Should the profile points be returned as a 'sf'
#' ('TRUE', the default) object or as a data.frame.
#' @param return.sf logical. Should the profile points be returned as a `sf`
#' object (`TRUE`, the default) object or as a data.frame.
#'
#' @note
#' Use metric values (meters, kilometers, etc) in case of a projected coordinate reference frame, and degree
Expand Down Expand Up @@ -126,9 +126,11 @@ profile_length <- function(x, ...) {


#' @title Distance Between Points
#' @description This uses the **haversine** formula (by default) to calculate the great-circle
#' distance between two points, i.e., the shortest distance over the earth<U+2019>s
#' surface.
#'
#' @description 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.
#'
#' @param a lon, lat coordinate of point 1
#' @param b lon, lat coordinate of point 2
#' @param ... parameters passed to [tectonicr::dist_greatcircle()]
Expand Down
12 changes: 5 additions & 7 deletions R/swath.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,12 @@
#' @author V. Haburaj
#'
#' @export
swathR <- function(coords, raster, k, dist, crs, method) {
message("Initializing ...")
# set default method:
if (missing(method)) {
method <- "bilinear"
}
swathR <- function(coords, raster, k, dist, crs, method = 'bilinear') {
#message("Initializing ...")

# create SpatialPoints from coords:
spt <- SpatialPoints(coords, proj4string = CRS(crs))

# get slope of baseline:
m <- (ymin(spt[1]) - ymin(spt[2])) / (xmin(spt[1]) - xmin(spt[2]))
# get slope of normal function:
Expand Down Expand Up @@ -134,7 +132,7 @@ swathR <- function(coords, raster, k, dist, crs, method) {
#' @importFrom dplyr c_across rowwise ungroup mutate tibble as_tibble
#' @export
swath_profile <- function(x) {
elevs <- c()
elevs <- numeric()
center <- as.character(median(seq_along(x$data)))
for (i in seq_along(x$data)) {
elevs <- cbind(elevs, x$data[[i]])
Expand Down
23 changes: 13 additions & 10 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@ knitr::opts_chunk$set(
# geoprofiler

<!-- badges: start -->

[![R-CMD-check](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml)

<!-- badges: end -->

The goal of geoprofiler is to get distances along and across user-defined
profile lines or transects. This is useful when variables depend on distances.
The goal of geoprofiler is to get distances along and across user-defined profile lines or transects. This is useful when variables depend on distances.

![Concept](man/figures/fig.png)

## Installation

Expand All @@ -41,12 +44,14 @@ library(ggplot2)
```

Import example data and transfer them into a `sf` object:

```{r quakes}
data(quakes)
quakes_sf <- sf::st_as_sf(quakes, coords = c("long", "lat"), crs = "WGS84")
```

Create a profile line from two known points:

```{r profile}
profile <- data.frame(lon = c(160, -170), lat = c(-15, -30)) |>
sf::st_as_sf(coords = c("lon", "lat"), crs = "WGS84") |>
Expand All @@ -57,12 +62,14 @@ profile <- data.frame(lon = c(160, -170), lat = c(-15, -30)) |>
> Note: You can also create a profile line by a direction via `profile_points()`
Calculate the distances of all points along and across the profile line:

```{r cooridnates}
quakes_profile <- profile_coords(quakes_sf, profile = profile) |>
dplyr::bind_cols(quakes_sf)
```

Finally, create your profile plot:

```{r plot}
ggplot(quakes_profile, aes(X, depth, color = mag, size = abs(Y), alpha = abs(Y))) +
geom_point() +
Expand All @@ -77,20 +84,16 @@ ggplot(quakes_profile, aes(X, depth, color = mag, size = abs(Y), alpha = abs(Y))

## Documentation

The detailed documentation can be found at
https://tobiste.github.io/geoprofiler/articles/geoprofiler.html

The detailed documentation can be found at <https://tobiste.github.io/geoprofiler/articles/geoprofiler.html>

## Author

Tobias Stephan (<[email protected]>)
Tobias Stephan ([tstephan\@lakeheadu.ca](mailto:[email protected]){.email})

## Feedback, issues, and contributions

I welcome feedback, suggestions, issues, and contributions! If you have
found a bug, please file it
[here](https://github.com/tobiste/geoprofiler/issues) with minimal code to
reproduce the issue.
I welcome feedback, suggestions, issues, and contributions! If you have found a bug, please file it [here](https://github.com/tobiste/geoprofiler/issues) with minimal code to reproduce the issue.

## License

MIT License
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
<!-- badges: start -->

[![R-CMD-check](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/tobiste/geoprofiler/actions/workflows/R-CMD-check.yaml)

<!-- badges: end -->

The goal of geoprofiler is to get distances along and across
user-defined profile lines or transects. This is useful when variables
depend on distances.

<figure>
<img src="man/figures/fig.png" alt="Concept" />
<figcaption aria-hidden="true">Concept</figcaption>
</figure>

## Installation

You can install the development version of geoprofiler from
Expand Down
Loading

0 comments on commit e4f71e7

Please sign in to comment.