% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/dbSpatial.R
\name{dbSpatial}
\alias{dbSpatial}
\alias{dbSpatial-class}
\title{Create a \code{\link{dbSpatial}} object with geometry data type}
\usage{
dbSpatial(
  value,
  name,
  conn,
  x_colName = NULL,
  y_colName = NULL,
  geomName = "geom",
  overwrite = FALSE,
  ...
)
}
\arguments{
\item{value}{\code{data.frame}, \code{tbl_duckdb_connection}, \code{character}
(valid file path), \code{sf} object, or \code{terra} object.
Data to construct \code{\link{dbSpatial}} object with geometry data type.
See details for more information.}

\item{name}{Table name.}

\item{conn}{A DBI connection object.}

\item{x_colName}{\code{character}. Name of column containing numerical X coordinates. default = \code{NULL}.}

\item{y_colName}{\code{character}. Name of column containing numerical Y coordinates. default = \code{NULL}.}

\item{geomName}{\code{character string}. The geometry column name in the  \code{\link{dbSpatial}}  object. Default: \code{"geom"}.}

\item{overwrite}{\code{logical}. Overwrite existing table. default = \code{FALSE}.}

\item{...}{Additional arguments to be passed}
}
\value{
\code{\link{dbSpatial}} object.
}
\description{
Constructor function to ingest diverse spatial data sources and create
a \code{\link{dbSpatial}} object containing a \code{geometry} data type based
on the \href{https://en.wikipedia.org/wiki/Simple_Features}{Simple Features}
standard.

If \code{x_colName} and \code{y_colName} are both provided, a \code{POINT} geometry
will be constructed based on these columns.
}
\details{
For list of files supported see link below.
\url{https://DuckDB.org/docs/extensions/spatial.html#st_read---read-spatial-value-from-files}
}
\examples{
if (interactive() && requireNamespace("duckdb", quietly = TRUE)) {
  # create in-memory DuckDB db
  duckdb_conn = DBI::dbConnect(duckdb::duckdb(), ":memory:")
  DBI::dbExecute(duckdb_conn, "SET threads = 1")

  # test value
  test_data = data.frame(x = 1:10, y = 1:10, id = 1:10)

  test_file <- tempfile(fileext = ".csv")
  write.csv(test_data, test_file, row.names = FALSE)

  # read data.frame and create point geometry
  dbSpatial(conn = duckdb_conn,
            name = "test_points",
            value = test_data,
            x_colName = "x",
            y_colName = "y",
            overwrite = TRUE)

  # read csv
  dbSpatial(conn = duckdb_conn,
            name = "test_points",
            value = test_file,
            x_colName = "x",
            y_colName = "y",
            overwrite = TRUE)
  unlink(test_file)
  DBI::dbDisconnect(duckdb_conn, shutdown = TRUE)
}
}
\seealso{
Other dbSpatial: 
\code{\link{as_dbSpatial}()},
\code{\link{show,dbSpatial-method}},
\code{\link{st_as_sf.dbSpatial}()},
\code{\link{vect,dbSpatial-method}}
}
\concept{dbSpatial}
