File: sf_transform_xy.Rd

package info (click to toggle)
r-cran-ggplot2 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 9,944 kB
  • sloc: sh: 15; makefile: 5
file content (44 lines) | stat: -rw-r--r-- 1,495 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/coord-sf.R
\name{sf_transform_xy}
\alias{sf_transform_xy}
\title{Transform spatial position data}
\usage{
sf_transform_xy(data, target_crs, source_crs, authority_compliant = FALSE)
}
\arguments{
\item{data}{Data frame or list containing numerical columns \code{x} and \code{y}.}

\item{target_crs, source_crs}{Target and source coordinate reference systems.
If \code{NULL} or \code{NA}, the data is not transformed.}

\item{authority_compliant}{logical; \code{TRUE} means handle axis order authority
compliant (e.g. EPSG:4326 implying \code{x = lat}, \code{y = lon}), \code{FALSE} means use
visualisation order (i.e. always \code{x = lon}, \code{y = lat}). Default is \code{FALSE}.}
}
\value{
A copy of the input data with \code{x} and \code{y} replaced by transformed values.
}
\description{
Helper function that can transform spatial position data (pairs of x, y
values) among coordinate systems. This is implemented as a thin wrapper
around \code{\link[sf:sf_project]{sf::sf_project()}}.
}
\examples{
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)
}
}
\keyword{internal}