Skip to content

Commit

Permalink
redesign aemet_stations function
Browse files Browse the repository at this point in the history
  • Loading branch information
Pakillo committed Mar 17, 2018
1 parent 1ad3ab3 commit a7abe77
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 26 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: aemet
Type: Package
Title: Obtain Climatic and Meteorological Data from Spanish Meteorological Agency (AEMET)
Version: 0.1.1
Version: 0.1.2
Date: 2018-03-17
Authors@R: c(person("Francisco", "Balao", role = "aut"),
person("Francisco", "Rodriguez-Sanchez", email = "[email protected]", role = c("aut", "cre")),
Expand Down
28 changes: 6 additions & 22 deletions R/aemet_stations.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,22 @@
#'
#' @param apikey String with the AEMET API key (see https://opendata.aemet.es/).
#'
#' @return A SpatialPointsDataFrame.
#' @return A data.frame
#' @export
#'
#' @import httr

#'
#' @examples \dontrun{
#' stations <- aemet_stations(apikey) #SpatialPointsDataFrame
#' stationdata <- as.data.frame(stations)
#' stations <- aemet_stations(apikey)
#' }
aemet_stations <- function(apikey) {

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

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

df <- stations[, c("indicativo", "indsinop", "nombre", "provincia", "altitud",
"longitud", "latitud")]

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

x <-
points <- SpatialPoints(coords = cbind(-x, y), CRS("+proj=longlat"))
colnames(points@coords) <- c("longitude", "latitude")
dfout <- data.frame(station_id = df[, "indicativo"],
station = df[, "nombre"],
province = df[, "provincia"],
elevation = as.numeric(df[, "altitud"]))

finaldf <- SpatialPointsDataFrame(points, dfout)

return(finaldf)
df

}
5 changes: 2 additions & 3 deletions man/aemet_stations.Rd

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

0 comments on commit a7abe77

Please sign in to comment.