Provided the following Polygons layer with 6 polygons (see image below), I would like to calculate each line's segment's angle (amongst other things), so I should convert those six polygons into lines, where each line should have only two vertices (start and end).

enter image description here

As far as I know (I am far from being an expert), I could do the following:

  1. Convert polygons into lines with Polygons to lines algorithm, which results into 6 closed lines with the same attributes as the polygons in Polygon layer.
  2. Split the lines into segments with GRASS' v.split and specify 2 as the maximum number of vertices in segments (see screenshot with the configuration I used) [EDIT: after Spacedman comment, I have discovered that I could also use Explode lines algorithm] [enter image description here]4

That would work if it weren't that I happen to have a vertex with id 38 (see first screenshot) which is redundant, as it breaks one line that does not have any other intersections nor angle's changes into two segments.

Is there any way to deal with such redundant vertices? (Of course, the image is just a sample of a much more complex layer with many more vertices like that and I cannot manually fix them).

I know I could use Simlify algorithm, but unfortunately, it would not solve my problems because currently only offers three ways of simplifiying:

  1. Distance-based: I cannot use this method, as the offending vertex is in the middle of the segment and far beyond any reasonable threshold. If I used that distance as threshold I would dramatically change the geometry with much worse negative effects.
  2. Snap to grid: I do not have any grid to snap vertices to
  3. Area: I cannot use it, as I am working with lines.

Surprisingly there's no method to fix vertices within a line where its neighbouring segments have the same azimuth angle, which would solve my problem.

From what I read, v.clean provides a tool called bpol which may be what I am looking for. From its manual:

bpol: break (topologically clean) polygons (imported from non topological format, like ShapeFile). Boundaries are broken on each point shared between 2 and more polygons where angles of segments are different

Unfortunately, I haven't succeeded in using it, and when I want to run the tool using Lines layer as input layer, I get unexpected results, as only 10 vertices are used as "slicing" vertices which result in 24 lines, many of them have several segments with different angles (see image below):

enter image description here

At this point I have two questions:

  1. Is there any other way to achieve what I want to achieve?
  2. Am I doing something wrong with v.clean (which, I have to admit that I have failed miserably on all my attempts to use v.clean inside QGIS 3.2 in Linux for other purposes)?
  • Have you tried simplifying the geometry using the Vector... Geometry Tools... Simplify tool? With the right threshold it will remove that vertex. Also you can use "Explode Lines" to turn lines with several segments into single-segment features. – Spacedman Sep 3 '18 at 14:16
  • thanks for pointing out this. Yes, I know I can use Simplify tool, but unfortunately, the vertex that is causing the problems is far beyond an acceptable threshold. If I were to use that distance, I would dramatically change the geometry. I did'nt know explode lines algorithm, but apparently gets the same result as v.split which would make things faster, but would not dramatically change results. – ccamara Sep 3 '18 at 14:45
  • I have updated my question after your comments. Thanks again for pointing out some key issues. – ccamara Sep 3 '18 at 14:52
  • "Simplify" using either "Distance" or "Area" won't change the geometry. Simplify is the GIS term for taking out redundant vertices in the middle of straight lines, which seems to be what you are trying to do. If you really have three vertexes in a straight line then simplify with distance tolerance = 0.01m will eliminate the middle one. – Spacedman Sep 3 '18 at 15:19
  • Sorry for not having answered before. You were right (I didn't try the "simplify" algorithm due to its description). If you want to add this as an answer, I will be more than happy to accept it. – ccamara Sep 17 '18 at 7:45

Your Answer

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

Browse other questions tagged or ask your own question.