sf (version 0.3-4)

st_transform: Transform or convert coordinates of simple feature

Description

Transform or convert coordinates of simple feature

Usage

st_transform(x, crs)

# S3 method for sfc st_transform(x, crs, ...)

# S3 method for sf st_transform(x, crs, ...)

# S3 method for sfg st_transform(x, crs, ...)

Arguments

x
object of class sf, sfc or sfg
crs
coordinate reference system: integer with the epsg code, or character with proj4string
...
ignored

Details

transforms coordinates of object to new projection the st_transform method for sfg objects assumes that the crs of the object is available as an attribute of that name.

Examples

Run this code
p1 = st_point(c(7,52))
p2 = st_point(c(-30,20))
sfc = st_sfc(p1, p2, crs = "+init=epsg:4326")
sfc
st_transform(sfc, "+init=epsg:3857")
st_transform(st_sf(a=2:1, geom=sfc), "+init=epsg:3857")
nc = st_read(system.file("shape/nc.shp", package="sf"))
st_area(nc[1,]) # area, using geosphere::areaPolygon
st_area(st_transform(nc[1,], 32119)) # NC state plane, m
st_area(st_transform(nc[1,], 2264)) # NC state plane, US foot
library(units)
as.units(st_area(st_transform(nc[1,], 2264)), make_unit("m")^2)
st_transform(structure(p1, proj4string = "+init=epsg:4326"), "+init=epsg:3857")

Run the code above in your browser using DataCamp Workspace