| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- #' Export GPKG to PostgreSQL
- #'
- #' Exports a gpkg file layer into a PostgreSQL database.
- #'
- #' gtype: Output geometry type 'enum':. Acceptable values: Number of selected option, e.g. '1' or Comma separated list of options, e.g. c(1,3). See more: \url{https://gdal.org/drivers/vector/pg.html}.
- #' - 0:
- #' - 1: NONE
- #' - 2: GEOMETRY
- #' - 3: POINT
- #' - 4: LINESTRING
- #' - 5: POLYGON
- #' - 6: GEOMETRYCOLLECTION
- #' - 7: MULTIPOINT
- #' - 8: MULTIPOLYGON
- #' - 9: MULTILINESTRING
- #'
- #' @param gpkg Gpkg file path.
- #' @param layer A gpkg file layer [sf::st_layers()].
- #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
- #' @return No output.
- #' @seealso [ruut::get_config()], [ruut::copy_shp_to_db()], [ruut::copy_qgis_object_to_db()]
- #' @keywords postgis, gpkg
- #' @export
- #' @examples
- #' \dontrun{
- #'
- #' conf <- ruut::get_config()
- #' gpkg_file <- "/home/ardo/aaa/data/gpkg/grids/estonian_grids.gpkg"
- #' # Vaata layer'eid
- #' sf::st_layers(gpkg_file)
- #' # Vali layer
- #' layer <- "epk200t_grid"
- #' conf$table <- "aaa_1"
- #' conf$schema <- "data"
- #' copy_gpkg_to_db(gpkg = gpkg_file, layer = layer, conf = conf)
- #' copy_gpkg_to_db(gpkg = gpkg_file, conf = conf) # viga
- #' }
- copy_gpkg_to_db <- function(gpkg = NULL, layer = NULL, conf = NULL) {
- if (is.null(gpkg)) {
- return(cat("\ngpkg fail puudu.\n"))
- }
- if (is.null(layer)) {
- return(cat("\ngpkg layer puudu.\n"))
- }
- if (is.null(conf)) conf <- ruut::get_config()
- layer <- sprintf("|layername=%s", layer)
- input <- sprintf("%s%s", gpkg, layer)
- # obj - objekti nimetus (näiteks: valga)
- # ruut::qgis_algorithm_search_by_word(str = "importinto")
- algorithm <- "qgis:importintopostgis"
- # cat(qgisprocess::qgis_show_help(algorithm = algorithm))
- # qgisprocess::qgis_outputs(algorithm = algorithm)
- ruut::db_create_new_schema(conf)
- result <- qgisprocess::qgis_run_algorithm(
- algorithm = algorithm,
- CREATEINDEX = 1,
- DATABASE = tools::toTitleCase(tolower(conf$dbname)), # millegipärast peab algama suure tähega
- DROP_STRING_LENGTH = 0,
- ENCODING = conf$encoding,
- FORCE_SINGLEPART = 0,
- GEOMETRY_COLUMN = conf$geometry_column,
- INPUT = input,
- LOWERCASE_NAMES = 1,
- OVERWRITE = 1,
- PRIMARY_KEY = conf$primary_key,
- SCHEMA = conf$schema,
- TABLENAME = conf$table,
- )
- # result
- }
|