Skip to content

Commit

Permalink
fix fuzzy search
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchobben committed Oct 11, 2023
1 parent 3e7938c commit ed1f216
Show file tree
Hide file tree
Showing 20 changed files with 1,014 additions and 1,389 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@
^tests/testthat/apps$
^Dockerfile$
^test_debian.sh$
^dev$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ docs
rsconnect
test_debian.sh
Dockerfile
# development
dev
4 changes: 1 addition & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ Suggests:
cffr,
covr,
curl,
devtools (>= 2.4.3),
diffviewer (>= 0.1.1),
globals (>= 0.14.0),
knitr,
rmarkdown,
Expand Down Expand Up @@ -63,7 +61,7 @@ Imports:
maps (>= 3.4.0),
ncmeta (>= 0.3.0),
RNetCDF (>= 2.6.1),
dplyr (>= 1.0.9)
dplyr
Config/testthat/edition: 3
VignetteBuilder: knitr
Depends:
Expand Down
21 changes: 9 additions & 12 deletions R/filter_NOAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,10 @@ extract_coords <- function(plane, coords, depth, epsg, fuzzy = 0, bilinear = is.

# add coordinates in case of matrix
if (inherits(coords , "matrix")) {

tb <- sf::st_as_sf(cbind(tb, coords), coords = c("lon", "lat"), crs = epsg)

# change coordinate system of sfc class if needed
} else if (inherits(coords, c("sf", "sfc")) & sf::st_crs(tb) != epsg) {

tb <- sf::st_transform(tb, epsg)

}

if (any(is.na(tb[[1]])) & fuzzy > 0) {
Expand All @@ -199,18 +195,19 @@ extract_coords <- function(plane, coords, depth, epsg, fuzzy = 0, bilinear = is.
bilinear = FALSE
)
)

tb_ft$id <- ft$id

# replace NAs
tb <- rbind(tb, sf::st_as_sf(tb_ft)) |>
dplyr::group_by(.data$id) |>
dplyr::summarise(
dplyr::across(-.data$geometry, .fns = ~mean(.x, na.rm = TRUE)),
.groups = "drop"
) |>
dplyr::mutate(geometry_search = .data$geometry, geometry = tb$geometry)
tb <- rbind(tb, sf::st_as_sf(tb_ft))
tb <- tb[!is.na(tb[[1]]),]
}

if (inherits(tb, "stars")) {
tb <- tb[names(tb) != "id"]
} else {
tb <- tb[, colnames(tb) != "id"]
}
dplyr::select(tb, -.data$id)
tb
}

17 changes: 13 additions & 4 deletions R/filter_module.R
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,19 @@ filter_server <- function(id, NOAA, external, ivars = c("depth", "lon", "lat"),
) {

req(NOAA)

# fuzzy search value
if (input$search == "point") {
fz = 0
} else if (input$search == "fuzzy") {
fz = 50
}
# execute
filter_NOAA(
NOAA(),
input2$depth,
list(lon = input2$lon, lat = input2$lat)
list(lon = input2$lon, lat = input2$lat),
fuzzy = fz
)
}
})
Expand Down Expand Up @@ -296,9 +304,10 @@ filter_server <- function(id, NOAA, external, ivars = c("depth", "lon", "lat"),
"and \"fuzzy\", where the former results in a very precise ",
"search, the latter option searches in an area with a ",
"circumference of 50 km around the selected coordinate ",
"point. The returned value of a fuzzy search is therefore ",
"an average of the search area. Currently, fuzzy search is ",
"not yet implemented."),
"point. Fuzzy search is only applied for points that don't ",
"return a value for the normal point search. The returned ",
"value of a fuzzy search is therefore an average of the ",
"search area."),
)
)
)
Expand Down
6 changes: 3 additions & 3 deletions R/plot_NOAA.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ plot_NOAA <- function(NOAA, depth = 0, points = NULL, epsg = NULL, rng = NULL) {
stars::geom_stars(data = NOAA) +
ggplot2::geom_sf(data = wmap, fill = "grey")

if (!is.null(points)) {
if (!is.null(points) && nrow(points) != 0) {
base <- base +
ggplot2::geom_sf(data = points)
ggplot2::geom_sf(data = points, fill = "black", linewidth = 2)
}

if (epsg == 3031 | epsg == 3995 | epsg == sf::st_crs(3031) |
Expand All @@ -109,7 +109,7 @@ plot_NOAA <- function(NOAA, depth = 0, points = NULL, epsg = NULL, rng = NULL) {
panel.grid.major = ggplot2::element_line(
color = grDevices::gray(.25),
linetype = 'dashed',
size = 0.5
linewidth = 0.5
),
panel.ontop = TRUE,
axis.line = ggplot2::element_blank(),
Expand Down
13 changes: 11 additions & 2 deletions R/table_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ format_coord <- function(NOAA, coord) {

# split coords in long and lat
coords <- strsplit(sf::st_as_text(NOAA$geometry), "[^[:alnum:]|.|-]+")
coords <- do.call(Map, c(f = c, coords)) |>
stats::setNames(c("geometry", "longitude", "latitude"))
coords <- Map(coords_df, coords)
coords <- do.call(rbind, coords)

# remove old geometry
NOAA <- as.data.frame(NOAA)
Expand All @@ -30,3 +30,12 @@ format_coord <- function(NOAA, coord) {
# combine new
cbind(NOAA_sc, coords)
}

coords_df <- function(x) {
subset_x <- x[2:length(x)]
data.frame(
geometry = x[1],
longitude = I(list(subset(subset_x, seq_along(subset_x) %% 2 != 0))),
latitude = I(list(subset(subset_x, seq_along(subset_x) %% 2 == 0)))
)
}
111 changes: 0 additions & 111 deletions R/utils-tidy-eval.R

This file was deleted.

0 comments on commit ed1f216

Please sign in to comment.