dcooley / geometries

R package for creating and manipulating geometric data structures
https://dcooley.github.io/geometries/
Other
28 stars 2 forks source link

class attributes #7

Closed dcooley closed 4 years ago

dcooley commented 4 years ago

https://github.com/paleolimbot/geovctrs/issues/8#issuecomment-656407607

Any chance that the class arg could be a generic list of attributes? Like...list(class = "something", dim = "XYZ")?

paleolimbot commented 4 years ago

So prompt!

I think that would make it possible to create sf (or wksxp, although I really should make that format align more closely with sf) without any looping over afterward to set more attributes. sf does this all with class, but wksxp does it slightly differently to make the parsing code cleaner.

lapply(sf::st_sfc(sf::st_point(c(1, 2, 3))), attributes)
#> [[1]]
#> [[1]]$class
#> [1] "XYZ"   "POINT" "sfg"
lapply(unclass(wk::as_wksxp("POINT Z (1 2 3)")), attributes)
#> [[1]]
#> [[1]]$dim
#> [1] 1 3
#> 
#> [[1]]$class
#> [1] "wk_point"
#> 
#> [[1]]$has_z
#> [1] TRUE

Created on 2020-07-09 by the reprex package (v0.3.0)

dcooley commented 4 years ago

I think that would make it possible to create sf

sf only needs the StringVector class for each individual sfg geometry. So this current implementation is fine for making sfg, then sfc, then sf objects as-is. But I agree it would be better to make this more generic and accept a list of attributes.

To clarify, the make_geometries() function makes individual geometries (i.e, sfg) for each level-1 ID. Then the list that all those sfgs are contained in is the sfc