I used the function landgenreport from the package popgenreport in R to create an object result.
This object is a list with various objects including SpatialLines class objects. I am trying to write these lines to a file readable in GIS software such as ArcGIS or QGIS. The problem is that I can not find a way to do that. I've tried several functions from several packages and I always get an error.
library(raster) library(rgdal) library(sp) library(maptools) results$leastcost$paths[][] #this is the specific SpatialLine linha78<-results$leastcost$paths[][] writeSpatialShape(linha78,"linha78.shp") Error in writeSpatialShape(results$leastcost$paths[][],"linha78.shp"):x is aSpatialLinesobject, not a compatible Spatial*DataFrame
So I tried to transform the SpatialLines object to a SpatialDataFrame and got another error message.
x = data.frame(linha78) Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class "structure("SpatialLines", package = "sp")" to a data.frame
I've tried a lot a different possible solutions I read here and there, but it simply does not work. As such: