get_closest_bins: Given lat/lon, find closest bin(s)

View source: R/matchup_funcs.R

get_closest_binsR Documentation

Given lat/lon, find closest bin(s)

Description

If you have a dataframe of longitudes and latitudes, find the closest bin numbers from NASA's 4km or 9km-resolution L3b (level-3 binned) files.

Usage

get_closest_bins(
  geo_df,
  bin_df,
  measure = "geodesic",
  max_bins = 100,
  radius = Inf
)

Arguments

geo_df

Dataframe with numeric columns longitude, latitude

bin_df

Dataframe with numeric columns bin, longitude, latitude (created using the bin, lon, lat vectors in this package, see details)

measure

Algorithm to use for distance calculation, see "measure" in ?geodist::geodist

max_bins

Maximum number of closest bins to return (<= 100)

radius

Maximum distance between lat/lon pair and bin lat/lon (in metres)

Details

Bin/lat/lon data can be retrieved using the get_bins() function (see examples).

Value

geo_df dataframe with new columns "dist" (distance to closest bin(s), in metres), "bin" (closest bin number(s)), and bin_latitude/longitude

Examples

geo_df <- data.frame(latitude=c(43.76299,43.6579,43.47346,51.83278,52.19771,60.32528,60.19208,52.28504,52.06484,44.6917,47.46267),
                     longitude=c(-62.7525,-62.6464,-62.45467,-46.45183,-45.65968,-48.6459,-48.68755,-53.53753,-54.30495,-63.6417,-59.95133),
                     stringsAsFactors = FALSE)
# note that this example is using a bin grid restricted to the Northwest Atlantic (NWA),
# so if any points in geo_df are near the edge of the grid, they might have fewer matching bins
bin_df <- get_bins(region="nwa", resolution="4km", variables=c("bin","latitude","longitude"))

# get closest bins within 10km, limited to the 50 closest bins
closest_bins <- get_closest_bins(geo_df=geo_df, bin_df=bin_df, max_bins=50, radius=10000)
head(closest_bins)


BIO-RSG/oceancolouR documentation built on April 30, 2024, 7:54 a.m.