An improved Douglas-poke algorithm and C + + implementation

Source: Internet
Author: User
Tags reserved
Douglas-Poke (Douglas one peukcer) algorithmCategory: Map | | Geo Data 2012-05-10 21:55 1431 people read comments (0) Collection report algorithm

Douglas-Peukcer algorithm is proposed by D.douglas and T.peueker in 1973, and is called D-P algorithm, which is recognized as a classical algorithm of linear element simplification. Quite a few of the existing algorithms are based on the improved algorithm. It has the advantage of translation and rotation invariance, given the curve and there value, the sampling results are certain. This chapter focuses on the algorithm in line simplification.

The basic idea of the algorithm is that the first end point of each curve is not connected with a straight line, the distance between all points and the line is found, and the maximum distance value is DMax, and the DMax is compared with the limit d: if DMax < D, the middle point of the curve is all out; if dmax≥d, keep dmax corresponding coordinates, With this point as the boundary, the curve is divided into two parts and the method is reused for the two parts.

The detailed steps of the algorithm are as follows:

(1) At the end of the curve two points between the virtual connection of a straight line, to find the remaining points to the distance from the line, as shown in Figure 3 (1).

(2) Choose its largest and threshold comparison, if greater than the threshold, then the distance from the largest point of the line reserved, otherwise the straight line between the points of all the points out, such as Figure 3 (2), the 4th reservation.

(3) The known curve is divided into two parts according to the reserved point, repeating the 1th, 2-step operation, iterative operation, that is still the largest selection distance and the threshold comparison, in turn, until no point can be shed, and finally to meet the given precision limit of the curve point coordinates, such as Figure 3 (3), (4) in order to retain the 6th, 7th, Shed other points, that is, the completion of the line of simplification.




GIS vector data simplification: An improved Douglas-poke algorithm and C + + implementation Category: GIS bottom development 2013-10-05 16:46 124 people read comments (0) Collection report

Since I have time today, I will write a few more blog posts, but also for tomorrow to go out to play a good relaxing.

As the comrades in the field of GIs know, the traditional Douglas-poke algorithms are recursive implementations. However, sometimes the recursive hierarchy is too deep, there will be stack overflow situation. In this paper, a non recursive algorithm is introduced.

To change the recursive algorithm to a non recursive algorithm, it is generally divided into two kinds of scenarios. The first is that the problem definition is recursive, such as factorial, Fibonacci sequence, and so on, for such problems, the recursive algorithm is very simple, directly with the iteration. Another is that the process is recursive, such as the Douglas-poke algorithm in this article, for this kind of problem, generally using stacks (stack) to record intermediate results, and finally get results.

In order to ensure that the extremum point is not abandoned, the curve is divided into two sections in the bending extremum point, and the bending extremum point is measured by the angle of the middle point and the adjacent two vertices. However, the traditional Douglas-peucker algorithm does not take into account the maximum distance in the middle of the calculation of the node, resulting in long cycle time, recursive nesting level is too deep, thus affecting the operation of the program efficiency. In this paper, a piecewise douglas-peucker algorithm combining stack data structure is proposed, which starts from one end of the curve, takes first point and last point as the working interval of the improved Douglas-peucker algorithm, and then determines whether the furthest distance is greater than the threshold value. This completes the synthesis simplification of the line element. The specific steps to improve the D-P algorithm are as follows:

(1) In order to find the maximum curvature of the curve, the curve is divided into two parts by dividing this point, which is somewhat column for each part. The two curves are then processed separately.

(2) for the first segment of the curve, there are vector discrete point sequences, which are set and connected to form a line segment. Generate a stack that will point into the stack.

(3) in the point between the search for the maximum distance with the line, recorded as.

(4) Determine whether the point to the distance is less than the threshold, if not, then set, and will be added to the feature point sequence, will be pressed into the stack, connected with line segments, back (3). If so, carry out step (5).

(5) To determine whether the stack is equal to the top element, if not, then set, to represent the top of the stack, connected with line segments, back (3). If so, execute (6).

(6) Whether the judge is equal to, if not, then set, (the next point of the top of the stack), connected with line segments, stack top elements out of the stack, back (3).

(7) When the stack is empty, the first section of the curve calculates the end. Process the second curve and repeat (1) ~ (7).

The program flow chart of the improved algorithm is shown in the following figure.

Figure Improved Douglas-peucker flowchart

The improved algorithm proposed in this paper is more complex in programming, but it can reduce the number of repeat cycles in the middle. With the above flowchart, the code is relatively simple.[CPP]  View plain copy void douglaspeucker (linevertex *v,int &i,int &j,double e)    {       double dist = 9999;        int f = 0;          //the point ordinal of the maximum distance        stack<int> tempVertex;       &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;//STL implementation of the Stack        tempvertex.push (j);           do        {            //cycle I and J distance line ij The largest point             findsplit (*v,i,j,&f,&dist);               if  (dist > e)       //greater than threshold   

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.