dcooley / sfheaders

Build sf objects from R and Rcpp
https://dcooley.github.io/sfheaders/
Other
74 stars 5 forks source link

CAST error #67

Closed dcooley closed 4 years ago

dcooley commented 4 years ago

The final column names are incorrect (using geometry as the column)

df <- data.frame(
    id = c(1,1,1,1,2,2,2,2)
    , x = rnorm(8)
    , y = rnorm(8)
)

sf <- sfheaders::sf_multipoint(df, "x", "y", multipoint_id = "id")

sf <- cbind( sf, sf )
sf <- setNames( sf, c("id1","geometry","id2","geometry.1"))

origin <- c("geometry")
destination <- c("geometry.1")

attr( sf, "sf_column" ) <- origin
sf <- sfheaders::sf_cast( sf, "POINT" )

but it works when the geometry is not geometry

df <- data.frame(
    id = c(1,1,1,1,2,2,2,2)
    , x = rnorm(8)
    , y = rnorm(8)
)

sf <- sfheaders::sf_multipoint(df, "x", "y", multipoint_id = "id")

sf <- cbind( sf, sf )
sf <- setNames( sf, c("id1","geometry","id2","geometry.1"))

origin <- c("geometry")
destination <- c("geometry.1")

attr( sf, "sf_column" ) <- destination
sf <- sfheaders::sf_cast( sf, "POINT" )