Skip to content

Commit

Permalink
version 0.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
stanyip authored and gaborcsardi committed Aug 26, 2015
1 parent 4d66b78 commit 0f84970
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 17 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,14 +1,14 @@
Package: weatherr
Type: Package
Title: Tools for Handling and Scrapping Instant Weather Forecast Feeds
Version: 0.1
Date: 2015-07-15
Version: 0.1.1
Date: 2015-08-25
Author: Stan Yip [aut, cre]
Maintainer: Stan Yip <stanyip101@gmail.com>
Description: Handle instant weather forecasts and geographical information. It combines multiple sources of information to obtain instant weather forecasts.
Depends: ggmap, lubridate, RJSONIO, XML
License: GPL (>= 2)
Packaged: 2015-07-16 02:55:23 UTC; STANLEYCYYIP
Packaged: 2015-08-26 04:28:32 UTC; STANLEYCYYIP
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2015-07-16 14:24:43
Date/Publication: 2015-08-26 08:50:30
11 changes: 6 additions & 5 deletions MD5
@@ -1,6 +1,7 @@
eaaae8a803e025ee222cd78d752466d3 *DESCRIPTION
3b4870f0f6e59c248e34cc8655bfbfc1 *INDEX
8e51f304e59de7643629189d2509e471 *DESCRIPTION
584eb9909df0fae17be59fec04e8c06f *NAMESPACE
b9bede9f12d8de4ccb9560d1195754c4 *R/locationforecast.R
4c516856a860e022f50229a44359d92a *man/locationforecast.Rd
8ec76daa34f08f980eba8e4f4baa7469 *man/weatherr-package.Rd
0c7365448d96c16380cac482c07e706c *R/ggele.R
180254083c663baef7ee26351fef203d *R/locationforecast.R
c4578404743d1f1f76f841af174fa295 *man/ggele.Rd
ef8c153667e7c906de2502441e7da569 *man/locationforecast.Rd
2310e4a3f02068957d51cc7b69b0e0b0 *man/weatherr-package.Rd
11 changes: 11 additions & 0 deletions R/ggele.R
@@ -0,0 +1,11 @@
ggele = function(lat=0,lon=0, output=c('elevation','elevation/resolution','all')) {
output <- match.arg(output)
if ((length(lat) != length(lon)) | (any(abs(lat)>90)) | (any(abs(lon)>180))) stop('Longitude and latitude should have equal length and within the valid range')
inpar = paste(paste0(lat,', ', lon),collapse = ' | ')
url = paste0("http://maps.googleapis.com/maps/api/elevation/json?locations=", inpar)
u = paste0(paste0(readLines(url), collapse = "\n"), "\n")
tmp = try(RJSONIO::fromJSON(u))
if (class(tmp) == 'try-error') stop('Error: fail to obtain data from Google Elevation API')
if (tmp$status != 'OK') stop('Request denied')
switch(output, 'elevation' = {y=sapply(tmp$results,function(x) x$elevation);names(y)=1:length(tmp$results);y}, 'elevation/resolution' = {y=sapply(tmp$results,function(x) c(x$elevation,x$resolution));y=as.data.frame(y);colnames(y)=1:length(tmp$results);rownames(y) = c('elevation','resolution');y}, all = tmp)
}
7 changes: 3 additions & 4 deletions R/locationforecast.R
@@ -1,7 +1,6 @@
locationforecast <-
function(lat,lon,elevation=NULL,location=NULL,exact=TRUE,tz=Sys.timezone()) {
locationforecast <- function(lat,lon,elevation=NULL,location=NULL,exact=TRUE,tz=Sys.timezone()) {
if (!is.null(location)) {
latlon = as.numeric(rev(geocode(location)))
latlon = as.numeric(rev(geocode(location=location,source = "google")))
if (any(is.null(latlon))) stop('Error: no match location')
lat = latlon[1]; lon = latlon[2]
elevation = fromJSON(paste0('http://maps.googleapis.com/maps/api/elevation/json?locations=',lat,',',lon,'&sensor=false'))$results[[1]]$elevation
Expand Down Expand Up @@ -44,6 +43,6 @@ precipitation = as.numeric(sapply(1:length(temp),function(x) {x1 = temp[[x]]$pre
minTemperature = as.numeric(sapply(1:length(temp),function(x) {x1 = temp[[x]]$minTemperature['value']; ifelse(!is.null(x1),x1,NA)}))
maxTemperature = as.numeric(sapply(1:length(temp),function(x) {x1 = temp[[x]]$maxTemperature['value']; ifelse(!is.null(x1),x1,NA)}))
weather_id = sapply(1:length(temp),function(x) {x1 = temp[[x]]$symbol['id']; ifelse(!is.null(x1),x1,NA)})
data.frame(timefrom=timefrom[v], timeto=timeto[v], interval = tdiff[v], precipitation=precipitation, minTemperature=minTemperature, maxTemperature=maxTemperature, weather_id=weather_id)
data.frame(timefrom=timefrom[v], timeto=timeto[v], interval = tdiff[v], precipitation=precipitation, minTemperature=minTemperature, maxTemperature=maxTemperature, weather_id=weather_id, stringsAsFactors=F)
}
}
27 changes: 27 additions & 0 deletions man/ggele.Rd
@@ -0,0 +1,27 @@
\name{ggele}
\alias{ggele}

\title{Elevation of a set of specific locations}

\description{Obtaining elevation at a set of given locations. Note that using this function you are agreeing to the Google Maps API Terms of Service at https://developers.google.com/maps/terms.
}

\usage{ggele(lat=0,lon=0, output=c('elevation','elevation/resolution','all'))}
\arguments{
\item{lat, lon}{numeric objects. latitude and longitude of a location in decimal degrees}

\item{output}{elevation; elevation and its corresponding resolution or the original JSON output (in a list format)}

}
\value{
\item{}{If output="elevation", a numeric vector is returned with the elevation in metres.}
\item{}{If output="elevation/resolution", a data frame is return with the elevation and its corresponding resolution in metres.}
\item{}{If output="all", a list is returned with full JSON query output.}
}

\author{Stan Yip}

\examples{
# Get the elevation of a location in Hong Kong
ggele(lat=22.39643,lon=114.1095)
}
4 changes: 2 additions & 2 deletions man/locationforecast.Rd
Expand Up @@ -55,9 +55,9 @@ If exact=FALSE, A data frame is returned with the following quantities:

\examples{
# Get exact time location forecast of Hong Kong
locationforecast(lon=114.1095,lat=22.39643)
locationforecast(lat=22.39643,lon=114.1095)
# Get time interval location forecast of Malta
locationforecast(lon=14.37542,lat=35.9375, exact=FALSE)
locationforecast(lat=35.9375,lon=14.37542,exact=FALSE)
# Get exact time location forecast of Cape Town, South Africa with timezone 'Africa/Johannesburg'
locationforecast(location='Cape Town, South Africa', tz='Africa/Johannesburg')
}
4 changes: 2 additions & 2 deletions man/weatherr-package.Rd
Expand Up @@ -8,8 +8,8 @@
\tabular{ll}{
Package: \tab weatherr\cr
Type: \tab Package\cr
Version: \tab 0.1\cr
Date: \tab 2015-07-15\cr
Version: \tab 0.1.1\cr
Date: \tab 2015-08-25\cr
License: \tab GPL (>=2)\cr
}
}
Expand Down

0 comments on commit 0f84970

Please sign in to comment.