as_crs: Standardise the coordinate reference system (CRS) of an...

View source: R/utils.R

as_crsR Documentation

Standardise the coordinate reference system (CRS) of an object

Description

Standardise the coordinate reference system (CRS) of an object

Usage

as_crs(x, allow_geographic = FALSE)

Arguments

x

An object of class sf, sfc, bbox, or a numeric or character vector representing a CRS (e.g., EPSG code). If numeric, the value should be an unrestricted positive number representing a valid EPSG code.

allow_geographic

Logical, whether to allow geographic CRS (lat/lon).

Value

An object of class sf::crs with a valid CRS.

Examples

library(sf)

# Standardise a numeric EPSG code
as_crs(4326, allow_geographic = TRUE)

# Standardise a character EPSG code
as_crs("EPSG:4326", allow_geographic = TRUE)

# Standardise a bbox object
bb <- st_bbox(c(xmin = 25.9, ymin = 44.3, xmax = 26.2, ymax = 44.5),
                crs = 4326)
as_crs(bb, allow_geographic = TRUE)

# Standardise a simple feature object
bb_sfc <- st_as_sfc(bb)
bb_sf <- st_as_sf(bb_sfc)
as_crs(bb_sf, allow_geographic = TRUE)
as_crs(bb_sfc, allow_geographic = TRUE)

rcrisp documentation built on Nov. 24, 2025, 5:07 p.m.