@@ -141,15 +141,27 @@ st_sample.sfg = function(x, size, ...) {
141141
142142# ' @export
143143# ' @name st_sample
144+ # ' @param great_circles logical; if `TRUE`, great circle arcs are used to connect the bounding box vertices, if `FALSE` parallels (graticules)
145+ # ' @param segments units, or numeric (degrees); segment sizes for segmenting a bounding box polygon if `great_circles` is `FALSE`
144146# ' @examples
145147# ' bbox = st_bbox(
146- # ' c(xmin = 16.1 , xmax = 16.6 , ymax = 48.6 , ymin = 47.9 ),
147- # ' crs = st_crs(4326 )
148+ # ' c(xmin = 0 , xmax = 40 , ymax = 70 , ymin = 60 ),
149+ # ' crs = st_crs('OGC:CRS84' )
148150# ' )
149- # '
150- # ' st_sample(bbox, 5)
151- st_sample.bbox = function (x , size , ... ) {
152- st_sample(st_as_sfc(x ), size , ... )
151+ # ' set.seed(13531)
152+ # ' s1 = st_sample(bbox, 400)
153+ # ' st_bbox(s1) # within bbox
154+ # ' s2 = st_sample(bbox, 400, great_circles = TRUE)
155+ # ' st_bbox(s2) # outside bbox
156+ st_sample.bbox = function (x , size , ... , great_circles = FALSE , segments = units :: set_units(2 , degrees )) {
157+ polygon = st_as_sfc(x )
158+ crs = st_crs(x )
159+ if (isTRUE(st_is_longlat(x )) && ! great_circles ) {
160+ st_crs(polygon ) = NA_crs_ # to fool segmentize that we're on R2:
161+ segments = units :: drop_units(units :: set_units(segments , degrees ))
162+ polygon = st_set_crs(st_segmentize(polygon , segments ), crs )
163+ }
164+ st_sample(polygon , size , ... )
153165}
154166
155167st_poly_sample = function (x , size , ... , type = " random" ,
0 commit comments