GIS measure ranging formula and Implementation of C # and JavaScript)

Source: Internet
Author: User

Unit: m

Util. distancebylnglat = function (lng1, LAT1, lng2, LAT2)
{
VaR radlat1 = util. Rad (LAT1 );
VaR radlat2 = util. Rad (LAT2 );
VaR A = radlat1-radlat2;
VaR B = util. Rad (lng1)-util. Rad (lng2 );
VaR S = 2 * Math. asin (math. SQRT (math. pow (math. sin (A/2), 2) + math. cos (radlat1) * Math. cos (radlat2) * Math. pow (math. sin (B/2), 2 )));
S = S * 6378137.0;
S = math. Round (S * 10000)/10000;
Return S;
}

Util. Rad = function (d)
{
Return D * Math. PI/180.0;
}

Note
Math. SQRT (x): the square root of X
Math. Pow (x, n): returns the nth power of X.
Math. Cos (x): returns the cosine of X.
Math. Sin (x): sine function of X
Math. asin (y): arcsin function of X
Math. Round (x): returns the value closest to integer x.
6378137: long radius

Coordinate System
WGS-84 World Earth coordinate system (wor1d geodetic system ). Coordinate System

The implementation of distance between two points on the earth's surface based on the latitude and longitude obtained from Google map is slightly adapted. For space distance calculation in China, this implementation is sufficient, in meters .. Net2.0, C # implementation.

Public static double distanceoftwopoints (double lng1, double LAT1, double lng2, double LAT2, gausssphere GS)
{
Double radlat1 = rad (LAT1 );
Double radlat2 = rad (LAT2 );
Double A = radlat1-radlat2;
Double B = rad (lng1)-rad (lng2 );
Double S = 2 * Math. asin (math. SQRT (math. pow (math. sin (A/2), 2) + math. cos (radlat1) * Math. cos (radlat2) * Math. pow (math. sin (B/2), 2); string 8
S = S * (GS = gausssphere. WGS84? 6378137.0: (GS = gausssphere. xian80? 6378140.0: 6378245.0 ));
S = math. Round (S * 10000)/10000;
Return S;
}
Private Static double rad (double D)
{
Return D * Math. PI/180.0;
}

Gausssphere is a custom Enumeration type
/// <Summary>
/// Reference elliptical in Gaussian projection
/// </Summary>
Public Enum gausssphere
{
Beijing54,
Xian80,
WGS84,
}

Shenzhen Universiade-Shenzhen 2011 Summer Universiade

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.