| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- #' QGIS objekti kopeerimine andmebaasi
- #'
- #' Funktsioon kopeerib QGIS objekti ('qgis_object') postgis andmebaasi. Andmebaasi ja konfiguratsiooni muutmiseks muuda konfiguratsiooni muutujat \code{conf}. Vaata \code{\link[ruut]{get_config}}.
- #' @param x object of 'qgis_result' spatial object.
- #' @param conf A list() of configuration variables. Default values \code{\link[ruut]{get_config}}.
- #' @param id A specified feature id will be processed. Unique field database. Default value 'fid'.
- #' @param crs_source CRS source CRS for example 'EPSG:3301' (Estonia). Default is 'EPSG:4326'.
- #' @param crs_target CRS target CRS for example 'EPSG:4326'. Default is 'EPSG:4326'.
- #' @param geometry_type str Force a geometry type for new layer. One of: NONE, GEOMETRY, POINT, LINESTRING, POLYGON, GEOMETRYCOLLECTION, MULTIPOINT, MULTIPOLYGON, or MULTILINESTRING, or PROMOTE_TO_MULTI or CONVERT_TO_LINEAR. Add "25D" for 3D layers.
- #' @return No output.
- #' @seealso [ruut::db_create_new_schema()], [ruut::get_config()], \url{https://gdal.org/programs/ogr2ogr.html}
- #' @keywords postgis, QGIS object
- #' @export
- #' @examples
- #' \dontrun{
- #'
- #' copy_qgis_object_to_db()
- #'
- #' }
- copy_qgis_object_to_db <- function(x = NULL, conf = NULL, id = "fid",
- crs_source = "EPSG:4326",
- crs_target = "EPSG:4326",
- geometry_type = "PROMOTE_TO_MULTI") {
- # Command 'ogr2ogr' help
- # system("ogr2ogr --long-usage")
- if (!is.null(x) && class(x) == "qgis_result") {
- cmd <- sprintf(
- paste0(
- "ogr2ogr -progress --config PG_USE_COPY YES -f PostgreSQL ",
- "PG:\" dbname='%s' host=%s port=%d user='%s' password='%s' ",
- "sslmode=%s active_schema=%s \" -lco DIM=2 %s -overwrite -nlt GEOMETRY ",
- "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
- "-s_srs %s -t_srs %s -nlt %s"
- ),
- conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode,
- conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target,
- geometry_type
- )
- ruut::db_create_new_schema(conf)
- Sys.sleep(1)
- system(cmd)
- } else {
- NULL
- }
- }
|