line2points doesn't work if the geometry column isn't called geometry #358
Open
Description
Reprex of the problem
# packages
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(stplanr)
# create some fake data
my_sfc_linestring <- st_sfc(
st_linestring(matrix(c(1, 1, 2, 2, 3, 3), ncol = 2, byrow = TRUE))
)
my_sf_linestring <- st_as_sf(data.frame(ID = 1), geometry = my_sfc_linestring)
line2points(my_sf_linestring)
#> Simple feature collection with 2 features and 1 field
#> geometry type: POINT
#> dimension: XY
#> bbox: xmin: 1 ymin: 1 xmax: 3 ymax: 3
#> epsg (SRID): NA
#> proj4string: NA
#> id geometry
#> 1 1 POINT (1 1)
#> 2 1 POINT (3 3)
colnames(my_sf_linestring)
#> [1] "ID" "geometry"
# save data
st_write(my_sf_linestring, "my_sf_linestring.gpkg")
#> Updating layer `my_sf_linestring' to data source `my_sf_linestring.gpkg' using driver `GPKG'
#> Writing 1 features with 1 fields and geometry type Line String.
# read that same data
my_sf_linestring <- st_read("my_sf_linestring.gpkg")
#> Reading layer `my_sf_linestring' from data source `C:\Users\Utente\AppData\Local\Temp\RtmpEJviv4\reprex20fc24412f88\my_sf_linestring.gpkg' using driver `GPKG'
#> Simple feature collection with 1 feature and 1 field
#> geometry type: LINESTRING
#> dimension: XY
#> bbox: xmin: 1 ymin: 1 xmax: 3 ymax: 3
#> epsg (SRID): NA
#> proj4string: NA
line2points(my_sf_linestring)
#> Error in x_coords[o_indices] <- sapply(l$geometry, `[[`, 1): replacement has length zero
colnames(my_sf_linestring)
#> [1] "ID" "geom"
Created on 2019-11-05 by the reprex package (v0.3.0)
The problem lies here I think
Lines 388 to 391 in b2fd352
I can fill a PR in the next days.
Metadata
Assignees
Labels
No labels