sf_transform_xy | R Documentation |
Helper function that can transform spatial position data (pairs of x, y
values) among coordinate systems. This is implemented as a thin wrapper
around sf::sf_project()
.
sf_transform_xy(data, target_crs, source_crs, authority_compliant = FALSE)
data |
Data frame or list containing numerical columns |
target_crs , source_crs |
Target and source coordinate reference systems.
If |
authority_compliant |
logical; |
A copy of the input data with x
and y
replaced by transformed values.
if (requireNamespace("sf", quietly = TRUE)) {
# location of cities in NC by long (x) and lat (y)
data <- data.frame(
city = c("Charlotte", "Raleigh", "Greensboro"),
x = c(-80.843, -78.639, -79.792),
y = c(35.227, 35.772, 36.073)
)
# transform to projected coordinates
data_proj <- sf_transform_xy(data, 3347, 4326)
data_proj
# transform back
sf_transform_xy(data_proj, 4326, 3347)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.