Learn R Programming

GeoThinneR (version 1.0.0)

r_tree_thinning: Perform R-Tree Thinning

Description

Applies the R-tree thinning algorithm on a set of coordinates.

Usage

r_tree_thinning(
  coordinates,
  thin_dist = 10,
  trials = 10,
  all_trials = FALSE,
  space_partitioning = FALSE,
  euclidean = FALSE,
  R = 6371
)

Value

A logical vector indicating which points are kept in the best trial if all_trials is FALSE; otherwise, a list of logical vectors for each trial.

Arguments

coordinates

A matrix of coordinates to thin, with longitude and latitude.

thin_dist

Thinning distance in kilometers.

trials

Number of trials to run for thinning.

all_trials

If TRUE, returns results of all attempts; if FALSE, returns the best attempt with the most points retained (default: FALSE).

space_partitioning

A logical value indicating whether to use space partitioning.

euclidean

Logical value indicating whether to compute the Euclidean distance (`TRUE`) or Haversine distance (`FALSE`, default).

R

Radius of the Earth in kilometers (default: 6371 km).

Details

If you want to use R-trees you need to install the `rtree` package from `remotes::install_github("jmestret/rtree")`. It is a modified version from https://github.com/akoyabio/rtree.

Examples

Run this code
if (requireNamespace("rtree", quietly = TRUE)) {
  # Generate random coordinates
  set.seed(123)
  coordinates <- matrix(runif(20, min = -180, max = 180), ncol = 2) # 10 random points

  # Perform thinning without space partitioning
  result <- r_tree_thinning(coordinates, thin_dist = 10, trials = 5)
  print(result)

  # Perform thinning with space partitioning
  result_space_part <- r_tree_thinning(coordinates, thin_dist = 10, trials = 5,
                                       space_partitioning = TRUE)
  print(result_space_part)

  # Perform thinning with euclidean distance
  result_euclidean <- r_tree_thinning(coordinates, thin_dist = 10, trials = 5, euclidean = TRUE)
  print(result_euclidean)
}

Run the code above in your browser using DataLab