| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- #' 'qgisprocess' funktsiooonides GPKG INPUT/OUTPUT konstrueerimine Postgresql salvestamiseks
- #'
- #' See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide kasutatava fraasi, mis on vajalik postgresql andmebaasiga ühendamiseks.
- #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
- #' @param geometry_field str A geometri field name. Default: "geom".
- #' @param geometry_type str Select: 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection','PolygonWithHole','Collection'.
- #' @param srid CRS Default: 3301. Other: 4326.
- #' @param checkPrimaryKeyUnicity TRUE/FALSE.
- #' @param key str A primary key ID, usally 'id'.
- #' @seealso [ruut::db_connect()], [ruut::get_config()], [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::construct_qgis_output_result_to_beter_format()],[ruut::construct_to_gpkg_output_file_str()]
- #' @return A string "postgres://dbname='%s' host=%s port=%s user='%s' password='%s' sslmode=%s key='id' srid=3301 checkPrimaryKeyUnicity='1' table=\"%s\".\"%s\" (geom)".
- #' @seealso [ruut::construct_ogr2ogr_PG_connect_str()], [ruut::construct_qgis_output_result_to_beter_format()]
- #' @keywords qgis_process
- #' @export
- #' @examples
- #' \dontrun{
- #'
- #'
- #' conf <- ruut::get_config()
- #' conf$schema <- "maaamet"
- #' conf$table <- "epk200t"
- #' input <- ruut::construct_to_gpkg_output_postgres_str(
- #' conf = conf, geometry_type = "Polygon", srid = 3301,
- #' checkPrimaryKeyUnicity = TRUE, key = "id"
- #' )
- #' conf$schema <- "data"
- #' conf$table <- "test"
- #' output <- ruut::construct_to_gpkg_output_postgres_str(
- #' conf = conf, geometry_type = NULL, srid = NULL,
- #' checkPrimaryKeyUnicity = FALSE, key = NULL
- #' )
- #'
- #' str <- paste0("{ 'DISSOLVE' : False, 'DISTANCE' : 100, 'END_CAP_STYLE' : 2,
- #' 'INPUT' : '", input, "', 'JOIN_STYLE' : 1, 'MITER_LIMIT' : 2,
- #' 'OUTPUT' : '", output, "', 'SEGMENTS' : 5 }")
- #' algorithm <- "native:buffer"
- #' cmd <- ruut::construct_qgis_output_result_to_beter_format(str = str, algorithm = algorithm)
- #' system(cmd)
- #' }
- construct_to_gpkg_output_postgres_str <- function(conf = NULL, geometry_field = "geom", geometry_type = NULL, srid = NULL, checkPrimaryKeyUnicity = FALSE, key = NULL) {
- if (is.null(conf)) conf <- ruut::get_config()
- if (is.null(geometry_type)) geometry_type <- "" else geometry_type <- sprintf("type=%s", geometry_type)
- if (is.null(srid)) srid <- "" else srid <- sprintf("srid=%s", srid)
- if (checkPrimaryKeyUnicity) checkPrimaryKeyUnicity <- "checkPrimaryKeyUnicity='1'" else checkPrimaryKeyUnicity <- ""
- if (is.null(key)) key <- "" else key <- sprintf("key='%s'", key)
- PG <- sprintf(
- "postgres://dbname='%s' host=%s port=%s user='%s' password='%s' sslmode=%s %s %s %s %s table=\"%s\".\"%s\" (%s)",
- conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, key, srid, geometry_type, checkPrimaryKeyUnicity, conf$schema, conf$table, geometry_field
- )
- PG
- }
|