stplanr
                                
                                 stplanr copied to clipboard
                                
                                    stplanr copied to clipboard
                            
                            
                            
                        Error in UseMethod("line2points") when using `stplanr::line_bearing`
Dear all,
I get this error when using stplanr::line_bearing with a spatial line object:
Error in UseMethod("line2points") : no applicable method for 'line2points' applied to an object of class "c('SpatialLinesDataFrame', 'SpatialLines', 'Spatial')"
I have a simple feature collection of LINESTRINGs (lines of 2 points each) and dimension XY, no CRS.
blank.ID                                 geometry
I want to calculate the bearing angle of each line.
foo <- foo %>% sf::as_Spatial()
bearing.deg <- stplanr::line_bearing(l = foo, bidirectional = TRUE)
Do you have a reproducible example? If you can provide code starting with reading in an open access dataset, or a dataset in stplanr, plus your expectation of what the result should find, that will help.
Here's my starting point, does this work as you expected?
library(stplanr)
?line_bearing
bearings_sf_1_9 <- line_bearing(flowlines_sf[2:5, ])
bearings_sf_1_9 # lines of 0 length have NaN bearing
line_bearing(flowlines_sf[2:5, ], bidirectional = TRUE)
See here for full documentation: https://docs.ropensci.org/stplanr/reference/line_bearing.html
sf::as_Spatial() creates an sp class object. The error is emitted because line2points() is an s3 generic. line_bearing() is not designed to be used with sp objects. This can probably be closed as designed.
Agreed, and yes, support for sp was phased out quite a while ago. Closing :tada: