I have this NDVI image of eucalyptus trees. I've already been able to isolate the trees and extract the location.


Then I created the delaunay triangulation, turned it into lines, and then exploded to separate the lines and removed the duplicates.

What I want is to be able to join these pieces of lines so that they form a line in the same direction. As it is in yellow in the image below. I need to do this for the whole image.

enter image description here

I did using QGIS but any help using GRASS, SAGA, Postgis, python, etc, is welcome!


The process could be divided into two parts

  • Select the lines that will form the polylines (get rid of unnecessary lines).
  • Form the polylines.

The first part is the most delicate:
It is necessary to create a condition (or several), which must be able to be formalized mathematically in terms of Set theory, and which will decide whether a line should be selected or not.

The most practical approach, although probably the least robust, is that the condition be established in terms of azimuth ranges that the geometry must have to be selected.

I present an example of a set of lines purposely drawn for this answer, which were labeled with their corresponding azimuth. Labels are based on the expression: round( degrees( azimuth( start_point( $geometry), end_point( $geometry))), 1).

Two conflicting lines are selected:


Obviously, the azimuth depends on the direction (forward or backward) in which they were digitized. So the condition will be established over opposite azimuth ranges.

If a condition based on azimuth ranges can be established for all (or almost all) of the image, I would think that some conflicting lines that are selected in the first instance would not be a problem, since it would be relatively easy to manually delete them later.

In my case, since I do not want to select the 171.9 azimuth line, one of the edges of my ranges will be 170 degrees (and its opposite 350). The other edge I chose wide because I saw no drawbacks (100 degrees and its opposite 280).

Lower ranges would be more restrictive, but I would prefer to choose more lines (and then delete them), but that all the lines that interest me are selected. Likewise, in some iterations by trial and error, a convenient range can be determined. Also, what condition could I impose so that the 179.1 degrees azimuth line would not be selected if it were within my range? Of course there is an answer, but I don't know it.

I selected by the expression:

    ( ( azimuth( start_point ( $geometry), end_point( $geometry))) >= ( radians( 100)))
    ( ( azimuth( start_point ( $geometry), end_point( $geometry))) <= ( radians( 170)))
    ( ( azimuth( start_point ( $geometry), end_point( $geometry))) >= ( radians( 280)))
    ( ( azimuth( start_point ( $geometry), end_point( $geometry))) <= ( radians( 350)))

And exported selected features as a new layer.


Form polylines is much simpler now.

Note that the polylines must be topologically correct. Each line must start at the exact point at which another ends. By your procedure exposed in the question I have no doubt that this is so. But if necessary, you should clean them first with v.clean.

Polylines are formed with v.build.polylines.

Both GRASS tools are integrated to QGIS.

If any unwanted line has remained (has not been deleted before building the polylines), then three lines will come from one node, and the correct interpretation of the topology is that there will be three different polylines that share that node.

If so, eliminate the unwanted line (or polyline) and rebuild.

  • Thank you! It helped me a lot, that's what I was looking for! – hugonbg Jan 9 at 19:11
  • @hugonbg, you are welcome. I'm glad it helped. – Gabriel De Luca Jan 9 at 19:17

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.