|
|
@@ -1,36 +1,41 @@
|
|
|
-#' Polügoni kopeerimine andmebaasi
|
|
|
+#' QGIS objekti 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.
|
|
|
+#' Funktsioon kopeerib QGIS objeketi postgis andmebaasi. Andmebaasi parameetri muutmiseks muuda konfiguratsiooni muutujat config <- ruut::get_config().
|
|
|
+#' @param x object of "qgis_result" spatial object.
|
|
|
#' @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
|
|
|
+#' @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.
|
|
|
+#' @keywords postgis, QGIS object
|
|
|
#' @export
|
|
|
#' @examples
|
|
|
#' ## Not run:
|
|
|
#' ##
|
|
|
-#' ## copy_polygon_to_db()
|
|
|
+#' ## copy_qgis_object_to_db()
|
|
|
#' ##
|
|
|
#' ## End(**Not run**)
|
|
|
-copy_polygon_to_db <- function(x = NULL, conf = NULL, id = "fid",
|
|
|
- crs_source = "EPSG:4326",
|
|
|
- crs_target = "EPSG:4326") {
|
|
|
+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 POLYGON ",
|
|
|
+ "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 POLYGON"
|
|
|
+ "-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
|
|
|
+ conf$schema, x, id, conf$schema, conf$table, crs_source, crs_target,
|
|
|
+ geometry_type
|
|
|
)
|
|
|
ruut::db_create_new_schema(conf)
|
|
|
- Sys.sleep(2)
|
|
|
+ Sys.sleep(1)
|
|
|
system(cmd)
|
|
|
} else {
|
|
|
NULL
|