2
2
# # the plugins
3
3
# ' @noRd
4
4
foo_gbif <- function (sources , query , limit , start , geometry , has_coords ,
5
- callopts , opts ) {
5
+ date , callopts , opts ) {
6
6
if (any(grepl(" gbif" , sources ))) {
7
7
8
8
opts $ hasCoordinate <- has_coords
@@ -24,6 +24,10 @@ foo_gbif <- function(sources, query, limit, start, geometry, has_coords,
24
24
} else {
25
25
query_use <- NULL
26
26
}
27
+ if (! is.null(date )) {
28
+ if (length(date ) != 2 ) stop(" 'date' for GBIF must be length 2" )
29
+ opts $ eventDate <- paste0(date , collapse = " ," )
30
+ }
27
31
28
32
if (is.null(query_use ) && is.null(geometry ) && length(opts ) == 0 ) {
29
33
warning(sprintf(" No records found in GBIF for %s" , query ), call. = FALSE )
@@ -88,7 +92,7 @@ foo_gbif <- function(sources, query, limit, start, geometry, has_coords,
88
92
89
93
# ' @noRd
90
94
foo_ecoengine <- function (sources , query , limit , page , geometry , has_coords ,
91
- callopts , opts ) {
95
+ date , callopts , opts ) {
92
96
if (any(grepl(" ecoengine" , sources ))) {
93
97
opts <- limit_alias(opts , " ecoengine" )
94
98
time <- now()
@@ -105,6 +109,11 @@ foo_ecoengine <- function(sources, query, limit, page, geometry, has_coords,
105
109
geometry
106
110
}
107
111
}
112
+ if (! is.null(date )) {
113
+ if (length(date ) != 2 ) stop(" 'date' for Ecoengine must be length 2" )
114
+ opts $ min_date <- date [1 ]
115
+ opts $ max_date <- date [2 ]
116
+ }
108
117
# This could hang things if request is super large. Will deal with this issue
109
118
# when it arises in a usecase
110
119
# For now default behavior is to retrive one page.
@@ -141,7 +150,7 @@ foo_ecoengine <- function(sources, query, limit, page, geometry, has_coords,
141
150
142
151
# ' @noRd
143
152
foo_antweb <- function (sources , query , limit , start , geometry , has_coords ,
144
- callopts , opts ) {
153
+ date , callopts , opts ) {
145
154
if (any(grepl(" antweb" , sources ))) {
146
155
time <- now()
147
156
opts $ georeferenced <- has_coords
@@ -158,8 +167,15 @@ foo_antweb <- function(sources, query, limit, start, geometry, has_coords,
158
167
opts $ scientific_name <- NULL
159
168
}
160
169
170
+ if (! is.null(date )) {
171
+ if (length(date ) != 2 ) stop(" 'date' for Ecoengine must be length 2" )
172
+ opts $ min_date <- date [1 ]
173
+ opts $ max_date <- date [2 ]
174
+ }
175
+
161
176
if (! ' limit' %in% names(opts )) opts $ limit <- limit
162
177
if (! ' offset' %in% names(opts )) opts $ offset <- start
178
+ if (length(callopts ) > 0 ) opts $ callopts <- callopts
163
179
out <- tryCatch(do.call(aw_data2 , opts ), error = function (e ) e )
164
180
165
181
if (is.null(out ) || inherits(out , " simpleError" )) {
@@ -181,7 +197,9 @@ foo_antweb <- function(sources, query, limit, start, geometry, has_coords,
181
197
}
182
198
183
199
# ' @noRd
184
- foo_bison <- function (sources , query , limit , start , geometry , callopts , opts ) {
200
+ foo_bison <- function (sources , query , limit , start , geometry , date ,
201
+ callopts , opts ) {
202
+
185
203
if (any(grepl(" bison" , sources ))) {
186
204
opts <- limit_alias(opts , " bison" , geometry )
187
205
if (class(query ) %in% c(" ids" ," tsn" )) {
@@ -190,10 +208,12 @@ foo_bison <- function(sources, query, limit, start, geometry, callopts, opts) {
190
208
} else {
191
209
opts $ TSNs <- query
192
210
}
211
+ if (! is.null(date )) opts $ eventDate <- date
193
212
bisonfxn <- " bison_solr"
194
213
} else {
195
214
if (is.null(geometry )) {
196
- opts $ scientificName <- query
215
+ opts $ ITISscientificName <- query
216
+ if (! is.null(date )) opts $ eventDate <- date
197
217
bisonfxn <- " bison_solr"
198
218
} else {
199
219
opts $ species <- query
@@ -250,7 +270,8 @@ foo_bison <- function(sources, query, limit, start, geometry, callopts, opts) {
250
270
251
271
# ' @noRd
252
272
foo_inat <- function (sources , query , limit , page , geometry , has_coords ,
253
- callopts , opts ) {
273
+ date , callopts , opts ) {
274
+
254
275
if (any(grepl(" inat" , sources ))) {
255
276
opts <- limit_alias(opts , " inat" )
256
277
opts $ geo <- has_coords
@@ -268,6 +289,11 @@ foo_inat <- function(sources, query, limit, page, geometry, has_coords,
268
289
c(geometry [2 ], geometry [1 ], geometry [4 ], geometry [3 ])
269
290
}
270
291
}
292
+ if (! is.null(date )) {
293
+ if (length(date ) != 2 ) stop(" 'date' for Inaturalist must be length 2" )
294
+ opts $ date_start <- date [1 ]
295
+ opts $ date_end <- date [2 ]
296
+ }
271
297
opts $ callopts <- callopts
272
298
out <- tryCatch(do.call(" spocc_inat_obs" , opts ), error = function (e ) e )
273
299
if (! is.data.frame(out $ data ) || inherits(out , " simpleError" )) {
@@ -325,14 +351,25 @@ foo_ebird <- function(sources, query, limit, callopts, opts) {
325
351
}
326
352
327
353
# ' @noRd
328
- foo_vertnet <- function (sources , query , limit , has_coords , callopts , opts ) {
354
+ foo_vertnet <- function (sources , query , limit , has_coords , date , callopts , opts ) {
329
355
if (any(grepl(" vertnet" , sources ))) {
330
356
time <- now()
331
357
if (! is.null(has_coords )) {
332
358
opts $ mappable <- has_coords
333
359
}
334
360
opts $ query <- query
335
361
opts $ messages <- FALSE
362
+ if (! is.null(date )) {
363
+ if (length(date ) != 2 ) stop(" 'date' for Vertnet must be length 2" )
364
+ date <- tryCatch(as.Date(date ), error = function (e ) e )
365
+ if (inherits(date , " error" )) stop(" 'date' values do not appear to be dates" )
366
+ opts $ year <- c(paste0(' >=' , format(date [1 ], " %Y" )),
367
+ paste0(' <=' , format(date [2 ], " %Y" )))
368
+ opts $ month <- c(paste0(' >=' , as.numeric(format(date [1 ], " %m" ))),
369
+ paste0(' <=' , as.numeric(format(date [2 ], " %m" ))))
370
+ opts $ day <- c(paste0(' >=' , as.numeric(format(date [1 ], " %d" ))),
371
+ paste0(' <=' , as.numeric(format(date [2 ], " %d" ))))
372
+ }
336
373
if (! ' limit' %in% names(opts )) opts $ limit <- limit
337
374
opts $ callopts <- callopts
338
375
out <- tryCatch(do.call(rvertnet :: searchbyterm , opts ),
@@ -363,7 +400,7 @@ foo_vertnet <- function(sources, query, limit, has_coords, callopts, opts) {
363
400
364
401
# ' @noRd
365
402
foo_idigbio <- function (sources , query , limit , start , geometry , has_coords ,
366
- callopts , opts ) {
403
+ date , callopts , opts ) {
367
404
if (any(grepl(" idigbio" , sources ))) {
368
405
time <- now()
369
406
@@ -375,6 +412,11 @@ foo_idigbio <- function(sources, query, limit, start, geometry, has_coords,
375
412
list (type = " missing" )
376
413
}
377
414
415
+ if (! is.null(date )) {
416
+ if (length(date ) != 2 ) stop(" 'date' for IdigBio must be length 2" )
417
+ opts $ rq $ datecollected <- list (type = " range" , gte = date [1 ], lte = date [2 ])
418
+ }
419
+
378
420
if (! is.null(geometry )) {
379
421
if (grepl(' POLYGON' , paste(as.character(geometry ), collapse = " " ))) {
380
422
geometry <- unlist(unname(c(wkt2bbox(geometry ))))
@@ -429,7 +471,7 @@ foo_idigbio <- function(sources, query, limit, start, geometry, has_coords,
429
471
430
472
# ' @noRd
431
473
foo_obis <- function (sources , query , limit , start , geometry , has_coords ,
432
- callopts , opts ) {
474
+ date , callopts , opts ) {
433
475
434
476
if (any(grepl(" obis" , sources ))) {
435
477
time <- now()
@@ -444,6 +486,12 @@ foo_obis <- function(sources, query, limit, start, geometry, has_coords,
444
486
}
445
487
}
446
488
489
+ if (! is.null(date )) {
490
+ if (length(date ) != 2 ) stop(" 'date' for OBIS must be length 2" )
491
+ opts $ startdate <- date [1 ]
492
+ opts $ enddate <- date [2 ]
493
+ }
494
+
447
495
if (! " limit" %in% names(opts )) opts $ limit <- limit
448
496
if (! ' offset' %in% names(opts )) opts $ offset <- start
449
497
@@ -475,10 +523,15 @@ foo_obis <- function(sources, query, limit, start, geometry, has_coords,
475
523
476
524
# ' @noRd
477
525
foo_ala <- function (sources , query , limit , start , geometry , has_coords ,
478
- callopts , opts ) {
526
+ date , callopts , opts ) {
527
+
479
528
if (any(grepl(" ala" , sources ))) {
480
529
time <- now()
481
530
opts $ taxon <- sprintf(' taxon_name:"%s"' , query )
531
+ if (! is.null(date )) {
532
+ if (length(date ) != 2 ) stop(" 'date' for ALA must be length 2" )
533
+ opts $ taxon <- paste0(opts $ taxon , sprintf(" occurrence_date:[%s TO %s]" , date [1 ], date [2 ]))
534
+ }
482
535
483
536
if (! is.null(geometry )) {
484
537
opts $ wkt <- if (grepl(' POLYGON' , paste(as.character(geometry ),
0 commit comments