Skip to content

Commit bf7f67b

Browse files
committed
CST-564 add preview_grid()
1 parent e2bbbcd commit bf7f67b

9 files changed

Lines changed: 89 additions & 17 deletions

File tree

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: SAVM
22
Title: Submerged aquatic vegetation model
3-
Version: 0.0.1.9002
4-
Date: 2025-07-14
3+
Version: 0.0.1.9003
4+
Date: 2025-07-15
55
Authors@R: c(
66
person(given = "Kevin",
77
family = "Cazelles",

NAMESPACE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# Generated by roxygen2: do not edit by hand
22

3+
S3method(preview_grid,sav_data)
34
export(compute_fetch)
45
export(invert_polygon)
56
export(plot_sav_density)
67
export(plot_sav_distribution)
78
export(plot_sav_tmap)
9+
export(preview_grid)
810
export(read_sav)
911
export(read_sav_aoi)
1012
export(read_sav_csv)

NEWS.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SAVM (devel)
22

3+
* `preview_grid()` allows to preview grid (see #8).
34
* Add more guidance on reading shapefiles in the vignette (see #6).
45
* `invert_polygon()` has been added to invert polygon (see #6).
56
* `compute_fetch()` has a new argument `n_bearings` that provides the number of bearings, it replaces `n_quad_seg` (see #4 and #5).
6-
* `compute_fetch()` only compute the mean fetch for all bearings (see #4).
7+
* `compute_fetch()` only compute the mean fetch for all bearings (see #4).

R/data_input.R

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
#' Read SAV data from different formats
22
#'
33
#' @param file_path {`character`}\cr{} Path to the input file.
4-
#' @param spacing {`numeric`}\cr{} Spacing for grid generation (if AOI is used).
4+
#' @param spacing {`numeric`}\cr{}
5+
#' Spacing for grid generation. Used if an area of interest (AOI) is provided,
6+
#' ignored otherwise.
57
#' @param layer {`character`}\cr{} Layer name for multi-layer spatial files (default: NULL).
6-
#' @param crs {`numeric`}\cr{} Coordinate Reference System (CRS) of the output data. Default is 32617.
7-
#' @param crs_input {`numeric`}\cr{} Coordinate Reference System (CRS) of the input data, used for CSV import. Default is 4326.
8-
#' @param export {`character`}\cr{} Optional. Folder path to export outputs as .gpkg.
8+
#' @param crs {`numeric`}\cr{}
9+
#' Coordinate Reference System (CRS) of the output data. Default is 32617.
10+
#' @param crs_input {`numeric`}\cr{}
11+
#' Coordinate Reference System (CRS) of the input data, used for CSV import.
12+
#' Default is 4326.
13+
#' @param export {`character`}\cr{}
14+
#' Optional. Folder path to export outputs as .gpkg.
915
#'
1016
#' @return A list with `points` (sf object) and `polygon` (sf object).
1117
#'
@@ -52,12 +58,15 @@ read_sav <- function(file_path, spacing = 500, layer = NULL, crs = 32617, crs_in
5258
file_ext <- tools::file_ext(file_path)
5359

5460
if (file_ext == "csv") {
61+
sav_msg_info("csv detected")
5562
points_sf <- read_sav_csv(file_path, crs = crs)
5663
polygon_sf <- sf::st_sf(geometry = sf::st_union(points_sf) |> sf::st_convex_hull())
5764
} else if (file_ext %in% c("shp", "geojson", "gpkg", "gbd")) {
5865
if (file_ext == "gbd") {
66+
sav_msg_info("gdb detected")
5967
sf_obj <- sf::st_read(file_path, layer = layer, quiet = TRUE)
6068
} else {
69+
sav_msg_info("spatial file detected")
6170
sf_obj <- sf::st_read(file_path, quiet = TRUE)
6271
}
6372

@@ -83,7 +92,12 @@ read_sav <- function(file_path, spacing = 500, layer = NULL, crs = 32617, crs_in
8392
sav_msg_success("Exported outputs to {export}.")
8493
}
8594

86-
return(list(points = points_sf, polygon = polygon_sf))
95+
return(
96+
structure(
97+
list(points = points_sf, polygon = polygon_sf),
98+
class = "sav_data"
99+
)
100+
)
87101
}
88102

89103

R/preview_grid.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#' Preview grid
2+
#'
3+
#' @param x an object of class `sav_data`.
4+
#'
5+
#' @export
6+
#'
7+
preview_grid <- function(x) {
8+
UseMethod("preview_grid")
9+
}
10+
11+
#' @describeIn preview_grid Preview spatail grid.
12+
#'
13+
#' @export
14+
#'
15+
preview_grid.sav_data <- function(x) {
16+
plot(x$polygon |> sf::st_geometry(), border = 1)
17+
plot(x$points |> sf::st_geometry(), col = "grey50", pch = 19, add = TRUE)
18+
}

man/data_input.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/plot_sav.Rd

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/preview_grid.Rd

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/get_started.Rmd

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ erie_lake |>
8080
plot(col = 1)
8181
```
8282

83-
The file can then be exported in various format, for instance in [GeoPackage](https://www.geopackage.org/):
83+
Using `sf` capacities, the file can then be exported in various format, for instance in [GeoPackage](https://www.geopackage.org/):
8484

8585
```R
8686
erie_lake |> sf::st_write(erie_lake, "lake_erie.gpkg")
@@ -91,22 +91,35 @@ we will use the package [`stars`](https://r-spatial.github.io/stars/) that works
9191

9292

9393

94-
9594
## Reading file
9695

9796
Now we consider a zone near Buffalo in the Lake Erie. Note that all
98-
the data required data are included on in the package SAVM.
97+
the data required are included on in the package SAVM. We first load the geopackage of Lake Erie.
9998

100-
```{r reading}
99+
```{r reading1}
101100
# Lake Erie boundaries polygon (reading from SAVM internal files)
102101
le_bound <- system.file("example", "lake_erie.gpkg", package = "SAVM") |>
103102
sf::st_read() |>
104103
sf::st_transform(crs = 3857)
104+
```
105105

106+
We then load the shapefile of the area of interest that is stored as a GeoJSON file. Note that for the area (or points) of interest, we use `read_sav()` that returns an object of class `sav_data`.
107+
108+
```{r reading2}
106109
# Lake Erie study zone: read
107110
study_zone <- system.file("example", "study_zone.geojson", package = "SAVM") |>
108111
read_sav(spacing = 2000)
112+
```
113+
114+
Note that the corresponfing grid can be visualized using the `preview_grid()` function.
115+
116+
```{r preview_grid}
117+
preview_grid(study_zone)
118+
```
119+
120+
We now load the depth data.
109121

122+
```{r reading3}
110123
# Depth (reading with stars)
111124
study_depth <- stars::read_stars(system.file("example", "le_bathy.tiff", package = "SAVM"))
112125
```
@@ -118,7 +131,7 @@ study_depth <- stars::read_stars(system.file("example", "le_bathy.tiff", package
118131

119132
### Compute fetch
120133

121-
To compute wind fetch (in kilometers, we called `compute_fetch()`), by default, the maximum distance is set to 15 km (see argument `max_dist`) and the default number of radial transect by quadrant is 9 (see argument `n_quad_seg`).
134+
To compute wind fetch (in kilometers), we called `compute_fetch()`. By default, the maximum distance is set to 15 km (see argument `max_dist`) and the default number of bearings is 16 (see argument `n_bearings`).
122135

123136
```{r fetch}
124137
fetch <- compute_fetch(study_zone$points, le_bound)

0 commit comments

Comments
 (0)