View source: R/io_write_dataset.R
| ddbs_write_dataset | R Documentation |
Writes spatial data to disk using DuckDB's COPY command for Parquet and
GDAL spatial formats, or as a native DuckDB database for .duckdb, .db,
and .ddb paths. Format is auto-detected from file extension for common
formats, or can be specified explicitly via gdal_driver.
ddbs_write_dataset(
data,
path,
gdal_driver = NULL,
conn = NULL,
overwrite = FALSE,
crs = NULL,
layer = "spatial",
options = list(),
partitioning = if (inherits(data, c("tbl_lazy", "duckspatial_df")))
dplyr::group_vars(data) else NULL,
parquet_compression = NULL,
parquet_row_group_size = NULL,
layer_creation_options = NULL,
quiet = FALSE,
duckdb_storage_version = duckspatial_storage_default()
)
data |
A |
path |
Path to output file. |
gdal_driver |
GDAL driver name for writing spatial formats. If
For non-standard file extensions (e.g., Note: If you specify a driver that doesn't match the file extension (e.g.,
The function validates that the specified driver is available and writable on your
system. Note: |
conn |
A connection object to a DuckDB database. If |
overwrite |
Logical. If |
crs |
Output CRS (e.g., "EPSG:4326"). Passed to GDAL as |
layer |
Table name for native DuckDB database output. |
options |
Named list of additional options passed to |
partitioning |
Character vector of columns to partition by (Parquet/CSV only). |
parquet_compression |
Compression codec for Parquet. |
parquet_row_group_size |
Row group size for Parquet. |
layer_creation_options |
GDAL layer creation options. |
quiet |
A logical value. If |
duckdb_storage_version |
Storage compatibility for newly created native
DuckDB database files (
Other major version strings like |
Persistent DuckDB database files created by duckspatial use Native
Spatial Storage (storage_version = "v1.5.0") by default so CRS metadata is
retained in native GEOMETRY columns. These files require DuckDB >= 1.5.0
to open; use Legacy Compatibility (storage_version = "v1.0.0")
when the output must be readable by older DuckDB versions.
The path invisibly.
This function is inspired by and builds upon the logic found in the
duckdbfs package (https://github.com/cboettig/duckdbfs),
particularly its write_dataset and write_geo functions.
For advanced features like cloud storage (S3) support, the
duckdbfs package is highly recommended.
ddbs_drivers() to list all available GDAL drivers and formats.
## Not run:
library(duckspatial)
# Read example data
path <- system.file("spatial/countries.geojson", package = "duckspatial")
ds <- ddbs_open_dataset(path)
# Auto-detect format from extension
ddbs_write_dataset(ds, "output.geojson")
ddbs_write_dataset(ds, "output.gpkg")
ddbs_write_dataset(ds, "output.parquet")
# Explicit GDAL driver for non-standard extension
ddbs_write_dataset(ds, "mydata.dat", gdal_driver = "GeoJSON")
# See available drivers on your system
drivers <- ddbs_drivers()
writable <- drivers[drivers$can_create == TRUE, ]
head(writable)
# CRS override
ddbs_write_dataset(ds, "output_3857.geojson", crs = "EPSG:3857")
# Overwrite existing file
ddbs_write_dataset(ds, "output.gpkg", overwrite = TRUE)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.