Skip missing/non-finite coordinates when encoding, with a warning - #56
Open
neon-ninja wants to merge 1 commit into
Open
Skip missing/non-finite coordinates when encoding, with a warning#56neon-ninja wants to merge 1 commit into
neon-ninja wants to merge 1 commit into
Conversation
Coordinates containing NA, NaN or Inf values previously went through an undefined double -> int cast in encode_polyline(), corrupting the whole polyline with out-of-range characters (bytes below 63 and above 127) that decode() could not even parse. Empty sf POINTs (whose coordinates are NaN) silently encoded as "??", which decodes to the real coordinate (0, 0). Such coordinate pairs are now skipped during encoding and a warning reports how many were dropped. With encode(byrow = TRUE), rows with missing coordinates return NA instead (which decode() already maps back to NA coordinates). Also documents the previously undocumented `precision` argument of decode(). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UYymBnTDZbXyuus9FY97pd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
encode()passed NaN coordinates through an undefineddouble -> intcast inencode_polyline()(src/googlePolylines.cpp). On x86 the cast yieldsINT_MIN, so a NaN pair emitted invalid polyline characters (bytes outside the valid 63–126 range, e.g.0f ce 76 d7) and — because the format is delta-based — corrupted every subsequent point too.decode()on such a string threw a raw C++ exception (basic_string::at: __n >= this->size()). R'sNA_real_is a NaN at the C level, soNAtriggered the same behaviour. Relatedly, emptysfPOINTs (whose coordinates are NaN) encoded as"??", which silently decodes to the real coordinate (0, 0).Changes
encode_polyline()now skips coordinate pairs where lon or lat is not finite (NA/NaN/Inf); every entry point (encode(),encodeCoordinates(), thesf/sfcpath) warns with a count of pairs that could not be encoded.encode(byrow = TRUE)returnsNAfor such rows instead of skipping (anddecode()already mapsNAstrings back toNAcoordinates).sfPOINTs now encode to""(with the warning) instead of"??"/(0, 0); the test pinning the old behaviour was updated.RcppExportsregenerated withRcpp::compileAttributes(); roxygen docs updated (including the previously undocumentedprecisionargument ofdecode()) and man pages regenerated.NA/NaN/Infinputs,byrow, and empty points; NEWS entry; version bumped to 0.8.8.9000.Testing
Full testthat suite (with
NOT_CRAN=true): 161 pass, 0 fail.R CMD check(no vignettes/manual) shows nothing beyond pre-existing environment notes.🤖 Generated with Claude Code
https://claude.ai/code/session_01UYymBnTDZbXyuus9FY97pd
Generated by Claude Code