@@ -161,12 +161,12 @@ st_sample.bbox = function(x, size, ..., great_circles = FALSE, segments = units:
161161 segments = units :: drop_units(units :: set_units(segments , " degree" , mode = " standard" ))
162162 polygon = st_set_crs(st_segmentize(polygon , segments ), crs )
163163 }
164- st_sample(polygon , size , ... )
164+ st_sample(polygon , size , ... , oriented = TRUE )
165165}
166166
167167st_poly_sample = function (x , size , ... , type = " random" ,
168168 offset = st_sample(st_as_sfc(st_bbox(x )), 1 )[[1 ]],
169- by_polygon = FALSE ) {
169+ by_polygon = FALSE , oriented = FALSE ) {
170170
171171 if (by_polygon && inherits(x , " sfc_MULTIPOLYGON" )) { # recurse into polygons:
172172 sum_a = units :: drop_units(sum(st_area(x )))
@@ -201,13 +201,15 @@ st_poly_sample = function(x, size, ..., type = "random",
201201 h1 = sin(bb [" ymax" ] * toRad )
202202 h2 = sin(bb [" ymin" ] * toRad )
203203 a0 = 2 * pi * R ^ 2 . * (h1 - h2 ) * (bb [" xmax" ] - bb [" xmin" ]) / 360 .
204- a1 = as.numeric(sum(st_area(x )))
204+ # a1 = as.numeric(sum(st_area(x)))
205+ a1 = sum(s2 :: s2_area(st_as_s2(x , oriented = oriented )))
205206 if (! is.finite(a1 ))
206207 stop(" One or more geometries have a non-finite area" )
207- if (a1 < 1 ) { # global polygon FIXME:
208- a1 = a0
209- global = TRUE
210- }
208+ # if (a1 < 1) { # global polygon FIXME:
209+ # a1 = a0
210+ # global = TRUE
211+ # }
212+ global = (a1 / a0 ) > .9999
211213 size = round(size * a0 / a1 )
212214 } else {
213215 a0 = as.numeric(st_area(st_as_sfc(bb )))
0 commit comments