10

I have a map that I have digitised and converted to a vector layer (the rivers only). The problem is that the vectorisation has produced a large number of segments for each river, that show up as different features (each may have multiple straight line segments, but they do not cover whole rivers). What I am looking for is a tool to merge into one feature (a polyline, I guess) all the segments whose extremes are within a given distance. I am using QGis, and the GRASS plugin. I have tried v.clean.snap, v.build.polylines, but did not yet manage to actually merge the lines. Any help would be very appreciated!

Gavin Simpson
  • 170,508
  • 25
  • 396
  • 453
LittleFish
  • 789
  • 3
  • 10
  • 15

7 Answers7

7

You can do it using GEOS library in your programming language and maybe also commandline. In my case, I was doing it in R, using rgeos library:

require(rgdal)
require(rgeos)
lines <- readOGR("f:/dir", "itineraris")
# grouping line features by lines$ITINERARI
lines2 <- gLineMerge(lines, byid = lines$ITINERARI, id = lines$ITINERARI)
writeOGR(lines2, "f:/dir", "itineraris_merged", driver="ESRI Shapefile")

Be careful: from the note in the documentation "specifically it joins line segments with intersecting end points" it seems that the line features must be consecutive - however it is not clear whether this applies also to case when you merge by IDs.

Tomas
  • 57,621
  • 49
  • 238
  • 373
5

I'd suggest selecting the line parts manually and then using the "merge" tool (located in advanced editing toolbar).

You might also want to ask such questions over at http://gis.stackexchange.com

underdark
  • 1,146
  • 7
  • 22
  • 1
    Thanks, but I have a few hundred such situations, and I must repeat for 133 maps...... I guess I really need to get at a plugin for this. Any suggestions where I could start looking? – LittleFish Mar 24 '12 at 07:28
4

A very late answer that could be useful to other people :

I faced the same issue and I developed a QGIS plugin to solve it. It automatically merges multiple connected lines (i.e. lines that share an endpoint) into a smaller set of longer lines. The output layer type is Line, not PolyLine. Merging can be based on one of these two criteria:

  • Length: a segment is merged to its longest neighbor.
  • Alignment: a segment is merged to its best aligned neighbor. I think this criterion is the most suitable for a river network.

This plugin is called MergeLines (full documentation here), you can find it in the public QGIS repo. Work is still in progress, don't hesitate to suggest new functionalities.

ArMoraer
  • 169
  • 1
  • 7
3

For anyone else stumbling upon this question:

You can use the Roadgraph plugin ( Shortest Path ) or the PointsToRoute script. Choose points at either end ( or in the case of Points2Route add extra points to specify from multiple paths ) and then export to it's own layer.

As far as the 133 maps goes.. I've modified the PointsToRoute script for a similar heavy-duty situation to automatically step through a layer of lines and find routes between their endpoints. I'll clean it up and see if I can publish it on github soon.

PointsToRoute: https://github.com/anitagraser/QGIS-Processing-tools/blob/master/1.1/scripts/points_to_route.py

ShortestPath (Roadgraph): This is enabled by the QGIS plugins manager. Be aware that in newest versions of QGIS it is configured by the Vector->RoadGraph->Settings menu despite the plugin referring to itself as "Shortest Path".

JJones
  • 802
  • 7
  • 7
1

You can use the magnet icon Join 2 lines QGIS (enable snapping) to join 2 vertex of different polylines. It's a manual process, so it's useful if you want to join a couple of lines:

  1. Click on the pencil icon to edit the line
  2. Click on the vertex editor
  3. Click on the magnet icon (enable snapping).

Now, click on the last vertex of a line, and get the mouse closer to the vertex that you wish to join (QGIS will mark it in pink).

Join 2 lines

After you have joined the line, remember to use the dissolve tool to merge attributes, so that only one row on the attribute table remains.

Erik Martín Jordán
  • 4,332
  • 3
  • 26
  • 36
0

Use "snap geometry to layer" in the toolbox

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 11 '23 at 17:05
-6

You can use the "DISSOLVE" tool (ARC TOOLBOX). This will merge them all into one segment.

Then you can export the nodes (regular only), this being the points of intersection.

Then you can split the dissolved line feature with the nodes. This will at least provide you with a vector feature split at only the intersecting points.

At least it is a step further.

Jason
  • 2,503
  • 3
  • 38
  • 46
LANA
  • 1