You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to work around the lack of serialization support (#259) by converting s2 geography data into other formats (such as using simple features or wkb), but the data can get corrupted under certain circumstances. That is, doing s2_as_geography(st_as_sfc(g)) or s2_as_geography(s2_as_binary(g)) is not guaranteed to recover the original data.
Consider the following example from real-world code:
Unfortunately, I cannot provide an MRE because I do not know how to accurately persist s2 geography data. In the cases I am dealing with, it seems to be a precision issue when converting the data between various formats. The affected geographies have some points that are very close by, and it appears that these are detected as duplicates when the data is converted back to s2. While I can fix this by running s2_simplify(), it would be good to have a way to persist the data as is.
The text was updated successfully, but these errors were encountered:
We store s2 geometries as pointers to C++ structures for performance reasons. This is usually OK since s2 is most commonly used as an intermediary format (usually the start and end is an sfc). This is usually OK but, as you've found out, it is not possible to serialize it using serialize().
The issue you're seeing here is I think because S2's internal representation is a unit vector (e.g., 3 doubles), whereas the WKB export and import by default take the more ubiquitous longitude/latitude. The conversion between those is slightly lossy and looses a tiny bit of precision (in your case enough to trigguer a difference!).
It is possible to override this projection but it's not obvious how to do this. I've pasted an example below which may help!
I am trying to work around the lack of serialization support (#259) by converting s2 geography data into other formats (such as using simple features or wkb), but the data can get corrupted under certain circumstances. That is, doing
s2_as_geography(st_as_sfc(g))
ors2_as_geography(s2_as_binary(g))
is not guaranteed to recover the original data.Consider the following example from real-world code:
Unfortunately, I cannot provide an MRE because I do not know how to accurately persist s2 geography data. In the cases I am dealing with, it seems to be a precision issue when converting the data between various formats. The affected geographies have some points that are very close by, and it appears that these are detected as duplicates when the data is converted back to s2. While I can fix this by running
s2_simplify()
, it would be good to have a way to persist the data as is.The text was updated successfully, but these errors were encountered: