Skip to content
Prev 29346 / 29559 Next

How to create inward (shrinking) buffer zones with st_buffer()

Dear Xiang,

sure it is possible. I suggest using a CRS that is projected, e.g. 3857 
(Web Mercator), or turn off s2 geometry. If you turn off s2, then 
st_buffer() will interpret the dist parameter in degrees. Anyway, if you 
choose a small enough number, then you'll get a non-empty geometry.

 > sf_use_s2(FALSE)
Spherical geometry (s2) switched off
 > st_buffer(a, -100)
dist is assumed to be in decimal degrees (arc_degrees).
Geometry set for 1 feature? (with 1 geometry empty)
Geometry type: POLYGON
Dimension:???? XY
Bounding box:? xmin: NA ymin: NA xmax: NA ymax: NA
Geodetic CRS:? WGS 84
POLYGON EMPTY
Warning message:
In st_buffer.sfc(a, -100) :
 ? st_buffer does not correctly buffer longitude/latitude data
 > st_buffer(a, -0.001)
dist is assumed to be in decimal degrees (arc_degrees).
Geometry set for 1 feature
Geometry type: POLYGON
Dimension:???? XY
Bounding box:? xmin: -2.533411 ymin: 51.40595 xmax: -2.489763 ymax: 51.4315
Geodetic CRS:? WGS 84
POLYGON ((-2.533083 51.41747, -2.528692 51.4204...
Warning message:
In st_buffer.sfc(a, -0.001) :
 ? st_buffer does not correctly buffer longitude/latitude data

(I don't know why s2 can't deal with negative distance if the CRS is 
WGS-84.)

HTH,
?kos
____________
?kos Bede-Fazekas
Centre for Ecological Research, Hungary

2024. 02. 19. 11:04 keltez?ssel, Xiang Ye via R-sig-Geo ?rta: