Query a subset or the entire dataset from the DEFID2 database. Multiple filters and select options are implemented

build_query(
  select = c("agents", "hosts", "symptoms"),
  geoms = TRUE,
  geom_event_relation = "exact",
  reconstruct_multipart = FALSE,
  country_filter = NULL,
  before_date_filter = NULL,
  after_date_filter = NULL,
  hosts_filter = NULL,
  agents_filter = NULL,
  symptoms_filter = NULL,
  st_intersects_filter = NULL
)

read_defid(
  select = c("agents", "hosts", "symptoms"),
  geoms = TRUE,
  geom_event_relation = "exact",
  reconstruct_multipart = FALSE,
  country_filter = NULL,
  before_date_filter = NULL,
  after_date_filter = NULL,
  hosts_filter = NULL,
  agents_filter = NULL,
  symptoms_filter = NULL,
  st_intersects_filter = NULL
)

defid_read(
  select = c("agents", "hosts", "symptoms"),
  geoms = TRUE,
  geom_event_relation = "exact",
  reconstruct_multipart = FALSE,
  country_filter = NULL,
  before_date_filter = NULL,
  after_date_filter = NULL,
  hosts_filter = NULL,
  agents_filter = NULL,
  symptoms_filter = NULL,
  st_intersects_filter = NULL
)

Arguments

select

A characters vector indicating fields to return. Available options are c('agents', 'hosts', 'symptoms', 'patterns', 'survey_method', 'country', 'dataset_code', 'survey_date_precision', 'triggers', 'triggers_dates', 'silvicultural_system', 'sanitary_intervention', 'sanitary_intervention_date', 'severities'). The survey date as well as the is_disturbed boolean are always included in the returned table. Default parameters are c('agents', 'hosts', 'symptoms')

geoms

Boolean indicating whether to return geometries or only attributes. If FALSE a data.frame is returned; else (TRUE, default) an sf data.frame is returned

geom_event_relation

A character indicating the type of geom-event relation of the returned records. Available options are 'exact' (default), 'substitute polygon', 'substitute point' and 'exact point'. See the vignette section on the DEFID2 data model for further details on the different relations between events and geometries.

reconstruct_multipart

Boolean indicating whether to recombine individual geometries into multi-part geometries when multiple geometries are linked to a single event

country_filter

A character vector (country names) used to filter records by countries. Exact spelling can be obtained using the countries function.

before_date_filter

A date or character indicating the posterior bound of the filtered data records (e.g. before_date_filter=as.Date('2015-01-01') or simply before_date_filter='2015-01-01' will only retain records prior to January 1st 2015).

after_date_filter

A date or character indicating the anterior bound of the filtered data records

hosts_filter

Filter returned records according to hosts (tree species). See hosts to get the list of hosts references in the DEFID2 database.

agents_filter

Filter returned records according to agents (infectious agent species). See agents to get the list of agents references in the DEFID2 database.

symptoms_filter

Filter returned records according to reported symptoms. Available symptoms that can be used for filtering are c('Defoliation', 'Discolouration', 'Mortality', 'Dieback').

st_intersects_filter

Spatial filter using a simple feature geometry (sfg). The sfg must be passed as a simple feature collection (sfc) of length 1.

Value

String representation of an SQL query

sf dataframe if geom is set to TRUE (default), dataframe otherwise

Details

defid_read is an alias for read_defid

Examples

if (FALSE) {
library(sf)
# load all 'exact' records as an sf dataframe containing agents and hosts information
df <- read_defid(select=c('agents', 'hosts'))
# Load all data from Czechia whose survey date is between January 1 2020 and December 31 2020
df <- read_defid(country_filter='Czechia', before_date_filter='2020-12-31', after_date_filter='2020-01-01')
# Spatial filter with geometry
buf <- st_sfc(st_buffer(st_point(c(16.10, 49.75)), 0.2), crs=4326)
df <- read_defid(st_intersects_filter = buf)
# Agent filter
df <- read_defid(agents_filter='Sirococcus conigenus')
# Host filter
df <- read_defid(hosts_filter=c('Pinus halepensis', 'Pinus nigra', 'Pinus sylvestris',
                                'Pinus pinaster', 'Pinus pinea', 'Pinus cembra',
                                'Pinus sp.', 'Pinus mugo'),
                 geom_event_relation='exact point')
}