@@ -380,7 +380,10 @@ sits_sampling_design <- function(cube,
380
380
# ' @param sampling_design Result of sits_sampling_design
381
381
# ' @param alloc Allocation method chosen
382
382
# ' @param overhead Additional percentage to account for border points
383
+ # ' @param multicores Number of cores that will be used to
384
+ # ' sample the images in parallel.
383
385
# ' @param shp_file Name of shapefile to be saved (optional)
386
+ # ' @param progress Show progress bar? Default is TRUE.
384
387
# ' @return samples Point sf object with required samples
385
388
# '
386
389
# ' @examples
@@ -418,7 +421,9 @@ sits_stratified_sampling <- function(cube,
418
421
sampling_design ,
419
422
alloc = " alloc_prop" ,
420
423
overhead = 1.0 ,
421
- shp_file = NULL ){
424
+ multicores = 2 ,
425
+ shp_file = NULL ,
426
+ progress = TRUE ){
422
427
# check the cube is valid
423
428
.check_raster_cube_files(cube )
424
429
# check cube is class cube
@@ -443,13 +448,21 @@ sits_stratified_sampling <- function(cube,
443
448
.check_that(all(unname(samples_class ) == floor(unname(samples_class ))),
444
449
msg = " allocation values should be integer"
445
450
)
451
+ .check_multicores(multicores , min = 1 , max = 2048 )
452
+ .check_progress(progress )
446
453
# name samples class
447
454
names(samples_class ) <- rownames(sampling_design )
448
455
# include overhead
449
456
samples_class <- ceiling(samples_class * overhead )
450
457
# estimate size
451
458
size <- ceiling(max(samples_class )/ nrow(cube ))
452
- samples_lst <- slider :: slide(cube , function (tile ) {
459
+ # Prepare parallel processing
460
+ .parallel_start(workers = multicores )
461
+ on.exit(.parallel_stop(), add = TRUE )
462
+ # Create assets as jobs
463
+ cube_assets <- .cube_split_assets(cube )
464
+ # Process each asset in parallel
465
+ samples <- .jobs_map_parallel_dfr(cube_assets , function (tile ) {
453
466
robj <- .raster_open_rast(.tile_path(tile ))
454
467
cls <- data.frame (id = 1 : n_labels ,
455
468
cover = labels )
@@ -463,8 +476,8 @@ sits_stratified_sampling <- function(cube,
463
476
samples_sf <- sf :: st_as_sf(samples_sv )
464
477
samples_sf <- dplyr :: mutate(samples_sf ,
465
478
label = labels [.data [[" cover" ]]])
466
- } )
467
- samples <- do.call( rbind , samples_lst )
479
+ samples_sf <- sf :: st_transform( samples_sf , crs = " EPSG:4326 " )
480
+ }, progress = progress )
468
481
469
482
samples <- purrr :: map_dfr(labels , function (lab ){
470
483
samples_class <- samples | >
0 commit comments