
Convert a clip polygon to a flat data frame for storage
Source:R/clip_to_dataframe.R
clip_to_dataframe.RdInternal helper that converts a polygon (as SpatVector, sf, or anything
terra::vect() accepts) into a flat data frame suitable for serializing
inside a BirdFlow object's metadata. The data frame has columns
id (polygon / object index), part (ring group within polygon), x,
y (vertex coordinates), and hole (integer ring index: 0 for the
outer ring of a part and 1..N for each distinct hole ring within the
same part). The schema mirrors the matrix that terra::vect() accepts
when type = "polygons", which is what dataframe_to_clip() uses to
round-trip the polygon back into spatial form.
Arguments
- clip
A polygon, in any form accepted by
terra::vect().
Details
Storing the polygon as plain columns avoids serializing terra/sf objects
(which hold C++ pointers / environments and don't survive saveRDS() or
HDF5 round-trips reliably).
Earlier versions of this code stored hole as a logical, which collapsed
multiple holes within one part into a single ring on round-trip; the
integer index keeps each hole distinct.
See also
dataframe_to_clip() for the inverse.