#' ESRI Shapefile kopeerimine andmebaasi #' #' Funktsioon kopeerib ESRI Shapefile objekti postgis andmebaasi. Andmebaasi ja konfiguratsiooni muutmiseks muuda konfiguratsiooni muutujat \code{conf}. Vaata \code{\link[ruut]{get_config}}. #' @param dir The directory where the shapefiles are located. #' @param layer str Layer to use. #' @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()] #' @keywords postgis, ESRI Shapefile #' @export #' @examples #' \dontrun{ #' #' copy_qgis_object_to_db() #' #' } copy_shp_to_db <- function(dir = NULL, layer = 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") # Kontrollime kas etteantud kataloogis paiknevad failid if (length(list.files(path = dir, pattern = sprintf("%s*", layer))) > 0) { source <- sprintf('"%s" "%s"', dir, layer) 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, source, id, conf$schema, conf$table, crs_source, crs_target, geometry_type ) ruut::db_create_new_schema(conf) Sys.sleep(1) system(cmd) } else { cat("\nEi leitud antud kataloogist faile.") return(NULL) } }