I have a simple polygon:
extent = sf::st_polygon(list(matrix(c(-88.17182, 40.06722, -88.17182, 43.06722, -85.17182, 43.06722, -85.17182, 40.06722, -88.17182, 40.06722), ncol=2, byrow=TRUE)))
.
How can I set the CRS to EPSG:4326?
I thought certainly sf::st_set_crs(extent, 'EPSG:4326')
or sf::st_crs(extent) <- 4326
would work, but both fail with no applicable method for 'st_crs<-' applied to an object of class "c('XY', 'POLYGON', 'sfg')"
.
Best Answer
Wrap the
st_csr
call on each side. Although, you are missing a stepsf::st_sfc
in creating the correct object type.The right side creates the projection object which is then piped into the spatial object. Although, with valid sfc geometry you can now now pass the crs directly.