I have a stream network and I want to convert it in graph like data structure, for which I need to have precise set of FROM and TO vertices.The geometry of stream network is not correct i.e. the stream segments are not split at intersection on stream network.So, I have to merge the degree two nodes in the network so that my network will have only 1 and 3 degree vertices. The label in the figure represents the stream vertex id and degree of the vertex (ID-Degree) . The degree is the total amount of incoming or outgoing edge in the network.I have two shape-files, one is point layer having vertex ID and degree of each vertex and other is stream network having TO and FROM attributes for each edge but with degree 2 vertex as well which is to be eliminated.
I want it to convert as below.
My approach:- For each edge , I will check the degree of the respective vertex ( assuming any starting vertex) and if the degree is not either 1 or 3 (degree greater than 3 is not expected) then the respective edge is merged and the iteration continues else the next vertex pair is considered.
I think there must be a easier way available as a plugin or Postgres/Postgis based query,please point out to any such tool or modified approach to achieve the same.