Skip to contents

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, sf object, 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 is FALSE.

crs

Output CRS (e.g., "EPSG:4326"). Passed to GDAL as SRS option. If NULL, auto-detects from input data.

compression

Compression codec for Parquet files. Common options: "zstd", "snappy", "gzip", "lz4", "uncompressed". Default NULL uses 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 partitioning

    • sort_by: Character vector of column names to sort by (ascending)

    • single_file_output: TRUE/FALSE to force single file vs directory output

    • geoparquet_version: "1.0" (default) or "1.1" for bbox columns

    • overwrite_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.verbosity option. See sx_options() for persistent configuration.

...

Additional arguments (reserved for future use).

Value

The path invisibly.

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")
} # }