HARPgroup / HARParchive

This repo houses HARP code development items, resources, and intermediate work products.
1 stars 0 forks source link

Develop method to retrieve small sub-watersheds that are custom in VAHydro in order to add FTABLEs for them. #547

Open rburghol opened 1 year ago

rburghol commented 1 year ago

Create batch script to create all subshed ftables :

jdkleiner commented 1 year ago

@megpritch See example method below for retrieving all rsegs (next step is to filter those down to just the sub-watersheds)

library("hydrotools")
basepath='/var/www/R';
source("/var/www/R/config.R")

##################################################################
# retrieve rsegs
##################################################################
# set up our data source environment
ds <- RomDataSource$new(site, rest_uname = rest_uname)
ds$get_token(rest_pw)

# retrieve all vahydro rseg features (this method is optimal b/c it allows retrieval of >100 records)
rsegs <- RomFeature$new(ds,list(ftype='vahydro',bundle='watershed'),TRUE)

# generate dataframe of rseg hydrocodes
rsegs_hydrocode_df <- data.frame("hydrocode"=character(),stringsAsFactors=FALSE)
for (i in 1:length(rsegs$hydrocode)){
  rsegs_hydrocode_df <- rbind(rsegs_hydrocode_df,rsegs$hydrocode[i])
}
print(head(rsegs_hydrocode_df))
##################################################################

##################################################################
# Next, use sqldf to query the sub-watersheds within the dataframe
# of hydrocodes (those with hydrocode greater than 29 characters)
##################################################################

# sqldf() here 

##################################################################
megpritch commented 1 year ago

Revised:

rsegs <- RomFeature$new(ds,list(ftype='vahydro',bundle='watershed'),TRUE)
  subshed<- subset(rsegs$hydrocode, nchar(rsegs$hydrocode)>29)
  subshed <- data.frame(subshed)