% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/ddbs_geom_validation.R
\name{ddbs_geom_validation_funs}
\alias{ddbs_geom_validation_funs}
\alias{ddbs_is_simple}
\alias{ddbs_is_valid}
\alias{ddbs_is_closed}
\alias{ddbs_is_empty}
\alias{ddbs_is_ring}
\title{Geometry validation functions}
\usage{
ddbs_is_simple(
  x,
  new_column = "is_simple",
  conn = NULL,
  name = NULL,
  mode = NULL,
  overwrite = FALSE,
  quiet = FALSE
)

ddbs_is_valid(
  x,
  new_column = "is_valid",
  conn = NULL,
  name = NULL,
  mode = NULL,
  overwrite = FALSE,
  quiet = FALSE
)

ddbs_is_closed(
  x,
  new_column = "is_closed",
  conn = NULL,
  name = NULL,
  mode = NULL,
  overwrite = FALSE,
  quiet = FALSE
)

ddbs_is_empty(
  x,
  new_column = "is_empty",
  conn = NULL,
  name = NULL,
  mode = NULL,
  overwrite = FALSE,
  quiet = FALSE
)

ddbs_is_ring(
  x,
  new_column = "is_ring",
  conn = NULL,
  name = NULL,
  mode = NULL,
  overwrite = FALSE,
  quiet = FALSE
)
}
\arguments{
\item{x}{Input spatial data. Can be:
\itemize{
\item A \code{duckspatial_df} object (lazy spatial data frame via dbplyr)
\item An \code{sf} object
\item A \code{tbl_lazy} from dbplyr
\item A character string naming a table/view in \code{conn}
}
Data is returned from this object.}

\item{new_column}{Name of the new column to create on the input data. Ignored
with \code{mode = "sf"}.}

\item{conn}{A connection object to a DuckDB database. If \code{NULL}, the function
runs on a temporary DuckDB database.}

\item{name}{A character string of length one specifying the name of the table,
or a character string of length two specifying the schema and table
names. If \code{NULL} (the default), the function returns the result as an
\code{sf} object}

\item{mode}{Character. Controls the return type. Options:
\itemize{
\item \code{"duckspatial"} (default): Lazy spatial data frame backed by dbplyr/DuckDB
\item \code{"sf"}: Eagerly collected sf object (uses memory)
}
Can be set globally via \code{\link{ddbs_options}(mode = "...")} or
per-function via this argument. Per-function overrides global setting.}

\item{overwrite}{Boolean. whether to overwrite the existing table if it exists. Defaults
to \code{FALSE}. This argument is ignored when \code{name} is \code{NULL}.}

\item{quiet}{A logical value. If \code{TRUE}, suppresses any informational messages.
Defaults to \code{FALSE}.}
}
\value{
\itemize{
\item \code{mode = "duckspatial"} (default): A \code{duckspatial_df} (lazy spatial data frame) backed by dbplyr/DuckDB.
\item \code{mode = "sf"}: An eagerly collected vector in R memory.
\item When \code{name} is provided: writes the table in the DuckDB connection and returns \code{TRUE} (invisibly).
}
}
\description{
Functions to check various geometric properties and validity conditions of spatial
geometries using DuckDB's spatial extension.
}
\details{
These functions provide different types of geometric validation. Note that by default,
the functions add a new column as a logical vector. This behaviour allows to filter the
data within DuckDB without the need or materializating a vector in R (see details).
\itemize{
\item \code{ddbs_is_valid()} checks if a geometry is valid according to the OGC Simple Features
specification. Invalid geometries may have issues like self-intersections in polygons,
duplicate points, or incorrect ring orientations.
\item \code{ddbs_is_simple()} determines whether geometries are simple, meaning they are free of
self-intersections. For example, a linestring that crosses itself is not simple.
\item \code{ddbs_is_ring()} checks if a linestring geometry is closed (first and last points are
identical) and simple (no self-intersections), forming a valid ring.
\item \code{ddbs_is_empty()} tests whether a geometry is empty, containing no points. Empty
geometries are valid but represent the absence of spatial information.
\item \code{ddbs_is_closed()} determines if a linestring geometry is closed, meaning the first
and last coordinates are identical. Unlike \code{ddbs_is_ring()}, this does not check for
simplicity.
}
}
\examples{
\dontrun{
## load package
library(duckspatial)
library(dplyr)

## create a duckdb database in memory (with spatial extension)
conn <- ddbs_create_conn(dbdir = "memory")

## read data
countries_ddbs <- ddbs_open_dataset(
  system.file("spatial/countries.geojson", 
  package = "duckspatial")
)

rivers_ddbs <- ddbs_open_dataset(
  system.file("spatial/rivers.geojson", 
  package = "duckspatial")
)

## geometry validation
ddbs_is_valid(countries_ddbs)
ddbs_is_simple(countries_ddbs)
ddbs_is_ring(rivers_ddbs)
ddbs_is_empty(countries_ddbs)
ddbs_is_closed(countries_ddbs)

## filter invalid countries
ddbs_is_valid(countries_ddbs) |> filter(!is_valid)
}

}
