Closed latot closed 6 months ago
The function does work on an sfc column. Note that an sfc is a list. Please provide a repro if you think it does not work.
The function you are looking for also does exist:
pub fn sfc_to_geometry(x: List) -> Vec<Option<Geometry>> {
x
.into_iter()
.map(|(_, robj)| {
let geo = sfg_to_geom(robj);
match geo {
Ok(g) => Some(g.geom),
Err(_) => None
}
}).collect::<Vec<Option<Geometry>>>()
}
Hi! after check this, you are right, and there is some concerns about it.
When we parse a SF object to Rust, it is a List, which means each column is a Robj, so, with this we can parse from R to Rust a column, but we can't convert a SF object from Rust to Rust, there is no intuitive implementation of convert a Robj column to List again...
Would it be better use a Robj instead of a List as input to be able to be compatible from both places? (R2R and Rust2Rust)
I'm sorry, I do not follow the logic. You should use sf::st_geometry()
to get the geometry out of sf object. To get an Robj into a List you can use List::try_from(x).unwrap()
Or you can use geoarrow-r and arrow-extendr to extract everything as a recordbatch in arrow-rs. Then the geometry column can be iterated over using geo-types if you'd like.
Hi, the actual functions like
sfc_to_geom
works from a List, not from a sfc column, which is pretty weird... that would be somethingsf_to_geoms
.At the same point, would be great have a function for sfc, to convert a
sfc
(column) to aVec<Option<Geometry>>
.Thx!