private bool is_in_circle(double circle_x, double circle_y, double r, double x, double y) { double d = new DotNetCoords.LatLng(Convert.ToDouble(circle_x), Convert.ToDouble(circle_y)).DistanceMiles(new DotNetCoords.LatLng(Convert.ToDouble(x), Convert.ToDouble(y))); //double d = Math.Sqrt(((circle_x - x) * (circle_x - x)) + ((circle_y - y) * (circle_y - y))); return(d <= r); }
public void LatLongDms() { const double Lat = 47.99999993; const double Lng = -122.000001509; var ll = new LatLng(47, 59, 59.99975, NorthSouth.North, 122, 00, 00.00543, EastWest.West); Assert.AreEqual(Lat, ll.Latitude, 0.00000001); Assert.AreEqual(Lng, ll.Longitude, 0.00000001); }
public void LatLonHeDatInvalidLat() { const double Lat = 99; const double Lng = -122.000001509; const double Height = 10; var dat = WGS84Datum.Instance; var ll = new LatLng(Lat, Lng, Height, dat); }
public void LatLongDec() { const double Lat = 47.99999993; const double Lng = -122.000001509; var ll = new LatLng(Lat, Lng); Assert.AreEqual(Lat, ll.Latitude); Assert.AreEqual(Lng, ll.Longitude); }
public void LatLongHeight() { const double Lat = 47.99999993; const double Lng = -122.000001509; const double height = 10; var ll = new LatLng(Lat, Lng, height); Assert.AreEqual(Lat, ll.Latitude); Assert.AreEqual(Lng, ll.Longitude); Assert.AreEqual(height, ll.Height); }
/// <summary> /// Create a new earth-centered, earth-fixed reference from the given latitude and longitude. /// </summary> /// <param name="ll"> The latitude and longitude. </param> public ECEFRef(LatLng ll) : base(ll.Datum) { var ellipsoid = Datum.ReferenceEllipsoid; var phi = Util.ToRadians(ll.Latitude); var lambda = Util.ToRadians(ll.Longitude); var h = ll.Height; var a = ellipsoid.SemiMajorAxis; var f = ellipsoid.Flattening; var eSquared = 2*f - f*f; var nphi = a/Math.Sqrt(1 - eSquared*Util.sinSquared(phi)); X = (nphi + h)*Math.Cos(phi)*Math.Cos(lambda); Y = (nphi + h)*Math.Cos(phi)*Math.Sin(lambda); Z = (nphi*(1 - eSquared) + h)*Math.Sin(phi); }
/// <summary> /// Create a new earth-centred, earth-fixed reference from the given latitude /// and longitude. /// </summary> /// <param name="ll">The latitude and longitude.</param> public ECEFRef(LatLng ll) : base(ll.Datum) { DotNetCoords.Ellipsoid.Ellipsoid ellipsoid = Datum.ReferenceEllipsoid; double phi = Util.ToRadians(ll.Latitude); double lambda = Util.ToRadians(ll.Longitude); double h = ll.Height; double a = ellipsoid.SemiMajorAxis; double f = ellipsoid.Flattening; double eSquared = (2 * f) - (f * f); double nphi = a / Math.Sqrt(1 - eSquared * Util.sinSquared(phi)); X = (nphi + h) * Math.Cos(phi) * Math.Cos(lambda); Y = (nphi + h) * Math.Cos(phi) * Math.Sin(lambda); Z = (nphi * (1 - eSquared) + h) * Math.Sin(phi); }
/// <summary> /// Initializes a new instance of the <see cref="LatLng"/> class based on another <see cref="LatLng"/> instance. /// </summary> /// <param name="original">The original <see cref="LatLng"/> instance.</param> public LatLng(LatLng original) : this(original.Latitude, original.Longitude, original.Height, original.Datum) { }
/// <summary> /// Convert this latitude and longitude into an OSGB (Ordnance Survey of Great /// Britain) grid reference. /// </summary> /// <param name="ll">The latitude and longitude.</param> /// <exception cref="ArgumentException">If the northing or easting are out of range</exception> public OSRef(LatLng ll) : base(OSGB36Datum.Instance) { Airy1830Ellipsoid airy1830 = Airy1830Ellipsoid.Instance; double OSGB_F0 = 0.9996012717; double N0 = -100000.0; double E0 = 400000.0; double phi0 = Util.ToRadians(49.0); double lambda0 = Util.ToRadians(-2.0); double a = airy1830.SemiMajorAxis; double b = airy1830.SemiMinorAxis; double eSquared = airy1830.EccentricitySquared; double phi = Util.ToRadians(ll.Latitude); double lambda = Util.ToRadians(ll.Longitude); double E = 0.0; double N = 0.0; double n = (a - b) / (a + b); double v = a * OSGB_F0 * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -0.5); double rho = a * OSGB_F0 * (1.0 - eSquared) * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -1.5); double etaSquared = (v / rho) - 1.0; double M = (b * OSGB_F0) * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n)) * (phi - phi0)) - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n)) * Math.Sin(phi - phi0) * Math.Cos(phi + phi0)) + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n)) * Math.Sin(2.0 * (phi - phi0)) * Math.Cos(2.0 * (phi + phi0))) - (((35.0 / 24.0) * n * n * n) * Math.Sin(3.0 * (phi - phi0)) * Math.Cos(3.0 * (phi + phi0)))); double I = M + N0; double II = (v / 2.0) * Math.Sin(phi) * Math.Cos(phi); double III = (v / 24.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 3.0) * (5.0 - Util.tanSquared(phi) + (9.0 * etaSquared)); double IIIA = (v / 720.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 5.0) * (61.0 - (58.0 * Util.tanSquared(phi)) + Math.Pow(Math.Tan(phi), 4.0)); double IV = v * Math.Cos(phi); double V = (v / 6.0) * Math.Pow(Math.Cos(phi), 3.0) * ((v / rho) - Util.tanSquared(phi)); double VI = (v / 120.0) * Math.Pow(Math.Cos(phi), 5.0) * (5.0 - (18.0 * Util.tanSquared(phi)) + (Math.Pow(Math.Tan(phi), 4.0)) + (14 * etaSquared) - (58 * Util.tanSquared(phi) * etaSquared)); N = I + (II * Math.Pow(lambda - lambda0, 2.0)) + (III * Math.Pow(lambda - lambda0, 4.0)) + (IIIA * Math.Pow(lambda - lambda0, 6.0)); E = E0 + (IV * (lambda - lambda0)) + (V * Math.Pow(lambda - lambda0, 3.0)) + (VI * Math.Pow(lambda - lambda0, 5.0)); Easting = E; Northing = N; }
/// <summary> /// Calculate the surface distance in kilometres from this LatLng to the given /// LatLng. /// </summary> /// <param name="ll">The LatLng object to measure the distance to..</param> /// <returns>The surface distance in kilometres.</returns> public double Distance(LatLng ll) { double er = 6366.707; double latFrom = Util.ToRadians(Latitude); double latTo = Util.ToRadians(ll.Latitude); double lngFrom = Util.ToRadians(Longitude); double lngTo = Util.ToRadians(ll.Longitude); double d = Math.Acos(Math.Sin(latFrom) * Math.Sin(latTo) + Math.Cos(latFrom) * Math.Cos(latTo) * Math.Cos(lngTo - lngFrom)) * er; return d; }
public void LatLonToDms() { const double Lat = 47.99999993; const double Lng = -122.000001509; var ll = new LatLng(Lat, Lng); var expected = "47 59 59.9997480000047 N 122 0 0.00543240000183687 W"; Assert.AreEqual(expected, ll.ToDmsString()); }
public void LatLonToString() { const double Lat = 47.99999993; const double Lng = -122.000001509; var ll = new LatLng(Lat, Lng); var expected = string.Format("{0}, {1}", Lat, Lng); Assert.AreEqual(expected, ll.ToString()); }
/// <summary> /// Convert this latitude and longitude into an OSGB (Ordnance Survey of Great /// Britain) grid reference. /// </summary> /// <param name="ll"> The latitude and longitude. </param> /// <exception cref="ArgumentException"> If the northing or easting are out of range </exception> public OsRef(LatLng ll) : base(OSGB36Datum.Instance) { ll.ToDatum(OSGB36Datum.Instance); var airy1830 = Airy1830Ellipsoid.Instance; var OSGB_F0 = 0.9996012717; var N0 = -100000.0; var E0 = 400000.0; var phi0 = Util.ToRadians(49.0); var lambda0 = Util.ToRadians(-2.0); var a = airy1830.SemiMajorAxis; var b = airy1830.SemiMinorAxis; var eSquared = airy1830.EccentricitySquared; var phi = Util.ToRadians(ll.Latitude); var lambda = Util.ToRadians(ll.Longitude); var E = 0.0; var N = 0.0; var n = (a - b)/(a + b); var v = a*OSGB_F0 *Math.Pow(1.0 - eSquared*Util.sinSquared(phi), -0.5); var rho = a*OSGB_F0*(1.0 - eSquared) *Math.Pow(1.0 - eSquared*Util.sinSquared(phi), -1.5); var etaSquared = v/rho - 1.0; var M = b*OSGB_F0 *((1 + n + 5.0/4.0*n*n + 5.0/4.0*n*n*n)*(phi - phi0) - (3*n + 3*n*n + 21.0/8.0*n*n*n) *Math.Sin(phi - phi0)*Math.Cos(phi + phi0) + (15.0/8.0*n*n + 15.0/8.0*n*n*n) *Math.Sin(2.0*(phi - phi0))*Math.Cos(2.0*(phi + phi0)) - 35.0/24.0 *n*n*n *Math.Sin(3.0*(phi - phi0))* Math.Cos(3.0*(phi + phi0))); var I = M + N0; var II = v/2.0*Math.Sin(phi)*Math.Cos(phi); var III = v/24.0*Math.Sin(phi)*Math.Pow(Math.Cos(phi), 3.0) *(5.0 - Util.tanSquared(phi) + 9.0*etaSquared); var IIIA = v/720.0*Math.Sin(phi)*Math.Pow(Math.Cos(phi), 5.0) *(61.0 - 58.0*Util.tanSquared(phi) + Math.Pow(Math.Tan(phi), 4.0)); var IV = v*Math.Cos(phi); var V = v/6.0*Math.Pow(Math.Cos(phi), 3.0) *(v/rho - Util.tanSquared(phi)); var VI = v/120.0 *Math.Pow(Math.Cos(phi), 5.0) *(5.0 - 18.0*Util.tanSquared(phi) + Math.Pow(Math.Tan(phi), 4.0) + 14*etaSquared - 58*Util.tanSquared(phi)*etaSquared); N = I + II*Math.Pow(lambda - lambda0, 2.0) + III*Math.Pow(lambda - lambda0, 4.0) + IIIA*Math.Pow(lambda - lambda0, 6.0); E = E0 + IV*(lambda - lambda0) + V*Math.Pow(lambda - lambda0, 3.0) + VI*Math.Pow(lambda - lambda0, 5.0); Easting = E; Northing = N; }
public void LatLonInvalidLat() { const double Lat = 99; const double Lng = -122.000001509; var ll = new LatLng(Lat, Lng); }
public void LatLontoUtmRef() { const double Lat = 47.99999993; const double Lon = -122.000001509; var ll = new LatLng(Lat, Lon); var utmActual = ll.ToUtmRef(); var utmExpected = new UtmRef(10, 'T', 574595, 5316784, WGS84Datum.Instance); Assert.AreEqual(utmExpected, utmActual); }
public void LatLonInvalidLon() { const double Lat = 55; const double Lng = -190; var ll = new LatLng(Lat, Lng); }
public void LatLngDistanceKm() { const double Lat1 = 1; const double Lng1 = 1; const double Lat2 = 2; const double Lng2 = 2; var ll1 = new LatLng(Lat1, Lng1); var ll2 = new LatLng(Lat2, Lng2); var expected = 157.2; Assert.AreEqual(expected, ll1.Distance(ll2), 0.1); }
public void LatLongHeightDatum() { const double Lat = 55; const double Lng = -122.000001509; const double Height = 10; var dat = WGS84Datum.Instance; var ll = new LatLng(Lat, Lng, Height, dat); Assert.AreEqual(Lat, ll.Latitude); Assert.AreEqual(Lng, ll.Longitude); Assert.AreEqual(Height, ll.Height); Assert.AreEqual(dat, WGS84Datum.Instance); }
public void LatLngDistanceMi() { const double Lat1 = 1; const double Lng1 = 1; const double Lat2 = 2; const double Lng2 = 2; var ll1 = new LatLng(Lat1, Lng1); var ll2 = new LatLng(Lat2, Lng2); var expected = 97.6796; Assert.AreEqual(expected, ll1.DistanceMiles(ll2), 0.1); }
/// <summary> /// Calculate the surface distance in miles from this LatLng to the given /// LatLng. /// </summary> /// <param name="ll">The LatLng object to measure the distance to.</param> /// <returns>The surface distance in miles.</returns> public double DistanceMiles(LatLng ll) { return Distance(ll) / 1.609344; }
public void LatLontoUtmRefInvalidLat() { const double Lat = 85; const double Lon = -122.000001509; var ll = new LatLng(Lat, Lon); var utmActual = ll.ToUtmRef(); }
/// <summary> /// Create an IrishRef object from the given latitude and longitude. /// </summary> /// <param name="ll">The latitude and longitude.</param> public IrishRef(LatLng ll) : base(Ireland1965Datum.Instance) { ll.ToDatum(Ireland1965Datum.Instance); DotNetCoords.Ellipsoid.Ellipsoid ellipsoid = Datum.ReferenceEllipsoid; double N0 = FALSE_ORIGIN_NORTHING; double E0 = FALSE_ORIGIN_EASTING; double phi0 = Util.ToRadians(FALSE_ORIGIN_LATITUDE); double lambda0 = Util.ToRadians(FALSE_ORIGIN_LONGITUDE); double a = ellipsoid.SemiMajorAxis * SCALE_FACTOR; double b = ellipsoid.SemiMinorAxis * SCALE_FACTOR; double eSquared = ellipsoid.EccentricitySquared; double phi = Util.ToRadians(ll.Latitude); double lambda = Util.ToRadians(ll.Longitude); double E = 0.0; double N = 0.0; double n = (a - b) / (a + b); double v = a * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -0.5); double rho = a * (1.0 - eSquared) * Math.Pow(1.0 - eSquared * Util.sinSquared(phi), -1.5); double etaSquared = (v / rho) - 1.0; double M = b * (((1 + n + ((5.0 / 4.0) * n * n) + ((5.0 / 4.0) * n * n * n)) * (phi - phi0)) - (((3 * n) + (3 * n * n) + ((21.0 / 8.0) * n * n * n)) * Math.Sin(phi - phi0) * Math.Cos(phi + phi0)) + ((((15.0 / 8.0) * n * n) + ((15.0 / 8.0) * n * n * n)) * Math.Sin(2.0 * (phi - phi0)) * Math.Cos(2.0 * (phi + phi0))) - (((35.0 / 24.0) * n * n * n) * Math.Sin(3.0 * (phi - phi0)) * Math.Cos(3.0 * (phi + phi0)))); double I = M + N0; double II = (v / 2.0) * Math.Sin(phi) * Math.Cos(phi); double III = (v / 24.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 3.0) * (5.0 - Util.tanSquared(phi) + (9.0 * etaSquared)); double IIIA = (v / 720.0) * Math.Sin(phi) * Math.Pow(Math.Cos(phi), 5.0) * (61.0 - (58.0 * Util.tanSquared(phi)) + Math.Pow(Math.Tan(phi), 4.0)); double IV = v * Math.Cos(phi); double V = (v / 6.0) * Math.Pow(Math.Cos(phi), 3.0) * ((v / rho) - Util.tanSquared(phi)); double VI = (v / 120.0) * Math.Pow(Math.Cos(phi), 5.0) * (5.0 - (18.0 * Util.tanSquared(phi)) + (Math.Pow(Math.Tan(phi), 4.0)) + (14 * etaSquared) - (58 * Util.tanSquared(phi) * etaSquared)); N = I + (II * Math.Pow(lambda - lambda0, 2.0)) + (III * Math.Pow(lambda - lambda0, 4.0)) + (IIIA * Math.Pow(lambda - lambda0, 6.0)); E = E0 + (IV * (lambda - lambda0)) + (V * Math.Pow(lambda - lambda0, 3.0)) + (VI * Math.Pow(lambda - lambda0, 5.0)); Easting = E; Northing = N; }
// [TestMethod] public void LatLonToWgs84() { const double lat = 47.950967; const double lon = -122.197045; var actual = new LatLng(lat, lon, 10, OSGB36Datum.Instance); actual.ToWgs84(); var expected = new LatLng(47.99999993, -122.000001509); Assert.AreEqual(expected, actual); }
/// <summary> /// Create an IrishRef object from the given latitude and longitude. /// </summary> /// <param name="ll"> The latitude and longitude. </param> public IrishRef(LatLng ll) : base(Ireland1965Datum.Instance) { ll.ToDatum(Ireland1965Datum.Instance); var ellipsoid = Datum.ReferenceEllipsoid; var N0 = FALSE_ORIGIN_NORTHING; var E0 = FALSE_ORIGIN_EASTING; var phi0 = Util.ToRadians(FALSE_ORIGIN_LATITUDE); var lambda0 = Util.ToRadians(FALSE_ORIGIN_LONGITUDE); var a = ellipsoid.SemiMajorAxis*SCALE_FACTOR; var b = ellipsoid.SemiMinorAxis*SCALE_FACTOR; var eSquared = ellipsoid.EccentricitySquared; var phi = Util.ToRadians(ll.Latitude); var lambda = Util.ToRadians(ll.Longitude); var E = 0.0; var N = 0.0; var n = (a - b)/(a + b); var v = a *Math.Pow(1.0 - eSquared*Util.sinSquared(phi), -0.5); var rho = a*(1.0 - eSquared) *Math.Pow(1.0 - eSquared*Util.sinSquared(phi), -1.5); var etaSquared = v/rho - 1.0; var M = b *((1 + n + 5.0/4.0*n*n + 5.0/4.0*n*n*n)*(phi - phi0) - (3*n + 3*n*n + 21.0/8.0*n*n*n) *Math.Sin(phi - phi0)*Math.Cos(phi + phi0) + (15.0/8.0*n*n + 15.0/8.0*n*n*n) *Math.Sin(2.0*(phi - phi0))*Math.Cos(2.0*(phi + phi0)) - 35.0/24.0 *n*n*n *Math.Sin(3.0*(phi - phi0))* Math.Cos(3.0*(phi + phi0))); var I = M + N0; var II = v/2.0*Math.Sin(phi)*Math.Cos(phi); var III = v/24.0*Math.Sin(phi)*Math.Pow(Math.Cos(phi), 3.0) *(5.0 - Util.tanSquared(phi) + 9.0*etaSquared); var IIIA = v/720.0*Math.Sin(phi)*Math.Pow(Math.Cos(phi), 5.0) *(61.0 - 58.0*Util.tanSquared(phi) + Math.Pow(Math.Tan(phi), 4.0)); var IV = v*Math.Cos(phi); var V = v/6.0*Math.Pow(Math.Cos(phi), 3.0) *(v/rho - Util.tanSquared(phi)); var VI = v/120.0 *Math.Pow(Math.Cos(phi), 5.0) *(5.0 - 18.0*Util.tanSquared(phi) + Math.Pow(Math.Tan(phi), 4.0) + 14*etaSquared - 58*Util.tanSquared(phi)*etaSquared); N = I + II*Math.Pow(lambda - lambda0, 2.0) + III*Math.Pow(lambda - lambda0, 4.0) + IIIA*Math.Pow(lambda - lambda0, 6.0); E = E0 + IV*(lambda - lambda0) + V*Math.Pow(lambda - lambda0, 3.0) + VI*Math.Pow(lambda - lambda0, 5.0); Easting = E; Northing = N; }
/// <summary> /// Calculate the surface distance in miles from this LatLng to the given /// LatLng. /// </summary> /// <param name="ll">The LatLng object to measure the distance to.</param> /// <returns>The surface distance in miles.</returns> public double DistanceMiles(LatLng ll) { return(Distance(ll) / 1.609344); }