I have a data.frame object which I can easily convert to a spatialpointdataframe then convert that to a spatiallinesdataframe but then when I tried to cover to a as.linnet it does not read marks
X Y roadID
1 177321.3 3378163 1
2 177321.4 3378168 1
3 177321.4 3378168 1
4 177321.5 3378177 1
5 177321.5 3378186 1
6 177321.5 3378195 1
then I make this data.frame to a SpatialPointsDataFrame
coordinates(roaDF1) <- c("X","Y")
proj4string(roaDF1)=proj4string(trtrtt)
class : SpatialPointsDataFrame
features : 100412
extent : 143516.4, 213981, 3353367, 3399153 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
variables : 1
names : roadID
min values : 1
max values : 347
then using SpatialPointsDataFrame to convert a SpatialLinesDataFrame ( found this code online )
LineXX <- lapply(split(roaDF1, roaDF1$roadID), function(x) Lines(list(Line(coordinates(x))), x$roadID[1L]))
linesXY <- SpatialLines(LineXX)
data <- data.frame(roadID = unique(roaDF1$roadID))
rownames(data) <- data$roadID
lxy <- SpatialLinesDataFrame(linesXY, data)
proj4string(lxy)=proj4string(trtrtt)
now lxy looks like this
> lxy
class : SpatialLinesDataFrame
features : 347
extent : 143516.4, 213981, 3353367, 3399153 (xmin, xmax, ymin, ymax)
crs : +proj=utm +zone=17 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
variables : 1
names : roadID
min values : 1
max values : 347
finally I want to concert this lxy to a linnet object
> W3.orig=as.linnet(lxy)
Warning messages:
1: In spatstat::linnet(vertices = V, edges = edges, sparse = TRUE) :
edge list should not join a vertex to itself; ignored
2: In as.linnet.SpatialLines(lxy) :
Internal error: could not map data frame to lines
it is not because roaDF1 has 100421 features when I make it 20K it still gives the same error.
Any help ?