# Class Structure

The `dbSpatial` package is designed to work with spatial geometries in a DuckDB table. The package builds on the DuckDB spatial extension.

`dbSpatial` objects adopt the S4 class system and represent spatial `geometries` in a DuckDB table. The `{dbSpatial}` package consists of methods for constructing `dbSpatial` objects from various data sources, as well as various spatial operations for working with these data.

`dbSpatial` provides methods for reading/writing `dbSpatial` objects from/to data.frames, S3 and S4 spatial-related objects (e.g. objects from `{sf}` or `{terra}`), and several other spatial files that are supported by the DuckDB spatial extension.

The runnable example below is evaluated only when the `duckdb` package is available in the check environment.

## Minimal example

    library(dbSpatial)

    con <- DBI::dbConnect(duckdb::duckdb(), ":memory:")
    DBI::dbExecute(con, "SET threads = 1")
    coords <- data.frame(id = 1:3, x = c(0, 1, 2), y = c(0, 1, 2))

    pts <- dbSpatial(
      conn = con,
      name = "class_structure_points",
      value = coords,
      x_colName = "x",
      y_colName = "y",
      overwrite = TRUE
    )

    class(pts)
    pts

    DBI::dbDisconnect(con, shutdown = TRUE)