Simplification of GIS vector data: An improved Douglas-poke algorithm and C + + implementation

Source: Internet
Author: User

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.

 void Douglaspeucker (Linevertex *v,int &i,int &j,double e) {Double dist = 9999; int f = 0; The number of points of the maximum distance stack<int> Tempvertex; The Stack Tempvertex.push (j) implemented by STL; do {//Loops I and J distance line ij The largest point findsplit (*v,i,j,&f,&dist); if (Dist > E)//greater than threshold {(*V) [F].flag = true; j = f; Update b value Tempvertex.push (f); Record the maximum distance point, put into the stack storage continue; else {if (!tempvertex.empty () && J!= Tempvertex.top ())//To determine whether the latter point is equal to the current stack top {i = f; j = Tempvertex.top (); Continue else {if (J!= v->size ())//To determine if the last point coincides with the B point of the current segment {i = j; if (!tempvertex.empty ()) {deque<int> cont = Tempvertex._get_container (); if (Cont.size () > 1)//stack There are at least two points {j = cont[cont.size ()-2]; else if (cont.size () = = 1)///stack only one point {j = cont[cont.size ()-1]; } tempvertex.pop (); Continue {}}}} while (!tempvertex.empty ()); }
The

 

Code is not complete. There are calls to another function, is to find the curve from the end of the curve in the distance between the two points of the maximum point, this process is very simple, not to say, there are some of their own definition of data structure, this article is only to explain the idea of this algorithm, The algorithm description part of the formula, the original text is edited in Word, if you do not understand directly to see the flow chart is also clear points.

 


 

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.