Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: powstreams
Type: Package
Title: powstreams
Version: 0.3.0
Version: 0.4.0
Date: 2014-12-08
Author: Jordan S Read, Luke A Winslow
Maintainer: Jordan S Read <jread@usgs.gov>
Expand All @@ -18,7 +18,8 @@ Imports:
mda.streams,
sbtools,
dplyr,
httr
httr,
dataRetrieval
Suggests:
testthat
LazyLoad: yes
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export(download_watershed)
export(list_sites)
export(list_timeseries)
export(load_timeseries)
export(site_location)
import(dataRetrieval)
import(dplyr)
import(httr)
import(mda.streams)
Expand Down
17 changes: 6 additions & 11 deletions R/list_sites.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,15 @@
list_sites <- function(with_timeseries = NULL, session = NULL){

if(is.null(with_timeseries)){
sites <- get_sites(session)

sites <- get_sites(session = session)

} else {
types <- mda.streams:::make_ts_variable(variable = with_timeseries) # can be multiple? not yet
ids <- data.frame()
types <- make_ts_variable(variable = with_timeseries)
sites <- vector('character')
for (k in 1:length(types)){
ids <- rbind(ids, query_item_identifier(scheme = "mda_streams", type = types[k], session = session, limit = 10000))
sites <- append(sites, get_sites(with_child_key = types[k], session = session))
}

sites <- vector(mode = 'character', length = nrow(ids))
for (i in 1:nrow(ids)){
site_id <- item_get_parent(ids[i, 2], session = session)
sites[i] <- mda.streams:::get_title(site_id, session)
}

# get sites that are repeated as many times as the number of types used
tbl_sites <- data.frame(table(sites))
sites <- as.character(tbl_sites$sites[tbl_sites$Freq == length(types)])
Expand Down
23 changes: 23 additions & 0 deletions R/site_location.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#'@title get site latitude and longitude
#'@param site a valid powstreams site (see \code{\link{list_sites}})
#'
#'@import mda.streams
#'@import dataRetrieval
#'@examples
#'site_location("nwis_11126000")
#'\dontrun{
#'site_location(list_sites(with_timeseries = c('doobs', 'wtr')))
#'}
#'@export
site_location <- function(site){
nwis_site <- split_site(site)
site_data <- readNWISsite(nwis_site)
lat <- site_data$dec_lat_va
lon <- site_data$dec_long_va
location <- data.frame('longitude' = lon, 'latitude' = lat)

if (length(site) > 1){
location <- cbind(data.frame('site' = site_data$site_no), location)
}
return(location)
}
21 changes: 21 additions & 0 deletions man/site_location.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
% Generated by roxygen2 (4.1.0): do not edit by hand
% Please edit documentation in R/site_location.R
\name{site_location}
\alias{site_location}
\title{get site latitude and longitude}
\usage{
site_location(site)
}
\arguments{
\item{site}{a valid powstreams site (see \code{\link{list_sites}})}
}
\description{
get site latitude and longitude
}
\examples{
site_location("nwis_11126000")
\dontrun{
site_location(list_sites(with_timeseries = c('doobs', 'wtr')))
}
}

4 changes: 4 additions & 0 deletions tests/testthat/test-sites.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ test_that("listing variables from site fails", {
expect_is(load_timeseries(site = "nwis_01408500", variable = 'doobs'), 'data.frame')
expect_is(load_timeseries(site = 'nwis_01408500', variable = c('doobs','wtr')), 'data.frame')

expect_is(site_location("nwis_11126000"), 'data.frame')
expect_is(site_location("11126000"), 'data.frame')
expect_is(site_location(c("11126000", "09258980")), 'data.frame')

})