If I understand correctly, there is not in attribute table anything that identifies the rivers by name or something. So keeping information from the table does not seem an issue either. Otherwise, maybe a spatial join could be tried to join that information afterwards.
This code with python
, geopandas
and shapely
's ops.linemerge should do the trick.
import geopandas as gpd
from shapely.ops import linemerge
def merge_lines():
lines_gdf = gpd.read_file("you_file.geojson") # or .shp or wathever
geometries = list(lines_gdf.geometry)
merged_lines = linemerge(geometries)
lines_dict = {}
for i, line in enumerate(merged_lines):
lines_dict[i] = gpd.GeoSeries({
'id': i,
'geometry': line
})
new_lines_gdf = gpd.GeoDataFrame(lines_dict)
new_lines_gdf.to_file("your_new_file.geojson", driver="GeoJSON")
dissolve
followed bymultipart to singleparts