Learn R Programming

spatialrisk (version 0.7.3)

concentration: Concentration calculation

Description

Calculates the concentration, which is the sum of all observations within a circle of a certain radius.

Usage

concentration(
  sub,
  full,
  value,
  lon_sub = lon,
  lat_sub = lat,
  lon_full = lon,
  lat_full = lat,
  radius = 200,
  display_progress = TRUE
)

Value

A data.frame equal to sub with an additional numeric column

concentration containing the summed values from full.

Arguments

sub

A data.frame of target points for which concentration risk is calculated. Must include at least columns for longitude and latitude.

full

A data.frame containing reference points. Must include at least columns for longitude, latitude, and the value of interest to summarize.

value

Column name in full containing the values to be summed.

lon_sub

Column name in sub for longitude (default: lon).

lat_sub

Column name in sub for latitude (default: lat).

lon_full

Column name in full for longitude (default: lon).

lat_full

Column name in full for latitude (default: lat).

radius

Numeric. Radius of the circle in meters. Must be positive (default: 200).

display_progress

Logical. Whether to display a progress bar (TRUE/FALSE). Default is TRUE.

Author

Martin Haringa

Details

This function uses a C++ backend for efficient distance calculations (Haversine formula). For each point in sub, it finds all points in full within the specified radius and sums their value.

Examples

Run this code
# Target points
sub <- data.frame(location = c("p1", "p2"),
                  lon = c(6.561561, 6.561398),
                  lat = c(53.21369, 53.21326))

# Reference points with values
full <- data.frame(lon = c(6.5614, 6.5620, 6.5630),
                   lat = c(53.2132, 53.2140, 53.2150),
                   amount = c(10, 20, 15))

# Calculate concentration within 100 meters
concentration(sub, full, value = amount, radius = 100)

Run the code above in your browser using DataLab