Skip to contents

use sf to create a 20th century style 'dot map' which features the state boundary and county lines.

Usage

map_maker(x, path_out, path, collection_col, parallel = 0)

Arguments

x

an sf dataframe of coordinates to make maps for, requires collection number and spatial attributes

path_out

a directory to store the map images in before merging

path

a path to the directory holding the BarnebyLivesGeodata

collection_col

column specify the collection number or other UNIQUE id for the collection

parallel

Whether to use parallel to write out the maps in parallel, defaults to 0 (for false), 1 uses all threads, 0.5 for half, 0.25 for a quarter etc.

Examples

if (FALSE) { # \dontrun{
ce <- collection_examples[ sample(1:nrow(collection_examples), size = 20), ] |>
  sf::st_as_sf(coords = c('longitude_dd', 'latitude_dd'), crs = 4326)

#' # You need to define 'path' to point to your geodata's root location
path <- "/path/to/your/BarnebyLivesGeodata"

map_maker(ce, path_out = 'test', path = path, collection_col = 'Collection_number')

# single threaded; but gains on parallel unlikely.
start_time <- Sys.time()
map_maker(ce, path_out = 'test', path = path, collection_col = 'Collection_number')
duration <- Sys.time() - start_time

# with all cores via parallel::
start_time_parallel <- Sys.time()
map_maker(ce, path_out = 'test', path = path, collection_col = 'Collection_number', parallel = 1)
parallel_duration <- Sys.time() - start_time_parallel

# but speed up gains unlikely. if pct is % loading cores took longer than single threading.
speedup <- as.numeric(duration) / as.numeric(parallel_duration)
if(speedup > 1) {
 cat("Parallel was", round((1 - as.numeric(parallel_duration)/as.numeric(duration)) * 100, 1), "% faster\n")
} else {
  cat("Single-threaded was", round((1 - speedup) * 100, 1), "% faster (parallel overhead exceeded benefits)\n")
}

rm(start_time, duration, start_time_parallel, parallel_duration, speedup)
} # }