#' Automatic ESRI shp file import into postgis table with ogr2ogr #' @details Selle funktsiooniga imporditakse zip kujul ESRI shp fail postgis andmebaasi. #' Geomeetria tuleb määrata parameetriga \code{\link{wkt}}. Andmete projektsioon #' konverteeritakse EPSG:4326 kujule. Esialgne tabel kirjutatakse andmebaasis üle. #' @param shpZip Zipped ESRI sho file. #' @param dsn data source name (interpretation varies by driver — for some drivers, #' dsn is a file name, but may also be a folder). #' @param tbl Postgis table name. #' @param wkt Text representations (WKT) of the spatial objects. #' @return return message. #' @seealso \code{\link{ogr2postgis}}, \code{\link{wkt}}, #' \code{\link{myPostgresCreateGisDb}}, \code{\link{myPostgresImprotShp}} #' @examples \dontrun{ #' # Postgis conf #' source('/home/ardo/apps/git/R/apps/postgis/conf.R') #' tblName = "test_tabel" #' # Zipped shp file #' shpZip = "/home/ardo/apps/git/R/apps/postgis/data-sources/geodata/transport/teed/tanel/riigimnt.zip" #' ogr2postgis(shpZip = shpZip, #' dsn = conf$dsn, tbl = tblName, wkt = "MULTILINESTRING") #' #' } #' #' @export #' ogr2postgis <- function(shpZip, dsn, tbl = NULL, wkt = c("NONE", "GEOMETRY", "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION")) { # Unzip zip <- utils::unzip(zipfile = shpZip, list = F, overwrite = T, exdir = paste0(tempdir(), "/unzip")) shpFileName <- list.files(paste0(tempdir(), "/unzip"), pattern = ".shp$", full.names = T, recursive = T) cmd <- paste0('ogr2ogr -lco FID="gid" -wrapdateline -t_srs "EPSG:4326" ', '-overwrite -lco GEOMETRY_NAME="geom" -a_srs "EPSG:4326"', ' -f "PostgreSQL" "', dsn, '"', ' -nlt ', wkt,' ', shpFileName, ' -nln ', tbl) # shpFileName system(cmd) unlink(zip) message(paste("Tabeli", tbl, "kopeeriti andmebaasi.")) # cmd } #' Text representations (WKT) of the spatial objects #' @details Text representations (WKT) of the spatial objects. Postgis andmebaasis #' kasutatavate geomeetriate tüübid. Vajalik ESRI shp failide importimisel #' (\code{\link{ogr2postgis}}) #' @seealso \code{\link{ogr2postgis}}, \code{\link{wkt}} #' @examples \dontrun{ #' transpordiTsoonid::wkt #' #' } #' #' @export #' wkt = c("NONE", "GEOMETRY", "POINT", "LINESTRING", "POLYGON", "MULTIPOINT", "MULTILINESTRING", "MULTIPOLYGON", "GEOMETRYCOLLECTION")