R/RcppExports.R

Defines functions deg2rad_cpp spherical_distance_cpp distance_matrix_cpp binary_matrix_cpp nearest_facility_dist spherical_distance_cpp_vec

Documented in binary_matrix_cpp deg2rad_cpp distance_matrix_cpp nearest_facility_dist spherical_distance_cpp spherical_distance_cpp_vec

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Convert degrees to radians
#'
#' @param deg degrees
#'
#' @return radians
#'
#' @export
deg2rad_cpp <- function(deg) {
    .Call('_maxcovr_deg2rad_cpp', PACKAGE = 'maxcovr', deg)
}

#' Calculate distance using haversines formula
#'
#' @param lat1 latitude from the first location
#' @param long1 longitude from the first location
#' @param lat2 latitude from the second location
#' @param long2 longitude from the second location
#'
#' @return distance in metres between two locations
#'
#' @export
spherical_distance_cpp <- function(lat1, long1, lat2, long2) {
    .Call('_maxcovr_spherical_distance_cpp', PACKAGE = 'maxcovr', lat1, long1, lat2, long2)
}

#' Create a matrix of distances between two areas
#'
#' @param facility a matrix with longitude and latitude in the first two columns
#' @param user a matrix with longitude and latitude in the first two columns
#'
#' @return a matrix of distances in metres between each user and facility,
#' with nrow(user) rows and nrow(facility) columns.
#'
#' @export
#'
distance_matrix_cpp <- function(facility, user) {
    .Call('_maxcovr_distance_matrix_cpp', PACKAGE = 'maxcovr', facility, user)
}

#' Create a binary matrix TRUE if distance satisfies a condition
#'
#' @param facility a matrix with longitude and latitude in the first two columns
#' @param user a matrix with longitude and latitude in the first two columns
#' @param distance_cutoff numeric indicating the distance cutoff (in metres)
#' you are interested in. If a number is less than distance_cutoff, it will be
#' 1, if it is greater than it, it will be 0.
#'
#' @return a logical matrix 1 if distance between element i, j is less than or
#' equal to the distance_cutoff, and 0 otherwise
#'
#' @export
#'
binary_matrix_cpp <- function(facility, user, distance_cutoff) {
    .Call('_maxcovr_binary_matrix_cpp', PACKAGE = 'maxcovr', facility, user, distance_cutoff)
}

#' nearest facility + distance to a user
#'
#' @param facility a matrix with longitude and latitude in the first two columns
#' @param user a matrix with longitude and latitude in the first two columns
#'
#' @return matrix with 3 columns: user_id, facility_id, distance, where the
#' user_id is the identifier for the user, the facility_id is the identifier
#' for the facility that is closest to that user, and the distance is the
#' distance in metres from that user to that facility.
#'
#' @export
#'
nearest_facility_dist <- function(facility, user) {
    .Call('_maxcovr_nearest_facility_dist', PACKAGE = 'maxcovr', facility, user)
}

#' Calculate (vectorized) distance using haversines formula
#'
#' @param lat1 latitude from the first location
#' @param long1 longitude from the first location
#' @param lat2 latitude from the second location
#' @param long2 longitude from the second location
#'
#' @return distance in metres between two locations
#'
#' @export
spherical_distance_cpp_vec <- function(lat1, long1, lat2, long2) {
    .Call('_maxcovr_spherical_distance_cpp_vec', PACKAGE = 'maxcovr', lat1, long1, lat2, long2)
}
njtierney/copertura documentation built on Nov. 13, 2019, 6:37 p.m.