Learn R Programming

duckspatial

The {duckspatial} package provides fast and memory-efficient functions to analyze and manipulate large spatial vector datasets in R. It allows R users to benefit directly from the analytical power of DuckDB and its spatial extension, while remaining fully compatible with R’s spatial ecosystem, especially {sf}.

At its core, {duckspatial} bridges two worlds:

  • R spatial workflows based on {sf} objects
  • Database-backed spatial analytics powered by DuckDB SQL

This design makes {duckspatial} especially well suited for:

  • Working with large spatial data sets
  • Speeding up spatial analysis at scale
  • Workflows where data does not fit comfortably in memory

Importantly, {duckspatial} brings the power of DuckDB spatial to R users while keeping workflows similar to {sf} .

Installation

You can install duckspatial directly from CRAN with:

install.packages("duckspatial")

Or you can install the development version from GitHub with:

# install.packages("pak")
pak::pak("Cidree/duckspatial")

Core idea: flexible spatial workflows

A central design principle of {duckspatial} is that the same spatial operation can be used in different ways, depending on how your data is stored and how you want to manage memory and performance.

Most functions in {duckspatial} support four complementary workflows:

  1. Inputsf → Output sf
  2. Input sf → Output DuckDB table
  3. Input DuckDB table → Output sf
  4. Input DuckDB table → Output DuckDB table

See the “Get Started” vignette for examples.

Copy Link

Version

Install

install.packages('duckspatial')

Monthly Downloads

450

Version

0.9.0

License

GPL (>= 3)

Issues

Pull Requests

Stars

Forks

Maintainer

Adrián Cidre González

Last Published

January 10th, 2026

Functions in duckspatial (0.9.0)

ddbs_exterior_ring

Extracts the exterior ring of polygon geometries
ddbs_convex_hull

Returns the convex hull enclosing the geometry
ddbs_envelope

Returns the envelope (bounding box) of geometries
ddbs_equals

Spatial equals predicate
ddbs_drivers

Get list of GDAL drivers and file formats
ddbs_distance

Returns the distance between two geometries
ddbs_install

Checks and installs the Spatial extension
ddbs_glimpse

Check first rows of the data
ddbs_intersection

Calculates the intersection of two geometries
ddbs_filter

Performs spatial filter of two geometries
ddbs_interpolate_aw

Areal-Weighted Interpolation using DuckDB
ddbs_crs

Check CRS of a table
ddbs_crosses

Spatial crosses predicate
ddbs_is_simple

Check if geometries are simple
ddbs_join

Performs spatial joins of two geometries
ddbs_is_valid

Check if geometries are valid
ddbs_is_within_distance

Within Distance predicate
ddbs_flip

Flip geometries horizontally or vertically
ddbs_generate_points

Generate random points within geometries
ddbs_make_valid

Make invalid geometries valid
ddbs_overlaps

Spatial overlaps predicate
ddbs_quadkey

Convert geometries to QuadKey tiles
ddbs_stop_conn

Close a duckdb connection
ddbs_predicate

Spatial predicate operations
ddbs_touches

Spatial touches predicate
ddbs_shear

Shear geometries
ddbs_scale

Scale geometries by X and Y factors
ddbs_register_vector

Register an SF Object as an Arrow Table in DuckDB
ddbs_read_vector

Load spatial vector data from DuckDB into R
get_geom_name

Get column names in a DuckDB database
ddbs_simplify

Simplify geometries
ddbs_load

Loads the Spatial extension
ddbs_shift

Shift geometries by X and Y offsets
ddbs_make_polygon

Creates polygons from linestring geometries
get_query_name

Get names for the query
get_st_predicate

Gets predicate name
overwrite_table

Feedback for overwrite argument
ddbs_difference

Calculates the difference of two geometries
ddbs_disjoint

Spatial disjoint predicate
ddbs_write_vector

Write an SF Object to a DuckDB Database
ddbs_within

Spatial within predicate
ddbs_within_properly

Spatial within properly predicate
feedback_query

Feedback for query success
ddbs_list_tables

Check tables and schemas inside a database
ddbs_rotate

Rotate geometries around centroid
ddbs_intersects

Spatial intersects predicate
ddbs_length

Calculates the length of geometries
ddbs_intersects_extent

Spatial intersects extent predicate
ddbs_rotate_3d

Rotate 3D geometries around an axis
ddbs_union

Union of geometries
ddbs_transform

Transform coordinate reference system of geometries
ddbs_as_hexwkb

Convert geometries to hexadecimal Well-Known Binary (HEXWKB) format
dbConnCheck

Check if a supported DuckDB connection
ddbs_boundary

Returns the boundary of geometries
ddbs_as_wkb

Convert geometries to Well-Known Binary (WKB) format
ddbs_bbox

Returns the minimal bounding box enclosing the input geometry
convert_to_sf_wkb

Converts from data frame to sf using WKB conversion
convert_to_sf

Converts from data frame to sf
ddbs_as_text

Convert geometries to Well-Known Text (WKT) format
ddbs_area

Calculates the area of geometries
ddbs_create_schema

Check and create schema
ddbs_create_conn

Create a DuckDB connection with spatial extension
ddbs_buffer

Creates a buffer around geometries
ddbs_combine

Combine geometries into a single MULTI-geometry
ddbs_centroid

Calculates the centroid of geometries
ddbs_covers

Spatial covers predicate
ddbs_covered_by

Spatial covered by predicate
ddbs_contains

Spatial contains predicate
ddbs_concave_hull

Returns the concave hull enclosing the geometry
ddbs_contains_properly

Spatial contains properly predicate