
Find points within a circle around a center coordinate
Source:R/points_in_circle.R
points_in_circle.Rd
This function selects rows from a data frame whose longitude/latitude coordinates fall within a given radius (in meters) from a specified center point. It also calculates the distance of each point to the center.
Usage
points_in_circle(
data,
lon_center,
lat_center,
lon = lon,
lat = lat,
radius = 200,
sort = TRUE
)
Arguments
- data
A data frame containing at least longitude and latitude columns.
- lon_center
Numeric scalar, longitude of the circle center.
- lat_center
Numeric scalar, latitude of the circle center.
- lon
Name of the longitude column in
data
.- lat
Name of the latitude column in
data
.- radius
Numeric, circle radius in meters. Default is 200.
- sort
Logical, if
TRUE
(default) results are sorted by distance from the center (closest first). IfFALSE
, the order ofdata
is preserved.
Value
A data frame subset of data
with an extra column
distance_m
giving the distance to the center point.
Examples
points_in_circle(Groningen, lon_center = 6.571561, lat_center = 53.21326,
radius = 60)
#> # A tibble: 3 × 10
#> street number letter suffix postal_code city lon lat amount distance_m
#> <chr> <int> <chr> <chr> <chr> <chr> <dbl> <dbl> <dbl> <dbl>
#> 1 Heresing… 5 NA NA 9711EP Gron… 6.57 53.2 5 31.4
#> 2 Heresing… 11 NA NA 9711ER Gron… 6.57 53.2 11 47.8
#> 3 Zuiderpa… 1003 NA NA 9724AK Gron… 6.57 53.2 1003 57.6