(17) Principle and realization of measurement of distance and area in Webgis

Source: Internet
Author: User

1. Background

In this chapter we will discuss two other common tools in the Basic toolbar: Distance measurement tool box Area measurement tool.

The distance measurement tool requires the following functions:

A. By clicking on a mouse, each point of click is connected to a line segment on the map.

B. The actual distance represented by this segment at each segment

C. Double-click the mouse to stop the wheel measurement, indicating the total length of all segments

D. Allow the mouse to drag the map

The requirements for area measurement tools are roughly the same as those for measuring tools, described below:

A. Click on the map to connect the click Point to the polygon by clicking on the mouse

B. Double-click the mouse to stop this round measurement, indicating the total area of the

C. Allow the mouse to drag the map

2. Starting from the principle

In completing the above requirements, we first need to understand the core principle of this function, in fact, we have in the elementary geometry of the distance formula and area formula.

Here I first give a model:

2.1 Distance Conversion formula

L (AB) = Math.sqrt ((x1-x2) * (X1-X2) + (y1-y2) * (Y1-y2));

2.2 Multi-side shape area conversion formula

First I give the formula directly:

S (total) =math.abs (0.5* (x1*y2-y1*x2+x2*y3-y2*x3+....+xn*y1-yn*x1)));

How is this formula deduced? Let me tell you about it.

2.2.1 Triangle area with coordinate points

We all know the most common area formula in triangles: S=1/2*a*h.

In my previous article (stored procedure Judging two lines coincident point) also mentioned another formula, Helen Formula:

S=MATH.SQT ((p* (P-A) * (p-b) * (p-c)), where p=1/2* (A+b+c).

Here we continue to derive the Helen Formula, which we already know A (x1,y1), B (X2,y2), C (X3,y3). The

A=MATH.SQT ((x2-x3) * (X2-X3) + (y2-y3) * (Y2-y3)), and B and C.

By substituting the a,b,c,p represented by the coordinate point into the Helen Formula, we can draw another equivalent formula in the area of the coordinate system:

S= Math.Abs (0.5* (x1*y2-y1*x2+x2*y3-y2*x3+x3*y1-y3*x1));

2.2.2 The polygon area derived from the triangular area

In the model, we set a P (x0,y0) point inside the polygon, and we can divide the polygons into (n-2) triangles by connecting the endpoints in the polygons with P points.

The area of the polygon becomes:

S (total) =s (PAB) +s (PBC) +s (PCD) +...+s (PNA);

By substituting the area coordinate formula of the triangle, we can finally calculate a general formula that offsets the P-point coordinates:

S (total) =math.abs (0.5* (x1*y2-y1*x2+x2*y3-y2*x3+....+xn*y1-yn*x1)));

2.2.3 Note

By deducing the formula, we can see that the formula is not valid for the area of the circular polygon.

3. Implementing Process 3.1 Concrete steps

Distance measurement and area measurement are basically the same way of realization.

A. Initialize three parameters, Isdone to True,flag to False,isclick to false.

B. When the mouse MouseDown, first determine if done is true, if so, clear the map of the existing drawing. Record the startpoint at this time, and given three parameters, Isdone is false,flag to True for True,isclick.

C. When the mouse MouseMove, determine if flag is true at this time. If true, the panning function is triggered. If it is false, first determine if Isdone is true, and if so, then empty redraw all previous points, then determine if Isclick is true, and if so, the segment will be drawn in real time with the mouse movement.

D. When the mouse MouseUp, recording the endpoint at this time, can be calculated by StartPoint and endpoint the length of the segment at this time. Change the flag to false, which stops the panning function.

E. When the mouse DoubleClick, change the Isdone parameter to True,flag to False,isclick to false. Figure out the total distance or total area of the whole process.

3.2 Attention Issues

Because this feature adds the ability to map panning, you can easily draw point offsets when drawing in real time without notice.

About this offset, I have in the previous two chapters to do a more detailed explanation, but also provides a solution, if you are not very clear, you can look back.

In the concrete steps, I mentioned that there was an empty redraw process in the MouseMove event to prevent the effect of map movement. At the same time, the total offset must be subtracted at each point's drawing.

3.3 Effect Display

The distance measurements and area measurements are given here respectively: two

4. Further discussion

Above, the formulas we give are all for the plane coordinates, that is, the coordinates of the projection transformation. If we get the coordinates of the latitude and longitude coordinates, can this formula still be used?

The answer is no. So we have to do our own projection transformation to convert the latitude and longitude coordinates into planar coordinates. This kind of conversion formula, involves the principle is more complex, the code implementation also is relatively difficult.

At the moment, I've been exposed to transformations with WGS84, BeJing54, XiAn80 and some local geographic coordinate systems, which also involve four parameters and seven parameter methods. The specific process, in the later chapters of this series, I will discuss with you in detail.

However, in the case of low accuracy requirements, we can uniformly use the mecator (UTM) projection for conversion, and using the four parameter method, the four parameter is fixed.

5. Summary

In this chapter, we leave a huge problem, that is, the coordinate transformation problem. The problem is a lot of learning, but we can understand it in general and use this algorithm. In the next section, I will discuss with you the other two functions that are left in the basic function, the empty function and the map positioning function. In the next chapter, we will explore the basic functions involved in the more difficult a function, I query function, the function of the reasonable realization and reasonable presentation are need to be carefully scrutinized. We welcome your continued attention.

--Welcome reprint, but retain the copyright, please indicate the source in obvious place: http://www.cnblogs.com/naaoveGIS/

(17) Principle and realization of measurement of distance and area in Webgis

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.