| 123456789101112131415161718192021222324252627282930313233343536373839 |
- #' Polügoni kopeerimine andmebaasi
- #'
- #' Funktsioon kopeerib sf polügooni postgis andmebaasi. Andmebaasi parameetri muutmiseks muuda konfiguratsiooni muutujat config <- ruut::get_config().
- #' @param x object of "qgis_result" spatial polygon.
- #' @param conf list database configuration. Default get_config()
- #' @param id field andmebaasi unikaalne id veerg. Default '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'.
- #' @keywords postgis, polygon
- #' @export
- #' @examples
- #' ## Not run:
- #' ##
- #' ## copy_polygon_to_db()
- #' ##
- #' ## End(**Not run**)
- copy_polygon_to_db <- function(x = NULL, conf = NULL, id = "fid",
- crs_source = "EPSG:4326",
- crs_target = "EPSG:4326") {
- 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 POLYGON ",
- "-lco GEOMETRY_NAME=geometry -lco FID=%s -nln %s.%s ",
- "-s_srs %s -t_srs %s -nlt POLYGON"
- ),
- conf$dbname, conf$host, conf$port, conf$user, conf$password, conf$sslmode,
- conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target
- )
- source(paste0(getwd(), "/R/db_create_new_schema.R"))
- # Create new schema if not exist.
- db_create_new_schema(conf)
- system(cmd)
- } else {
- NULL
- }
- }
|