10

I'm interested in computing a line graph for an input graph, preferably in GRASS since I'll be using other GRASS network analysis tools afterwards. I couldn't find any reference to line graphs in the GRASS docs. Is there a different term I should be using in my search or a hidden function that would create such a graph?

For context:

the line graph of an undirected graph G is another graph L(G) that represents the adjacencies between edges of G.

enter image description here

Source: http://en.wikipedia.org/wiki/Line_graph

5
  • 1
    This question is probably better posted in the grass-dev mailing list...
    – markusN
    Commented Jun 2, 2015 at 17:02
  • Thanks @markusN, done osgeo-org.1560.x6.nabble.com/…
    – underdark
    Commented Jun 2, 2015 at 17:48
  • 1
    The only reference I found within GRASS is the d.linegraph function, although the input must be numerical data. I know it's not much help but atleast we know there's something in GRASS that's related to line graphs :)
    – Joseph
    Commented Jun 3, 2015 at 9:20
  • Have I understood this correctly? You are looking for something like the opposite of PostGIS pgr_createTopology, where you already have the vertices but want instead to create the links described in terms of the two vertex ids? Could you parse a PostGIS vertex table to generate the network you're looking for?
    – Adrian
    Commented Jun 5, 2015 at 8:05
  • @Adrian Yes, vertices in the line graph can be identified by the two vertices in the input graph. The edges in the line graph represent the adjacencies between edges in the input graph. Maybe it would work with PostGIS as you describe, but if I have to implement something from scratch that wouldn't be my first choice.
    – underdark
    Commented Jun 5, 2015 at 13:03

1 Answer 1

3

If Python is okay, then there are some good Python modules that know about line graphs. One example is NetworkX (which I installed with simply sudo pip install networkx).

This is not a perfect answer since you need to write some glue code. First you would convert your input into NetworkX graph objects:

import networkx as nx
G = nx.Graph()
G.add_node( ... )
G.add_edge( ... )

Then you'd call the line_graph function get NetworkX to compute the line graph:

H = nx.line_graph(G)

And finally you would convert the result back to something useful by iterating over H.edges() and H.nodes().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.