Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dealing with sf geometry collections #585

Closed
see24 opened this issue Mar 24, 2022 · 1 comment
Closed

Dealing with sf geometry collections #585

see24 opened this issue Mar 24, 2022 · 1 comment

Comments

@see24
Copy link
Contributor

see24 commented Mar 24, 2022

Would it be possible to handle sf geometry collections in a way that preserves all the data? Or if not it would be great if there was a warning that data is being lost.

When I tried to convert an sf object with geometry type "GEOMETRYCOLLECTION" that contains points and lines to a SpatVector it appeared to work but the result only contained the lines.

It would be great if vect could detect that it was a "GEOMETRYCOLLECTION" and either produce a warning or maybe iterate over geometry types and then produce a SpatVectorCollection.

library(terra)
library(sf)

geom_col <- c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))),
  st_geometrycollection(list(st_multilinestring(list(matrix(11:16,3)))))) %>% 
  # list() %>% 
  st_sfc() %>% 
  st_sf()

plot(geom_col)

# convert to SpatVector
sv_geom_col <- vect(geom_col)

# Point is gone without warning
plot(sv_geom_col)

# SpatVectorCollection would seem like the right class for it but doesn't work with sf
svc(geom_col)
rhijmans added a commit that referenced this issue Apr 4, 2022
@rhijmans
Copy link
Member

rhijmans commented Apr 4, 2022

Thank you, I now get:

library(terra)
library(sf)
geom_col <- c(st_geometrycollection(list(st_point(1:2), st_linestring(matrix(1:6,3)))),
  st_geometrycollection(list(st_multilinestring(list(matrix(11:16,3)))))) %>% 
  st_sfc() %>% st_sf()

sv_geom_col <- vect(geom_col)
#Warning message:
#[SpatVector from sf] not all geometries were transferred, use svc for a geometry collection
 
s <- svc(geom_col)
s
# class       : SpatVectorCollection 
# length      : 2 
# geometry    : lines (2)
#               points (1)

Attributes are not transferred yet. I could use a more complex example of an sf object that contains a geometrycollection but also simpler features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants