CoordInBounds: Determine if coordinate is in bounds, and if not, return...

View source: R/MapSites.R

CoordInBoundsR Documentation

Determine if coordinate is in bounds, and if not, return valid value

Description

Determine if coordinate is in bounds, and if not, return valid value

Usage

CoordInBounds(x, latitude)

Arguments

x

numeric four coordinates of bounding box in decimal degrees

latitude

logical vector of length four indicating whether each element in x is latitude or not (i.e. is longitude)

Details

A helper function designed to keep map bounds from using invalid coordinates (latitudes outside of -90 and 90; longitudes outside of -180 and 180). Will round values to nearest valid value. A more feature-rich approach could treat longitudes a little more carefully, where values outside the range are updated with the antimeridian in mind. For example, a longitude of 182 would become -178. However, drawing polygons that include the antimeridian are a nightmare, and since that is what will be done with this helper function, it will simply round down to 180.

Value

a copy of the original numeric vector of decimal degrees, x, with any invalid values (i.e. a latitude > 90) corrected to their closest valid value


jcoliver/lifeR documentation built on Feb. 14, 2025, 11:54 p.m.