Skip to content

Commit 92bc3d1

Browse files
committed
fixes #2528
1 parent a9ceef1 commit 92bc3d1

File tree

3 files changed

+60
-2
lines changed

3 files changed

+60
-2
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# version 1.0-22
2+
3+
* clarify approximation errors in `st_buffer()` and how they differ for the GEOS or S2 backends, with examples by David Kaplan @dmkaplan2000; #2528
4+
15
# version 1.0-21
26

37
* `st_crs(..., parameters = TRUE)` returns base geographic CRS as `gcs_crs`; #2524

R/geom-transformers.R

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@
2929
#' when \code{sf_use_s2()} is set to \code{FALSE}). See \href{https://postgis.net/docs/ST_Buffer.html}{postgis.net/docs/ST_Buffer.html}
3030
#' for details. The \code{max_cells} and \code{min_level} parameters ([s2::s2_buffer_cells()]) work with the S2
3131
#' engine (i.e. geographic coordinates) and can be used to change the buffer shape (e.g. smoothing).
32-
#' A negative `dist` value for geodetic coordinates does not give a proper (geodetic) buffer.
32+
#' The S2 engine returns a polygon _around_ a number of S2 cells that
33+
#' contain the buffer, and hence will always have an area larger than the
34+
#' true buffer, depending on `max_cells`, and will be non-smooth when sufficiently zoomed in.
35+
#' The GEOS engine will return line segments between points
36+
#' on the circle, and so will always be _smaller_ than the true
37+
#' buffer, and be smooth, depending on the number of segments `nQuadSegs`.
38+
#' A negative `dist` value for geodetic coordinates using S2 does not give a proper (geodetic) buffer.
3339
#'
3440
#' @examples
3541
#'
@@ -69,6 +75,27 @@
6975
#' main = "mitreLimit: 3")
7076
#' plot(l2, col = 'blue', add = TRUE)
7177
#' par(op)
78+
#'
79+
#' # compare approximation errors depending on S2 or GEOS backend:
80+
#' # geographic coordinates, uses S2:
81+
#' x = st_buffer(st_as_sf(data.frame(lon=0,lat=0), coords=c("lon","lat"),crs='OGC:CRS84'), units::as_units(1,"km"))
82+
#' y = units::set_units(st_area(x), "km^2")
83+
#' # error: postive, default maxcells = 1000
84+
#' (units::drop_units(y)-pi)/pi
85+
#' x = st_buffer(st_as_sf(data.frame(lon=0,lat=0), coords=c("lon","lat"),crs='OGC:CRS84'), units::as_units(1,"km"), max_cells=1e5)
86+
#' y = units::set_units(st_area(x), "km^2")
87+
#' # error: positive but smaller:
88+
#' (units::drop_units(y)-pi)/pi
89+
#'
90+
#' # no CRS set: assumes Cartesian (projected) coordinates
91+
#' x = st_buffer(st_as_sf(data.frame(lon=0,lat=0), coords=c("lon","lat")), 1)
92+
#' y = st_area(x)
93+
#' # error: negative, nQuadSegs default at 30
94+
#' ((y)-pi)/pi
95+
#' x = st_buffer(st_as_sf(data.frame(lon=0,lat=0), coords=c("lon","lat")), 1, nQuadSegs = 100)
96+
#' y = st_area(x)
97+
#' # error: negative but smaller:
98+
#' ((y)-pi)/pi
7299
st_buffer = function(x, dist, nQuadSegs = 30,
73100
endCapStyle = "ROUND", joinStyle = "ROUND", mitreLimit = 1.0, singleSide = FALSE, ...)
74101
UseMethod("st_buffer")

man/geos_unary.Rd

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)