7.3 Geometry operations on projected/unprojected data
sf use GEOS for projected and s2 for geographic CRS.
= data.frame(lon = -0.1, lat = 51.5) |>
london st_as_sf(coords = c("lon", "lat"))
st_is_longlat(london)
## [1] NA
= st_set_crs(london, "EPSG:4326")
london_geo st_is_longlat(london_geo)
## [1] TRUE
= st_buffer(london, dist = 1) # incorrect: no CRS
london_buff_no_crs = st_buffer(london_geo, dist = 100000) # silent use of s2 london_buff_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).
= st_buffer(london_geo, dist = 100000, max_cells = 10000) # play with max_cells london_buff_s2_100_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)
= data.frame(x = 530000, y = 180000) |>
london_proj st_as_sf(coords = c("x", "y"), crs = "EPSG:27700")
= st_buffer(london_proj, 100000) london_buff_projected
In geographic CRS:
<- world[world$name_long == "United Kingdom",]
UK 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")