4

I have this vector layer of lines between 2 nodes. I need to select all second entries that have the same length of the previous one. Can someone help me with this?

enter image description here

  • What is the end goal - what do you want to do with the selection? There may be tools that can eliminate the duplicates as opposed to just selecting them if that will work. Also related (and sort of a duplicate of): gis.stackexchange.com/questions/120041/… – Chris W Nov 6 '14 at 19:19
1

If you only want to select rows (leaving the geometry intact):
From your table I understand that "the row above" means an identical line in the reverse direction. One solution is to create two views on the data each of alternate rows, do a join of name_x2_y2 on name_x1_y1 and select where myLayer_copy_length_km = length_km.

First, if you ordered your table to achieve what I see in your question (it looks like you have ordered on Length), then you must make a version of your table that replicates this. To do this use MMQGIS->Modify->Sort. Next Create a new field (let's call it 'order') and set its value to rownum. Save your edit. Now highlight your layer and go Layer->Query. In the expression editor dialog type the following expression: "order" % 2 > 0. This gives you all the odd rows as a view. Right-click your layer and select Duplicate to make a copy in the layers list. In the copy, change the query statement to "order" % 2 = 0 to get all the even rows. Now go to your first layer and go Properties->Joins and make a new join of name_x2_y2 on name_x1_y1 (i.e. the 'to' and 'from' nodes for a pair of lines match between the odd rows and the even rows). Open the table and use an expression to select where myLayer_copy_length_km = length_km.

If you want to edit the data to have only one line between any pair of nodes
You could use Delete duplicate Geometries from the Processing Toolbox to delete the duplicates. Alternatively, as your lines only have 2 nodes, you can simply dissolve everything and then use v.split.vert from GRASS (Processing toolbox) with a max verts per segment set to 2 to break it all apart again. A slightly fancier version would be to dissolve on length_km and then do the split and this will preserve any lines where the length is not the same (though that presumes some difference between the length stated in the attributes and the actual line length for some reason).

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.