Learn R Programming

sf (version 0.5-5)

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, ..., partial = TRUE, check = FALSE, use_gdal = TRUE)

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

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

st_proj_info(type = "proj")

st_wrap_dateline(x, options = "WRAPDATELINE=YES", quiet = TRUE)

Arguments

x

object of class sf, sfc or sfg

crs

coordinate reference system: integer with the EPSG code, or character with proj4string

...

ignored

partial

logical; allow for partial projection, if not all points of a geometry can be projected (corresponds to setting environment variable OGR_ENABLE_PARTIAL_REPROJECTION to TRUE)

check

logical; perform a sanity check on resulting polygons?

use_gdal

logical; if FALSE, arguments check and partial get ignored, and projection is directly carried out by lwgeom_transform which ignores the GDAL api. This allows proj.4 parameters such as +over to act (https://github.com/r-spatial/sf/issues/511) and certain projections such as wintri which do not have an inverse, to work (https://github.com/r-spatial/sf/issues/509). This requires that sf is built by linking to liblwgeom.

type

character; one of proj, ellps, datum or units

options

character; should have "WRAPDATELINE=YES" to function; another parameter that is used is "DATELINEOFFSET=10" (where 10 is the default value)

quiet

logical; print options after they have been parsed?

Details

Transforms coordinates of object to new projection. Features that cannot be transformed are returned as empty geometries.

The st_transform method for sfg objects assumes that the CRS of the object is available as an attribute of that name.

st_proj_info lists the available projections, ellipses, datums or units supported by the Proj.4 library

For a discussion of using options, see https://github.com/r-spatial/sf/issues/280

Examples

Run this code
# NOT RUN {
p1 = st_point(c(7,52))
p2 = st_point(c(-30,20))
sfc = st_sfc(p1, p2, crs = 4326)
sfc
st_transform(sfc, 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)
set_units(st_area(st_transform(nc[1,], 2264)), m^2)
st_transform(structure(p1, proj4string = "+init=epsg:4326"), "+init=epsg:3857")
st_proj_info("datum")
st_wrap_dateline(st_sfc(st_linestring(rbind(c(-179,0),c(179,0))), crs = 4326))
# }

Run the code above in your browser using DataLab