Added DB classes
This commit is contained in:
89
R/db_geometries.R
Normal file
89
R/db_geometries.R
Normal file
@@ -0,0 +1,89 @@
|
||||
#' @export
|
||||
# nolint next: object_name_linter. R6Class
|
||||
MNR.DB.Geometries <- R6::R6Class(
|
||||
"MNR.DB.Geometries",
|
||||
inherit = MNR.DB,
|
||||
public = list(
|
||||
getBlocks = function(
|
||||
with_geometries = TRUE, ordered = FALSE, collect = TRUE
|
||||
) {
|
||||
qry <- private$db_client$table("blocks")
|
||||
|
||||
if (ordered) {
|
||||
qry <- qry %>%
|
||||
dplyr::mutate(
|
||||
block_ref_num = stringr::str_replace_all(
|
||||
block_ref, "[A-Z]+/", "999/"
|
||||
),
|
||||
block_ref_let = stringr::str_replace_all(
|
||||
block_ref, "[0-9]+/", "A/"
|
||||
),
|
||||
block_order_A = as.integer(stringr::str_replace_all(
|
||||
block_ref_num, "/[0-9]+", ""
|
||||
)),
|
||||
block_order_B = stringr::str_replace_all(
|
||||
block_ref_let, "/[0-9]+", ""
|
||||
),
|
||||
block_order_C = as.integer(stringr::str_replace_all(
|
||||
block_ref, "[A-Z0-9]+/", ""
|
||||
))
|
||||
) %>%
|
||||
dplyr::collapse() %>%
|
||||
dbplyr::window_order(block_order_A, block_order_B, block_order_C) %>%
|
||||
dplyr::collapse()
|
||||
}
|
||||
|
||||
if (!with_geometries) {
|
||||
qry <- qry %>%
|
||||
dplyr::select(-dplyr::any_of(c("geometry", "proj", "geom"))) %>%
|
||||
private$db_client$collectOrReturn()
|
||||
} else if (collect) {
|
||||
qry <- qry %>%
|
||||
private$db_client$collectGeometries()
|
||||
}
|
||||
|
||||
qry
|
||||
},
|
||||
|
||||
getConservationAreas = function(with_geometries = TRUE, collect = TRUE) {
|
||||
qry <- private$db_client$table("conservation_areas")
|
||||
|
||||
if (!with_geometries) {
|
||||
qry <- qry %>%
|
||||
dplyr::select(-dplyr::any_of(c("geometry", "proj", "geom"))) %>%
|
||||
private$db_client$collectOrReturn()
|
||||
} else if (collect) {
|
||||
qry <- qry %>%
|
||||
private$db_client$collectGeometries()
|
||||
}
|
||||
|
||||
qry
|
||||
},
|
||||
|
||||
getMarineRegions = function(with_geometries = TRUE, collect = TRUE) {
|
||||
qry <- private$db_client$table("marine_regions")
|
||||
|
||||
if (!with_geometries) {
|
||||
qry <- qry %>%
|
||||
dplyr::select(-dplyr::any_of(c("geometry", "proj", "geom"))) %>%
|
||||
private$db_client$collectOrReturn()
|
||||
} else if (collect) {
|
||||
qry <- qry %>%
|
||||
private$db_client$collectGeometries()
|
||||
}
|
||||
|
||||
qry
|
||||
},
|
||||
|
||||
getBlockMarineRegions = function(collect = TRUE) {
|
||||
qry <- private$db_client$table("block_marine_regions")
|
||||
private$db_client$collectOrReturn(qry)
|
||||
},
|
||||
|
||||
# nolint next: object_length_linter. Descriptive function name required
|
||||
getBlockConservationAreaDistances = function(collect = TRUE) {
|
||||
qry <- private$db_client$table("block_conservation_area_distances")
|
||||
private$db_client$collectOrReturn(qry)
|
||||
}
|
||||
)
|
||||
)
|
||||
Reference in New Issue
Block a user