Skip to contents

Transforms the coordinates of the geometry column to a new Coordinate Reference System (CRS). Calculations are performed in SedonaDB using ST_Transform.

Usage

sx_transform(
  x,
  crs,
  src_crs = NULL,
  output = NULL,
  view_name = NULL,
  verbosity = NULL,
  ...
)

Arguments

x

A sedonadb_dataframe, sf object, or view name (character) in SedonaDB to transform.

crs

Target Coordinate Reference System. Can be:

  • An integer/numeric EPSG code (e.g., 5070).

  • A character string (e.g., "EPSG:5070").

  • An sf::crs object.

  • An sf object (to extract CRS from).

src_crs

Source Coordinate Reference System (optional). If NULL (default), the CRS is inferred from the input x using sx_crs(). If the input has no CRS, this argument is required.

output

Character or NULL. Output type: sedonadb_dataframe (default), sf, tibble, geoarrow, or raw. If NULL, uses getOption("sx.output_type", "sedonadb_dataframe").

Output types:

  • sedonadb_dataframe: Lazy data frame (no collection).

  • sf: Materialized sf object.

  • tibble: Tibble without geometry.

  • geoarrow: Tibble with geoarrow_vctr geometry (Arrow-native).

  • raw: Tibble with geometry as raw WKB bytes (for database import).

view_name

Character (optional). Name to register the result as a persistent view in the active backend. If NULL (default), returns the result directly without creating a view.

Not all backends support named views. Check backend-specific documentation for availability.

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.

...

Ignored. Used to catch sf-specific arguments.

Value

Result (type depends on output)

Examples

# \donttest{
library(sf)
nc <- st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)

# Transform to EPSG:5070 (Albers)
res <- sx_transform(nc, 5070, output = "sf")

# Register as view and transform
sx_as_view(nc, "nc_raw")
sx_transform("nc_raw", "EPSG:3857")
#> ┌────────────────────────────────────────────┬─────────┬───┬─────────┬─────────┐
#> │                  geometry                  ┆   AREA  ┆ … ┆  SID79  ┆ NWBIR79 │
#> │                  geometry                  ┆ float64 ┆   ┆ float64 ┆ float64 │
#> ╞════════════════════════════════════════════╪═════════╪═══╪═════════╪═════════╡
#> │ MULTIPOLYGON(((-9069486.066435972 4332928… ┆   0.114 ┆ … ┆     0.0 ┆    19.0 │
#> ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
#> │ MULTIPOLYGON(((-9043562.885968298 4351023… ┆   0.061 ┆ … ┆     3.0 ┆    12.0 │
#> ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
#> │ MULTIPOLYGON(((-8956336.229524622 4334060… ┆   0.143 ┆ … ┆     6.0 ┆   260.0 │
#> ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
#> │ MULTIPOLYGON(((-8461241.746303901 4344696… ┆    0.07 ┆ … ┆     2.0 ┆   145.0 │
#> ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
#> │ MULTIPOLYGON(((-8595797.151114915 4333841… ┆   0.153 ┆ … ┆     3.0 ┆  1197.0 │
#> ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
#> │ MULTIPOLYGON(((-8543185.635554852 4332866… ┆   0.097 ┆ … ┆     5.0 ┆  1237.0 │
#> └────────────────────────────────────────────┴─────────┴───┴─────────┴─────────┘
#> Preview of up to 6 row(s)
# }