Hi,

Finally, Barry came up with a solution.
http://r-sig-geo.2731867.n2.nabble.com/shortest-path-td7580832.html

I used his solution to take into account additional points, extra nodes.

For this, I connected points to their nearest point on the segment with
project2segment function. Then, I rebuilt the graph.

What I'd like to do next is assigning a diffferent attribute to nodes that
were extra vertexes using a column from the points dataset. They can be
shops, particular events, etc...

buildTopo <- function(lines, pts){
  require(rgeos)
  require(igraph)
  require(spatstat)

  # PROJECTION TO SEGMENT
  froms2 <- as(pts,"ppp")
  tos2 <- project2segment(froms2, as(lines, "psp"))$Xproj
  bb <- union.owin(bounding.box(froms2), bounding.box(tos2))
  connectLines <- as(psp(froms2$x, froms2$y, tos2$x, tos2$y, window=bb),
"SpatialLines")
  IDs <- sapply(connectLines@lines, function(x) paste("connect", x@ID,
sep="_"))
  connectLines <- spChFIDs(connectLines,IDs)
  proj4string(connectLines) <- proj4string(lines)

  # MERGING LINES
  Lines <- spRbind(lines, connectLines)

  # LINEAR NETWORK
  g = gIntersection(Lines,Lines)
  edges = do.call(rbind,lapply(g@lines
[[1]]@Lines,function(ls){as.vector(t(ls@coords))}))

  # LENGTH CALCULATION
  lengths = sqrt((edges[,1]-edges[,3])^2+(edges[,2]-edges[,4])^2)

  # GRAPH
  froms = paste(edges[,1],edges[,2])
  tos = paste(edges[,3],edges[,4])

  graph = graph.edgelist(cbind(froms,tos),directed=FALSE)
  E(graph)$weight=lengths

  return(graph)
}

Best,

Mathieu


2012/8/13 Mathieu Rajerison <mathieu.rajerison@gmail.com>

> Hi,
>
>
> Considering a linear network, how can I generate a graph of it that I
> could use in igraph? So that I could perform shortest paths and other
> calculations...
>
> The vertexes would be the intersections of lines.
>
>
> Thanks
>
> Mathieu
>

	[[alternative HTML version deleted]]

