Writes spatial data to disk. Parquet files use SedonaDB's native GeoParquet writer. Other formats (GeoJSON, Shapefile, GPKG) use DuckDB's GDAL-based COPY.
Usage
sx_write(
data,
path,
gdal_driver = NULL,
overwrite = FALSE,
crs = NULL,
compression = NULL,
options = list(),
verbosity = NULL,
...
)Arguments
- data
A
sedonadb_dataframe,sfobject, or view name (character) in SedonaDB. Can also be a character string specifying the input file path for reading operations to write.- path
Character string. Path to the file (local, HTTP, or S3) to write to.
- gdal_driver
GDAL driver name for writing spatial formats. If
NULL(default), the driver is auto-detected from the file extension:.geojson,.json→ "GeoJSON".shp→ "ESRI Shapefile".gpkg→ "GPKG".fgb→ "FlatGeobuf"
For non-standard extensions, specify the driver explicitly. Use
"parquet"extension for native GeoParquet output.- overwrite
Logical. If
TRUE, overwrites any existing view with the same name. Default isFALSE.- crs
Output CRS (e.g., "EPSG:4326"). Passed to GDAL as
SRSoption. IfNULL, auto-detects from input data.- compression
Compression codec for Parquet files. Common options:
"zstd","snappy","gzip","lz4","uncompressed". DefaultNULLuses the backend's default (SedonaDB: uncompressed via native writer, DuckDB: snappy). Note: Specifying compression routes parquet output through DuckDB instead of SedonaDB's native GeoParquet writer.- options
Named list of additional options:
For parquet (via SedonaDB native writer, when no compression):
partition_by: Character vector of column names for Hive-style partitioningsort_by: Character vector of column names to sort by (ascending)single_file_output: TRUE/FALSE to force single file vs directory outputgeoparquet_version: "1.0" (default) or "1.1" for bbox columnsoverwrite_bbox_columns: If TRUE, overwrites existing bbox columns
For parquet (via DuckDB, when compression specified):
ROW_GROUP_SIZE: Integer, row group size
For GDAL:
LAYER_CREATION_OPTIONS
- verbosity
Character or NULL. Controls message output for this function call.
"quiet": Suppress all informational messages."info": Show standard progress and status messages."debug": Show additional diagnostic messages for troubleshooting.
If NULL (the default), uses the global
sx.verbosityoption. Seesx_options()for persistent configuration.- ...
Additional arguments (reserved for future use).
Examples
if (FALSE) { # \dontrun{
# Read nc data
sdf <- sx_read(system.file("shape/nc.shp", package = "sf"))
# Write to GeoJSON (auto-detected)
sx_write(sdf, "nc.geojson")
# Write to GeoParquet (native SedonaDB writer)
sx_write(sdf, "nc.parquet")
# Write to compressed parquet (via DuckDB)
sx_write(sdf, "nc_compressed.parquet", compression = "zstd")
# Write to Shapefile with explicit driver
sx_write(sdf, "nc.shp", gdal_driver = "ESRI Shapefile")
# Overwrite existing file
sx_write(sdf, "nc.gpkg", overwrite = TRUE)
# CRS override
sx_write(sdf, "nc_3857.geojson", crs = "EPSG:3857")
} # }
