Examples for 'sf::st_crs'


Retrieve coordinate reference system from object

Aliases: st_crs st_crs.sf st_crs.numeric st_crs.character st_crs.sfc st_crs.bbox st_crs.CRS st_crs.crs st_crs<- st_crs<-.sf st_crs<-.sfc st_set_crs NA_crs_ is.na.crs $.crs format.crs st_axis_order

Keywords: datasets

### ** Examples

sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
sf = st_sf(a = 1:2, geom = sfc)
st_crs(sf) = 4326
st_geometry(sf)
Geometry set for 2 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
Geodetic CRS:  WGS 84
POINT (0 0)
POINT (1 1)
sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
st_crs(sfc) = 4326
sfc
Geometry set for 2 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 0 ymin: 0 xmax: 1 ymax: 1
Geodetic CRS:  WGS 84
POINT (0 0)
POINT (1 1)
sfc = st_sfc(st_point(c(0,0)), st_point(c(1,1)))
sfc %>% st_set_crs(4326) %>% st_transform(3857)
Geometry set for 2 features 
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 0 ymin: 0 xmax: 111319.5 ymax: 111325.1
Projected CRS: WGS 84 / Pseudo-Mercator
POINT (0 0)
POINT (111319.5 111325.1)
st_crs("EPSG:3857")$input
[1] "EPSG:3857"
st_crs(3857)$proj4string
[1] "+proj=merc +a=6378137 +b=6378137 +lat_ts=0 +lon_0=0 +x_0=0 +y_0=0 +k=1 +units=m +nadgrids=@null +wktext +no_defs"
pt = st_sfc(st_point(c(0, 60)), crs = 4326)
# st_axis_order() only has effect in GDAL >= 2.5.0:
st_axis_order() # query default: FALSE means interpret pt as (longitude latitude)
[1] FALSE
st_transform(pt, 3857)[[1]]
POINT (0 8399738)
old_value = FALSE
if (sf_extSoftVersion()["GDAL"] >= "2.5.0")
   (old_value = st_axis_order(TRUE))
[1] FALSE
# now interpret pt as (latitude longitude), as EPSG:4326 prescribes:
st_axis_order() # query current value
[1] TRUE
st_transform(pt, 3857)[[1]]
POINT (6679169 0)
st_axis_order(old_value) # set back to old value

[Package sf version 1.0-19 Index]