Skip to content

Commit

Permalink
Created new function dms2decdegrees.R to convert degrees, minutes and…
Browse files Browse the repository at this point in the history
… seconds to decimal degrees
  • Loading branch information
dgamez71 committed Mar 17, 2018
1 parent 4bd2bb8 commit 1ad3ab3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(aemet_stations)
export(dms2decdegrees)
export(get_aemet_normalized)
export(get_data)
import(httr)
Expand Down
17 changes: 6 additions & 11 deletions R/aemet_stations.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,17 @@
#' }
aemet_stations <- function(apikey) {

test <- get_data(apidest = "/api/valores/climatologicos/inventarioestaciones/todasestaciones", apikey)
stations <- get_data(apidest = "/api/valores/climatologicos/inventarioestaciones/todasestaciones", apikey)

stations$longitud <- Vectorize(dms2decdegrees)(stations$longitud)


df <- data.frame(t(sapply(listQ1, function(e) e)))
station_id <- df[, "indicativo"]
longString <- as.character(df[, "longitud"])
latString <- as.character(df[, "latitud"])


deg <- as.numeric(substr(longString, 0, 2))
min <- as.numeric(substr(longString, 3,4))
sec <- as.numeric(substr(longString, 5,6))
x <- deg + min/60 + sec/3600
x <- ifelse(substr(longString, 7, 8) == "W", x, -x)
deg <- as.numeric(substr(latString, 0, 2))
min <- as.numeric(substr(latString, 3,4))
sec <- as.numeric(substr(latString, 5,6))
y <- deg + min/60 + sec/3600
x <-
points <- SpatialPoints(coords = cbind(-x, y), CRS("+proj=longlat"))
colnames(points@coords) <- c("longitude", "latitude")
dfout <- data.frame(station_id = df[, "indicativo"],
Expand Down
18 changes: 18 additions & 0 deletions R/dms2decdegrees.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#' Converts degrees, minutes and seconds to decimal degrees
#'
#' @param input character
#'
#' @return num
#' @export
#'
#' @examples
#' dms2decdegrees("055245W")
#'
dms2decdegrees <- function(input) {
deg <- as.numeric(substr(input, 0, 2))
min <- as.numeric(substr(input, 3,4))
sec <- as.numeric(substr(input, 5,6))
x <- deg + min/60 + sec/3600
x <- ifelse(substr(input, 7, 8) == "W", -x, x)
x
}
21 changes: 21 additions & 0 deletions man/dms2decdegrees.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1ad3ab3

Please sign in to comment.