R/noExport_checkGeom.R

#' This function obtains the geometric columns of a vector table in a postgreSQL database.
#' @title Obtains the geometric columns of a vector table
#' @name checkGeom
#' @param con An object of class "pgConnectPG" generated by pgConnect()
#' @param vecTable Name of vectorial table in the database
#' @return The name of the geometric columns as a string
#' @author Bruno Silva
checkGeom <- function(con, vecTable) {
  fields <- RPostgreSQL::dbListFields(con[[1]], vecTable) 
  options(show.error.messages = FALSE, warn = -1) # Desabilitar erros e warnings
  data <- data.frame(fields = fields, geom = FALSE)
  for (i in seq(fields)) {
    sprintf("SELECT ST_GeometryType(%s) FROM vecTable",
            fields[i], vecTable) %>%
      try(test <- RPostgreSQL::dbGetQuery(con[[1]], .))
    if (!is.null(test)) {
      data$geom[i] <- TRUE
      remove(test)
    }
  }
  options(show.error.messages = TRUE, warn = 0)  # Voltar a introduzir erros e warnings
  name <- fields[which(data$geom == TRUE)]
  return(name)
}
berdinazzi/easyPostgreSQL documentation built on May 12, 2019, 3:04 p.m.