7.3 Geometry operations on projected/unprojected data

sf use GEOS for projected and s2 for geographic CRS.

london = data.frame(lon = -0.1, lat = 51.5) |> 
  st_as_sf(coords = c("lon", "lat"))
st_is_longlat(london)
## [1] NA
london_geo = st_set_crs(london, "EPSG:4326")
st_is_longlat(london_geo)
## [1] TRUE
london_buff_no_crs = st_buffer(london, dist = 1)   # incorrect: no CRS
london_buff_s2 = st_buffer(london_geo, dist = 100000) # silent use of s2
## Warning in st_buffer.sfc(st_geometry(x), dist, nQuadSegs, endCapStyle =
## endCapStyle, : st_buffer does not correctly buffer longitude/latitude data
## dist is assumed to be in decimal degrees (arc_degrees).
london_buff_s2_100_cells = st_buffer(london_geo, dist = 100000, max_cells = 10000) # play with max_cells 
## Warning in st_buffer.sfc(st_geometry(x), dist, nQuadSegs, endCapStyle =
## endCapStyle, : st_buffer does not correctly buffer longitude/latitude data
## dist is assumed to be in decimal degrees (arc_degrees).
# sf::sf_use_s2(FALSE)
london_proj = data.frame(x = 530000, y = 180000) |> 
  st_as_sf(coords = c("x", "y"), crs = "EPSG:27700")
london_buff_projected = st_buffer(london_proj, 100000)

In geographic CRS:

UK <- world[world$name_long == "United Kingdom",]
plot(UK$geom)
plot(london_buff_s2_100_cells, col = "red", add = TRUE)
plot(london_buff_no_crs$geometry, add = TRUE, lwd = 3)

In projected CRS:

plot(st_transform(UK$geom, "EPSG:27700"))
plot(london_buff_projected$geometry, add = TRUE, lwd = 3, col = "blue")