poissonconsulting / subfoldr2

An R package to facilitate saving and loading objects, data, plots, numbers and strings
https://poissonconsulting.github.io/subfoldr2/
Other
2 stars 0 forks source link

`convert_sfc_to_coords()` errors when trying to convert line string to point #96

Closed aylapear closed 1 year ago

aylapear commented 1 year ago

test in save-load named "save df as gpkg with linstring column and sf point" is erroring because line string is not converted to points correctly.

data <- data.frame(
  Places = c("Yakoun Lake", "Meyer Lake"),
  Activity = c("boating", "fishing"),
  X = c(53.350808, 53.640981),
  Y = c(-132.280579, -132.055175),
  X2 = c(53.350808, 53.640981),
  Y2 = c(-132.280579, -132.055175)
)

sf <- convert_coords_to_sfc(data)
sf <- convert_coords_to_sfc(sf, coords = c("X2", "Y2"), sfc_name = "geometry2")
sf <- sf::st_cast(sf, "LINESTRING")
convert_sfc_to_coords(sf, "geometry2")

Error produced when convert_sfc_to_coords() ran on line string.

Error in scan(text = lst[[length(lst)]], quiet = TRUE) : 
  scan() expected 'a real', got 'IllegalArgumentException:'
Error in (function (msg)  : 
  IllegalArgumentException: point array must contain 0 or >1 elements

Based on implementation of convert_sfc_to_coords() it appears it should turn the line string into a set of points but errors at this point based on the sf cast function.