geovctrs
geovctrs copied to clipboard
draft geovctrs_triang
Very draft attempt at a geovectrs_triang
analogous to geovectrs_rect
.
I see this as a very complementary addition to the set in geovctrs currently, it's harder than I thought - I have faked the casting to wkb and wkt, by cheating with a geo_xy
to capture the coordinates, and I don't pass the expectations when it comes to geo_collection. (A great lesson for me so far though!)
Is this of interest? I expect it's fairly easy for you to fold this in, but I guess there's a bit of C++ for the bbox/envelope stuff (or am I missing this at the vctrs level).
(This is compelling to me because the rgl::mesh3d
type can be expressed as rect and or triangle primitives in exactly this way, and this would be a very powerful and efficient tool a nice intermediate between the rgl compact form that we can use in mapdeck and anglr, and necessarily expanded form required by sf - oh and with your xyz work we basically have an unheard of superpower for merging vector and raster ...).
library(geovctrs)
## three corners to every triangle, x0,y0 x1,y1 x2,y2 as 6 input vectors
x <- geo_triang(x0 = 0:5, y0 = 0:5, x1 = 2:7, y1 = 1:6,
x2 = 1:6, y2 = 2:7)
x
<geovctrs_triang[6]>
[1] (0 0...2 1)...1 2) (1 1...3 2)...2 3) (2 2...4 3)...3 4)
[4] (3 3...5 4)...4 5) (4 4...6 5)...5 6) (5 5...7 6)...6 7)
My fakey approach passes some expectations, but not these ones:
# must be combinable with wkb, wkt, and collection
testthat::expect_silent(vec_c(geo_wkb(), x))
testthat::expect_silent(vec_c(geo_wkt(), x))
testthat::expect_silent(vec_c(geo_collection(), x))
# must be reverse combinable with wkb, wkt, and collection
testthat::expect_silent(vec_c(x, geo_wkb()))
testthat::expect_silent(vec_c(x, geo_wkt()))
testthat::expect_silent(vec_c(x, geo_collection()))
I fleshed out the "easy way" here: https://github.com/hypertidy/silicate/wiki/geovctrs-for-TRI