A line-simplifying and line-rectifying tool
Transcript of A line-simplifying and line-rectifying tool
Simplifying & Rectifyinga SHP Linestring Layer
While I was interested in my ideas about 3D data in QGIS I met the contour lines....
by Giuliano Curti (giulianc51 at gmail dot com)Gennaio 2014
v. 2014-02-01
my initial intention was to clean the lines (obtained from DEM) from the flurry of points;
when I planned this script I did not know that the job were already possible in QGIS with the help of fTools;
I knew even less about the Ramer-Douglas-Peucker algorithm used by fTools.
At the discovery of my error, reported to me by a friend of the Italian GFOSS mailing list, I wanted to compare my game
procedure with that of fTools, finding that my script behaved well all things considered: in one test case my script was
cleaning the lines from the original 46k vertices at only 10711, compared to 10716 of QGIS / fTools.
5 out of 11k are almost a trivial problem, even though I was intrigued so I wanted to investigate;with the help of Spatialite I have identified 5 points
that appeared in fTools and not in my result;some points were caused by different threshold
used, but other do not and I discovered something interesting:
a small flaw in the RDP algorithm !look at the next slide:
this point is not necessary for the definition of the line that is in that stretch rectilinear and uniquely
defined by the initial vertex and the final one;
this is the result of my script (as you can see, the only preserved vertices are those
essential to the definition of the line)
If I may hazard a guess, is the central point(*) to be critical: if this is far from the line joining the start point - end point, as evident in the first case, it is still preserved, although a subsequent analysis
could be eliminated.
I do not have enough mathematical skills to do an analysis of the problem and probably I can not even speak of error, because the
final result is correct, in fact the RDP algorithm provides a line similar to the original one, certainly simplified;
perhaps what we can say is that this solution is not optimal, since in some cases, such as those seen above, leaves vertices
unnecessary to define the line.
(*) more precisely, the center point of each portion of the line.
One more note:analyzing the problem it happens that the vertex 2 has the greater distance from the base line 0-4, therefore
becomes one of the cornerstones of the line
With the advice that my script is purely experimental and need for accommodation.
Furthermore, it has purposes different from the RDP algorithm, because:
● The intention is conservative: intends to build the same original line, using only the vertices strictly necessary
● The algorithm is different, based on a locally defined approach
DisclaimerThis script is not intended to be an improvement of the RDP algorithm or
any other similar algorithm; it is an independent, simple and naive approach to the problem of discarding unnecessary points from a linestring.
Extracting the contour lines(Raster → Estrazione → Curve di
livello) (sorry, I've an italian menu :-)
Many points are redundant:- or too near
- or, more frequently in this case, aligned;
thus I've written an (experimental) python script that should (it's far from
certain :-):a) simplify eliminating the points too near
b) rectify eliminating aligned points
below threshold value decided by the user
This is an enlargement where we can see that the only retained points are the fundamental ones :-)
the original ones (green circles) and the news (stars)