2

I have thousand of points generated along river channels. I am trying to connect these points based on distance. I tried "Join attributes by nearest Points" and "geometry by expression" in QGIS. The method was mentioned here by Babel. It works somehow. However, there are many gaps between the line segments and some lines are repeated drew.enter image description here

How can I use QGIS to fill the gap and remove the repeated line segments?

10
  • As far as I can see, this solution should work: gis.stackexchange.com/a/382246/88814
    – Babel
    Dec 30 '20 at 0:09
  • Please decide whether it’s ArcMap, QGIS or Python that you wish to ask about in this particular question. If it’s Python then please include a code snippet that illustrates what you have tried and where you are stuck.
    – PolyGeo
    Dec 30 '20 at 0:13
  • As long as the question is closed, I can't add an answer, so please update your question (stating you're interested in a solution in QGIS) so that it can be reopened. Just to give a few ideas: 1. from the red lines, create start- and end points and use these to cretate a connecting line where you have gaps. 2. Repeated line segments: define a min/max value for the angle of your line to avoid this. 3. Can you use river date (e.g. OpenStreetMap)? You could snap your points to this line and try this: gis.stackexchange.com/a/382253/88814 (should work better with rivers than with streets).
    – Babel
    Dec 30 '20 at 11:08
  • 1
    I think part of the question (and resulting answer) is going to be "what do you want the output to look like"? --- Those straight line segments are probably not the exact course traveled. A moving average applied to each segment, followed by a curve fitting is probably more representative of the route taken; but you should be clear in your question if you want to preserve the error or beautify the output (at risk of introducing error).
    – Rob
    Dec 30 '20 at 17:23
  • 2
    Does this answer your question? Points from various sources to one line
    – Taras
    Dec 31 '20 at 18:38
2

Find a river centerline dataset or digitize your own.

Then use the processing steps:

enter image description here

Result: enter image description here

3
  • Thank you. The points are obtained from the google earth engine and I am trying to build river channel lines for global rivers. Therefore, I cannot digitize them manually. The existed global channel lines are simplified also.
    – Bo Wang
    Jan 1 at 0:22
  • Then download them, for example: overpass-turbo.eu/s/5ts, then pan to your area and press Run
    – BERA
    Jan 1 at 10:14
  • Thank you for the method. I tried it in the Model designer but the generated lines are in a mess. This is because the river has multiple channels separated by vegetated islands or channel bars in it. The centerlines downloaded from your supplied website are generalized into a single-channel which means there are no nearby extracted vertices for many points.
    – Bo Wang
    Jan 5 at 23:35
1

Let's suppose your points do not have an order attribute like an id or timestamp that would make it ease to connect the points accordingly (from 1 to 2 to 3 to 4 etc.). So I suppose your points are just randomly distributed all along the river with varying distances between them. I created such a points layer (see my first screenshot with the id as label) to demonstrate how to generate a connecting line based on location alone. There are five steps involved, including the Plugin Join multiple lines. Install it before you start from Menu Plugins / Manage and Install Plugins…. This plugin should do what you want to do, connecting the separate lines on your screenshot. Steps 1 to 3 generate such lines from a points layer.

  1. Menu Processing / Toolbox / Join attributes by nearest - set Maximum nearest neighbors to 1 only! Optionally, you can set a Maximum distance
  2. Menu Processing / Toolbox / Geometry by expression: select the output from above as input layer, for Output geometry type select line and as Geometry expression insert this expression: make_line ( make_point ( "feature_x" , "feature_y" ) , make_point ( "nearest_x" , "nearest_y" ) )
  3. Menu Processing / Toolbox / Delete duplicate geometries and set the output from 2 as input layer
  4. On the output layer from 3, select all features (I use Ctrl - A on my Windows machine, or click on the Select all icon in the Toolbar )
  5. Open/run the Plugin Join multiple lines (from Menu Vector): you get the connecting line you wanted, see screenshot:

enter image description here

enter image description here

1
  • Thank you for your time! Please see my result after following your steps. The river have multi-channels and this may cause a mess of the connection. I have more than 30000 lines in the vector, if I select all and do the "Join multiple lines", QGIS becomes no response after running a while. photos.google.com/share/…
    – Bo Wang
    Dec 31 '20 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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