Description Usage Arguments Examples
This is a short-cut function that retrieves the database connection object from a
dbsettings
list, submits an SQL query, and returns the results as a data frame.
It is an alternative to composing queries as dplyr
pipelines.
1 | db_get_query(dbsettings, query)
|
dbsettings |
A named list of database connection settings returned
by |
query |
SQL query as a character string or similar (e.g. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ## Not run:
Sys.setenv(PGPASSWORD = "secret")
DBSettings <- db_connect_postgis("cermb_lidar")
# Simple query - count records in one of the tables
res <- db_get_query(DBSettings,
"select count(*) as n from mgazone56.point_counts")
# A more complex query: find overlapping LAS tiles in selected map sheets
library(glue)
mapnames <- c("Wallerawang", "StAlbans", "Gosford",
"MountPomany", "HowesValley", "Cessnock")
values <- paste(mapnames, collapse = ", ")
# Using spatial self-join on the metadata table
#
query <- glue("select a.id as id1, b.id as id2, mapname, purpose, capture_start
from mgazone56.las_metadata as a, mgazone56.las_metadata as b,
where mapname in ({values}) and
ST_Intersects(ST_Centroid(a.bounds), b.bounds) and
a.id < b.id;")
res <- db_get_query(DBSettings, query)
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.