Sfoglia il codice sorgente

Muudetud 'construct_to_gpkg_output_postgres_str' QGIS 3.18 jaoks.

Ardo Kubjas 5 anni fa
parent
commit
d44ed980fb

+ 2 - 0
R/construct_qgis_output_result_to_beter_format.R

@@ -49,6 +49,8 @@ construct_qgis_output_result_to_beter_format <- function(str = "", algorithm = "
   str <- gsub("\"([ a-zA-Z0-9_ ]*)\"", "\\\\\"\\1\\\\\"", str)
   # Eemaldame komad
   str <- gsub(", ", " ", str)
+  # Eemaldame reavahed
+  str <- gsub("\n", " ", str)
   # Asendame algoritmi
   str <- gsub("algorithm", algorithm, str)
   cat(str)

+ 33 - 6
R/construct_to_gpkg_output_postgres_str.R

@@ -2,23 +2,50 @@
 #'
 #' See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide  kasutatava fraasi, mis on vajalik postgresql andmebaasiga ühendamisegs.
 #' @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 gpkg
+#' @keywords qgis_process
 #' @export
 #' @examples
-#'
 #' \dontrun{
 #'
+#'
 #' conf <- ruut::get_config()
-#' construct_to_gpkg_output_postgres_str(conf = NULL)
+#' conf$schema <- "maaamet"
+#' conf$table <- "asustusyksus"
+#' 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) {
+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 key=\'id\' srid=3301  checkPrimaryKeyUnicity=\'1\' table=\"%s\".\"%s\" (geom)',
-    conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode, conf$schema, conf$table
+    "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
 }

+ 39 - 4
man/construct_to_gpkg_output_postgres_str.Rd

@@ -4,10 +4,27 @@
 \alias{construct_to_gpkg_output_postgres_str}
 \title{'qgisprocess' funktsiooonides GPKG INPUT/OUTPUT konstrueerimine Postgresql salvestamiseks}
 \usage{
-construct_to_gpkg_output_postgres_str(conf = NULL)
+construct_to_gpkg_output_postgres_str(
+  conf = NULL,
+  geometry_field = "geom",
+  geometry_type = NULL,
+  srid = NULL,
+  checkPrimaryKeyUnicity = FALSE,
+  key = NULL
+)
 }
 \arguments{
 \item{conf}{A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.}
+
+\item{geometry_field}{str A geometri field name. Default: "geom".}
+
+\item{geometry_type}{str Select: 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection','PolygonWithHole','Collection'.}
+
+\item{srid}{CRS Default: 3301. Other: 4326.}
+
+\item{checkPrimaryKeyUnicity}{TRUE/FALSE.}
+
+\item{key}{str A primary key ID, usally 'id'.}
 }
 \value{
 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)".
@@ -16,11 +33,29 @@ A string "postgres://dbname='\%s' host=\%s port=\%s user='\%s' password='\%s' ss
 See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide  kasutatava fraasi, mis on vajalik postgresql andmebaasiga ühendamisegs.
 }
 \examples{
-
 \dontrun{
 
+
 conf <- ruut::get_config()
-construct_to_gpkg_output_postgres_str(conf = NULL)
+conf$schema <- "maaamet"
+conf$table <- "asustusyksus"
+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)
 }
 }
 \seealso{
@@ -28,4 +63,4 @@ construct_to_gpkg_output_postgres_str(conf = NULL)
 
 \code{\link[=construct_ogr2ogr_PG_connect_str]{construct_ogr2ogr_PG_connect_str()}}, \code{\link[=construct_qgis_output_result_to_beter_format]{construct_qgis_output_result_to_beter_format()}}
 }
-\keyword{gpkg}
+\keyword{qgis_process}