Description Usage Arguments Details Value Note Author(s) References See Also Examples
This function looks on Wunderground to see if there are any PWS at a given lat/lon.
1 | getStations(lldf, radius = 10, numofStatLimit = 150)
|
lldf |
A data frame of locations specified in lat/lon |
radius |
A distance / radius specified in miles |
numofStatLimit |
A cap on the number of stations |
This function is not meant to be called directly by users
A list of PWS stations
None
Steve Pittard <wsp@emory.edu>
STATS290 Website
None
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | ## The function is currently defined as
function (lldf, radius = 10, numofStatLimit = 150)
{
library(XML)
library(RCurl)
library(svMisc)
dflength = length(lldf)
if (dflength == 0) {
stop("Hey. You passed an empty data frame. Unable to generate a list of stations !")
}
rlist = list()
wunderString = "http://api.wunderground.com/auto/wui/geo/GeoLookupXML/index.xml?query="
nrowdf = nrow(lldf)
pStr = paste("Now checking Wunderground to find stations")
print(pStr)
for (ii in 1:nrowdf) {
progress(ii, nrowdf - 1)
lat = lldf[ii, c("geo_latitude")]
lon = lldf[ii, c("geo_longitude")]
coords = paste(lat, lon, sep = ",")
urlstr = paste(wunderString, coords, sep = "")
if (ii == (nrowdf - 1))
cat("Done!\n")
if (radius < 10) {
halfradius = 3
}
else {
halfradius = radius/6
}
qstring = paste("//location/nearby_weather_stations/pws/station[distance_mi<",
halfradius, "]/ancestor-or-self::station/id", sep = "")
txt2parse = getURL(urlstr)
hold = xmlTreeParse(txt2parse, useInternalNodes = TRUE)
stationsXml = getNodeSet(hold, qstring)
stations = sapply(stationsXml, xmlValue)
rlist[[ii]] = stations
}
finalStationList = unique(unlist(rlist))
if (length(finalStationList) == 0) {
stop("No stations found")
}
else {
if (length(finalStationList) > numofStatLimit) {
length(finalStationList) = numofStatLimit
}
pStr = paste("Found", length(finalStationList), "Personal Weather Stations within",
radius, "miles", sep = " ")
print(pStr)
return(finalStationList)
}
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.