|
29 | 29 | #' 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}
|
30 | 30 | #' for details. The \code{max_cells} and \code{min_level} parameters ([s2::s2_buffer_cells()]) work with the S2
|
31 | 31 | #' 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. |
33 | 39 | #'
|
34 | 40 | #' @examples
|
35 | 41 | #'
|
|
69 | 75 | #' main = "mitreLimit: 3")
|
70 | 76 | #' plot(l2, col = 'blue', add = TRUE)
|
71 | 77 | #' 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 |
72 | 99 | st_buffer = function(x, dist, nQuadSegs = 30,
|
73 | 100 | endCapStyle = "ROUND", joinStyle = "ROUND", mitreLimit = 1.0, singleSide = FALSE, ...)
|
74 | 101 | UseMethod("st_buffer")
|
|
0 commit comments