This script corrects all nodes in a river network which have more than 2 streams flowing to them. The outermost streams' end vertices are adjusted by step
meters along the downgoing stream. New nodes are created at suitable places, and existing lines suitably split. This is useful for correcting river networks before using network analysis tools which don't allow complex confluences, such as STARS
Requires a line shapefile with the proper FROM_NODE and TO_NODE fields. The file is assumed to be correct in all other aspects, there is no error checking, so carefully check the result.
streams=readOGR("streams_Pt.shp","streams_Pt")
correctedshp=fix.streams(streams,step=10)
writeOGR(correctedshp,"streams_corrected.shp","streams_corrected","ESRI Shapefile")