@@ -233,23 +233,27 @@ RomFeature <- R6Class(
233233 # ' meteorology varkeys include 'prism_mod_daily', 'daymet_mod_daily',
234234 # ' 'nldas2_obs_hourly', 'nldas2_precip_hourly_tiled_16x16',
235235 # ' 'nldas2_precip_daily', 'amalgamate_simple_lm', 'amalgamate_storm_vol'
236- # ' @param starttime begin tstime to limit query (default FALSE to remove a
236+ # ' @param starttime begin date-time to limit query (default FALSE to remove a
237237 # ' tstime filter)
238- # ' @param endtime last tsendtime to limit query (default FALSE to remove a
239- # ' tsendtime filter)
238+ # ' @param endtime last date-time to limit query (default to Sys.Date())
240239 # ' @param band which raster band to query (default = 1)?
241240 # ' @param aggregate Should data be aggregated and if so, how? FALSE will
242241 # ' return 1 record for every date. Otheriwse, can use basic aggregate
243242 # ' functions like mean, min, max to summarize data
244243 # ' @param metric default mean, which aspect of the ST_SummaryStats() to return
244+ # ' @param touched Defaults to FALSE. Should PostGIS ST_Clip() use the
245+ # ' touched argument to return all raster cells touched by the feature? Or,
246+ # ' if FALSE, should only pixels that have centroids within the feature be
247+ # ' considered?
245248 # ' @return dataframe of timeseries values
246249 get_raster_ts = function (
247250 varkey = ' prism_mod_daily' ,
248251 starttime = FALSE ,
249252 endtime = Sys.Date(),
250253 band = ' 1' ,
251254 aggregate = FALSE ,
252- metric = ' mean'
255+ metric = ' mean' ,
256+ touched = FALSE
253257 ) {
254258 # looks at the table dh_timeseries_weather
255259 # coverage raster summary
@@ -269,14 +273,21 @@ RomFeature <- R6Class(
269273 }
270274 # If the user wishes to apply an aggregate function, group the data by the
271275 # featureid and apply the aggregate and metric arguments. Otherwise, just
272- # get the metric from st_summarystats
276+ # get the metric from st_summarystats. The data will be clipped to the
277+ # feature and the user can choose to apply the touched argument from
278+ # postGIS st_Clip
279+ if (touched ){
280+ clipSQL <- paste0(" st_clip(met.rast, fgeo.dh_geofield_geom,touched => true)" )
281+ }else {
282+ clipSQL <- paste0(" st_clip(met.rast, fgeo.dh_geofield_geom,touched => false)" )
283+ }
273284 if (! is.logical(aggregate )) {
274- rastercalc = fn $ paste0(" $aggregate((ST_summarystats(st_clip(met.rast, fgeo.dh_geofield_geom) , 1, TRUE)).$metric)" )
285+ rastercalc = fn $ paste0(" $aggregate((ST_summarystats($clipSQL , 1, TRUE)).$metric)" )
275286 groupby = " GROUP BY met.featureid"
276287 startcol = " to_timestamp(min(met.tsendtime))"
277288 endcol = " to_timestamp(max(met.tsendtime))"
278289 } else {
279- rastercalc = fn $ paste0(" (ST_summarystats(st_clip(met.rast, fgeo.dh_geofield_geom) , 1, TRUE)).$metric" )
290+ rastercalc = fn $ paste0(" (ST_summarystats($clipSQL , 1, TRUE)).$metric" )
280291 groupby = " "
281292 startcol = " to_timestamp(met.tsendtime)"
282293 endcol = " to_timestamp(met.tsendtime)"
0 commit comments