construct_to_gpkg_output_file_str.R 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #' 'qgisprocess' funktsiooonides GPKG INPUT/OUTPUT konstrueerimine GPKG kujule salvestamiseks
  2. #'
  3. #' See funktsioon konstrueerib 'qgisprocess' funktsioonides enamasti INPUT/OUTPUT/OVERLAY parameetri argumentide kasutatava fraasi, mis on vajalik postgresql andmebaasiga ühendamiseks.
  4. #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
  5. #' @param geometry_field str A geometri field name. Default: "geom".
  6. #' @param is_input_str TRUE/FALSE kui tulemusena väljastatakse import, siis TRUE.
  7. #' @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()]
  8. #' @return A string OUTPUT: "ogr:dbname='/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/test.gpkg' table=\"uus_epk200t_bb\"", INPUT: "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa/test.gpkg|layername=uus_epk200t_bb".
  9. #' @keywords qgis_process
  10. #' @export
  11. #' @examples
  12. #' \dontrun{
  13. #'
  14. #' conf <- ruut::get_config()
  15. #' conf$gpkg_home <- "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa"
  16. #' conf$gpkg_file <- "matsalu"
  17. #' conf$gpkg_table <- "piir"
  18. #' input <- ruut::construct_to_gpkg_output_postgres_str(
  19. #' conf = conf, is_input_str = TRUE
  20. #' )
  21. #' conf$gpkg_home <- "/data/gpkg/artiklid/artikkel_210127_valga_matsalu_lahemaa"
  22. #' conf$gpkg_file <- "mooduli_ruut_test"
  23. #' conf$gpkg_table <- "layerOne"
  24. #' output <- ruut::construct_to_gpkg_output_file_str(
  25. #' conf = conf, geometry_field = "geom", is_input_str = FALSE
  26. #' )
  27. #'
  28. #' str <- paste0("{ 'DISSOLVE' : False, 'DISTANCE' : 100, 'END_CAP_STYLE' : 2,
  29. #' 'INPUT' : '", input, "', 'JOIN_STYLE' : 1, 'MITER_LIMIT' : 2,
  30. #' 'OUTPUT' : '", output, "', 'SEGMENTS' : 5 }")
  31. #' algorithm <- "native:buffer"
  32. #' cmd <- ruut::construct_qgis_output_result_to_beter_format(str = str, algorithm = algorithm)
  33. #' system(cmd)
  34. #' }
  35. construct_to_gpkg_output_file_str <- function(conf = NULL, geometry_field = "geom", is_input_str = TRUE) {
  36. if (is.null(conf)) conf <- ruut::get_config()
  37. dsn <- sprintf("%s/%s.gpkg", conf$gpkg_home, conf$gpkg_file)
  38. if (is_input_str) {
  39. input <- sprintf("%s|layername=%s", dsn, conf$gpkg_table)
  40. input
  41. }
  42. else {
  43. ogr <- sprintf("ogr:dbname='%s'", dsn)
  44. output <- sprintf('%s table=\"%s\" (%s)', ogr, conf$gpkg_table, geometry_field)
  45. output
  46. }
  47. }