4

I have a MultiLine String that is straight but when I highlight vertices, I notice that it has 10 vertices - some vertices also overlap. When I covert this multipart line to singlepart, the line still has 10 vertices.

I would like to simplify this line (which has one single id) to have only one a start and end point.

I have tried dissolving the line, fix geometry and simplify and can't seem to remove the unwanted vertices

Line Vertices

5
  • You only have one line?
    – Bera
    Commented Feb 25, 2022 at 16:46
  • this is just a subset for an example of a larger dataset
    – user201402
    Commented Feb 25, 2022 at 16:48
  • Can you post a new image with the vertices numbered by their order? There are some results returned from the Plugins manager if you search on Topology but I do not have experience with these. Of course, if all else fails there is a Python solution. Maybe extract the vertices from the lines, generate minimum enclosing circles around the vertices, select the vertices that intersect the circle and rebuild the lines.
    – GBG
    Commented Feb 25, 2022 at 17:38
  • 1
    Is it actually a single LineString, or a series of LineStrings, as in this question. If it is the former, please include details about parameter settings of the methods you tried. For instance, what was the Simplification method and Tolerance in Simplify?
    – Matt
    Commented Feb 25, 2022 at 17:48
  • It is a single LineString. I have tried dissolve by ID and simplify with a tolerance of .001 in meters. The issue with going any higher for tolerance is that this is part of a much larger dataset and I do not want to simplify other geometries to a great extent. I am trying to detect straight lines related to this post and believe that the vertices are causing issues: gis.stackexchange.com/questions/424762/…
    – user201402
    Commented Feb 25, 2022 at 18:25

1 Answer 1

2

You can use the following expression to eliminate all vertices from a line that deviate for a maximum distance from the direct line connecting the start- and end-point of a line. Use Geoemtry Generator or Geometry by expression (see here for details).

  • The expression evaluates for each vertex of the initial line, except for start- and end-point, if a buffer of distance x (here: 50 on line 20, change this value to fit your needs) intersects the direct line connecting start- and end-point.

  • If so, the output is an empty element, otherwise the output is the respective vertex as a point geometry.

  • So for each vertex, these outputs are collected in an array and then the array is filtered to retain only elements > 0. You get an array than only contains points.

  • These ponints represent the vertices further away from the line connecting start- and end-point than the distance you defined.

  • Add start- and end-point of the initial line at the beginning and end of the array and convert the array to a line and here you are!

make_line (
    array (
        start_point ($geometry),
        collect_geometries (
            array_filter (
                array_foreach (
                    generate_series (2, num_points( $geometry)-1),
                    case
                    when        
                        intersects (
                            make_line (
                                start_point ($geometry), 
                                end_point ($geometry)
                            ),
                            buffer (
                                point_n (
                                    $geometry, 
                                    @element
                                ), 
                                1  -- change this distance
                            )
                        ) = 0
                    then point_n ($geometry, @element)
                    end
                ),
                @element>0
            )
        ), 
        end_point ($geometry)
    )
)

Black line with initial vertices (red dots) as well as the vertices of the line created by the expression above in blue (adding a nodes_to_points() function to the expression) - as you can see, just 2 vertices (start- and end-point) remain: enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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