Last chance! 50% off unlimited learning
Sale ends in
Transform or convert coordinates of simple feature
st_transform(x, crs, ...)# S3 method for sfc
st_transform(
x,
crs = st_crs(x),
...,
aoi = numeric(0),
pipeline = character(0),
reverse = FALSE,
partial = TRUE,
check = FALSE
)
# S3 method for sf
st_transform(x, crs = st_crs(x), ...)
# S3 method for sfg
st_transform(x, crs = st_crs(x), ...)
sf_proj_info(type = "proj", path)
st_wrap_dateline(x, options, quiet)
# S3 method for sfc
st_wrap_dateline(x, options = "WRAPDATELINE=YES", quiet = TRUE)
# S3 method for sf
st_wrap_dateline(x, options = "WRAPDATELINE=YES", quiet = TRUE)
# S3 method for sfg
st_wrap_dateline(x, options = "WRAPDATELINE=YES", quiet = TRUE)
object of class sf, sfc or sfg
coordinate reference system: integer with the EPSG code, or character with proj4string
ignored
area of interest, in degrees: WestLongitude, SouthLatitude, EastLongitude, NorthLatitude
character; proj4 or WKT coordinate operation, to override the default operation
boolean; if TRUE
, the inverse operation of the pipeline is applied
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
)
logical; perform a sanity check on resulting polygons?
character; one of have_datum_files
, proj
, ellps
, datum
, units
or prime_meridians
; see Details.
character; PROJ search path to be set
character; should have "WRAPDATELINE=YES" to function; another parameter that is used is "DATELINEOFFSET=10" (where 10 is the default value)
logical; print options after they have been parsed?
Transforms coordinates of object to new projection. Features that cannot be transformed are returned as empty geometries.
Projecting to projections not supported by GDAL may be done by st_transform_proj, part of package lwgeom.
The st_transform
method for sfg
objects assumes that the CRS of the object is available as an attribute of that name.
sf_proj_info
lists the available projections, ellipses, datums, units, or data search path of the PROJ library when type
is equal to proj, ellps, datum, units or path; when type
equals have_datum_files
a boolean is returned indicating whether datum files are installed and accessible (checking for conus
).
for PROJ >= 6, sf_proj_info
does not provide option type = "datums"
.
PROJ < 6 does not provide the option type = "prime_meridians"
.
for PROJ >= 7.1.0, the "units" query of sf_proj_info
returns the to_meter
variable as numeric, previous versions return a character vector containing a numeric expression.
For a discussion of using options
, see https://github.com/r-spatial/sf/issues/280 and https://github.com/r-spatial/sf/issues/541
# 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")
try(st_transform(sfc, 3857, aoi = c(-280,-90,180,90)))
if (sf_extSoftVersion()["GDAL"] >= "3.0.0") {
st_transform(sfc, pipeline =
"+proj=pipeline +step +proj=axisswap +order=2,1") # reverse axes
st_transform(sfc, pipeline =
"+proj=pipeline +step +proj=axisswap +order=2,1", reverse = TRUE) # also reverse axes
}
nc = st_read(system.file("shape/nc.shp", package="sf"))
st_area(nc[1,]) # area from long/lat
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")
sf_proj_info("datum")
st_wrap_dateline(st_sfc(st_linestring(rbind(c(-179,0),c(179,0))), crs = 4326))
library(maps)
wrld <- st_as_sf(maps::map("world", fill = TRUE, plot = FALSE))
wrld_wrap <- st_wrap_dateline(wrld, options = c("WRAPDATELINE=YES", "DATELINEOFFSET=180"),
quiet = TRUE)
wrld_moll <- st_transform(wrld_wrap, "+proj=moll")
plot(st_geometry(wrld_moll), col = "transparent")
# }
Run the code above in your browser using DataLab