Skip to contents

Tests longitude/latitude pairs for the two ways a position can be unusable: not a number at all, or outside the range it is meant to occupy.

Usage

valid_coordinates(longitude, latitude)

Arguments

longitude, latitude

Numeric vectors of equal length.

Value

Logical vector, TRUE where the pair is a position H3 can be given.

Details

h3jsr::point_to_cell() fails in opposite directions on the two, and the quiet one is the more damaging.

A non-finite coordinate (NA, NaN, Inf) raises Latitude or longitude arguments were outside of acceptable range, which aborts the entire run — a single bad ping in a batch of millions, and nothing is written, because the aggregation state is only uploaded at the end.

An out-of-range finite coordinate raises nothing at all. Despite the wording of that error, H3 does not reject these: it wraps them and returns a perfectly ordinary-looking cell. Latitude is where this does damage, because the wrap is not a wrap at all — it reflects over the pole and swings longitude by 180°. Measured at resolution 9, a point off the Tanzanian coast with a corrupt latitude of 91 comes back as a cell at 89°N, 141°W, in the Arctic Ocean some 10,000 km away; a latitude of 900 lands in the mid-Pacific. Either would enter the grid as a real hexagon carrying real fishing hours, with no error and no log line to explain it.

Longitude out of range is the harmless case — longitude is genuinely cyclic, so 181° resolves to 179°W, which is the correct point. It is rejected anyway: a device reporting outside ±180 is reporting something wrong, and the value being recoverable is not a reason to trust the rest of that ping.