Skip to content

Commit

Permalink
Merge pull request #21 from rubenfcasal/ria_coord
Browse files Browse the repository at this point in the history
Fix bug in RIA coordinates (#20)
  • Loading branch information
MalditoBarbudo authored Dec 18, 2023
2 parents e93dab4 + 53051a8 commit 77a92e8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: meteospain
Title: Access to Spanish Meteorological Stations Services
Version: 0.1.3
Version: 0.1.4
Authors@R:
c(
person(given = "Victor",
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# meteospain 0.1.4

* Fixed bug in RIA coordinates (#20)

# meteospain 0.1.3

* meteocat API: new data limits, now daily data can be retrieved starting on 1989
Expand Down
12 changes: 2 additions & 10 deletions R/ria_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,16 +191,8 @@
dplyr::mutate(
station_id = as.character(glue::glue("{province_id}-{station_id}")),
altitude = units::set_units(.data$altitude, 'm'),
latitud = dplyr::if_else(
stringr::str_detect(.data$latitud, 'S'),
-as.numeric(stringr::str_remove_all(.data$latitud, '[A-Za-z]'))/1e7,
as.numeric(stringr::str_remove_all(.data$latitud, '[A-Za-z]'))/1e7
),
longitud = dplyr::if_else(
stringr::str_detect(.data$longitud, 'W'),
-as.numeric(stringr::str_remove_all(.data$longitud, '[A-Za-z]'))/1e7,
as.numeric(stringr::str_remove_all(.data$longitud, '[A-Za-z]'))/1e7
)
latitud = .parse_coords_dmsh(latitud),
longitud = .parse_coords_dmsh(longitud),
) |>
sf::st_as_sf(coords = c('longitud', 'latitud'), crs = 4326)

Expand Down
11 changes: 11 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,17 @@ relocate_vars <- function(data) {
)
}


.parse_coords_dmsh <- function(coord){

# converts from "DDMMSSsssH" DMS format to numeric DD
dmsh <- stringr::str_sub_all(coord,
cbind(start = c(1, 3, 5, 10), length = c(2, 2, 5, 1)))
sapply(dmsh, function(x) (as.numeric(x[1]) + as.numeric(x[2])/60 +
as.numeric(x[3])/3600000) * if (grepl(x[4],"W|S")) -1 else 1)
}


unnest_safe <- function(x, ...) {

# if x is a list instead of a dataframe, something went wrong (happens sometimes in
Expand Down

0 comments on commit 77a92e8

Please sign in to comment.