public override double Area(Rectangle rect)
        {
            //From http://mathforum.org/library/drmath/view/63767.html
            double lat1 = DistanceUtils.ToRadians(rect.GetMinY());
            double lat2 = DistanceUtils.ToRadians(rect.GetMaxY());

            return(Math.PI / 180 * radiusDEG * radiusDEG *
                   Math.Abs(Math.Sin(lat1) - Math.Sin(lat2)) *
                   rect.GetWidth());
        }
Exemplo n.º 2
0
        private void TestDistCalcPointOnBearing(double distKm)
        {
            for (int angDEG = 0; angDEG < 360; angDEG += random.Next(1, 20 + 1))
            {
                IPoint c = ctx.MakePoint(
                    DistanceUtils.NormLonDEG(random.Next(359 + 1)),
                    random.Next(-90, 90 + 1));

                //0 distance means same point
                IPoint p2 = Dc().PointOnBearing(c, 0, angDEG, ctx, null);
                Assert.Equal(c, p2);

                p2 = Dc().PointOnBearing(c, distKm * DistanceUtils.KM_TO_DEG, angDEG, ctx, null);
                double calcDistKm = Dc().Distance(c, p2) * DistanceUtils.DEG_TO_KM;
                AssertEqualsRatio(distKm, calcDistKm);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculates the degrees longitude distance at latitude <paramref name="lat"/> to cover
        /// a distance <paramref name="dist"/>.
        /// <para>
        /// Used to calculate a new expanded buffer distance to account for skewing
        /// effects for shapes that use the lat-lon space as a 2D plane instead of a
        /// sphere. The expanded buffer will be sure to cover the intended area, but
        /// the shape is still skewed and so it will cover a larger area. For latitude
        /// 0 (the equator) the result is the same buffer. At 60 (or -60) degrees, the
        /// result is twice the buffer, meaning that a shape at 60 degrees is twice as
        /// high as it is wide when projected onto a lat-lon plane even if in the real
        /// world it's equal all around.
        /// </para>
        /// If the result added to abs(<paramref name="lat"/>) is &gt;= 90 degrees, then skewing is
        /// so severe that the caller should consider tossing the shape and
        /// substituting a spherical cap instead.
        /// </summary>
        /// <param name="lat">latitude in degrees</param>
        /// <param name="dist">distance in degrees</param>
        /// <returns>longitudinal degrees (x delta) at input latitude that is &gt;=
        /// <paramref name="dist"/> distance. Will be &gt;= dist and &lt;= 90.</returns>
        public static double CalcLonDegreesAtLat(double lat, double dist)
        {
            //This code was pulled out of DistanceUtils.pointOnBearingRAD() and
            // optimized
            // for bearing = 90 degrees, and so we can get an intermediate calculation.
            double distanceRAD = DistanceUtils.ToRadians(dist);
            double startLat    = DistanceUtils.ToRadians(lat);

            double cosAngDist  = Math.Cos(distanceRAD);
            double cosStartLat = Math.Cos(startLat);
            double sinAngDist  = Math.Sin(distanceRAD);
            double sinStartLat = Math.Sin(startLat);

            double lonDelta = Math.Atan2(sinAngDist * cosStartLat,
                                         cosAngDist * (1 - sinStartLat * sinStartLat));

            return(DistanceUtils.ToDegrees(lonDelta));
        }
Exemplo n.º 4
0
        private void AssertDistanceConversionImpl(double dist)
        {
            double radius = DistanceUtils.EARTH_MEAN_RADIUS_KM;
            //test back & forth conversion for both
            double distRAD = DistanceUtils.Dist2Radians(dist, radius);

            CustomAssert.EqualWithDelta(dist, DistanceUtils.Radians2Dist(distRAD, radius), EPS);
            double distDEG = DistanceUtils.Dist2Degrees(dist, radius);

            CustomAssert.EqualWithDelta(dist, DistanceUtils.Degrees2Dist(distDEG, radius), EPS);
            //test across rad & deg
            CustomAssert.EqualWithDelta(distDEG, DistanceUtils.ToDegrees(distRAD), EPS);
            //test point on bearing
            CustomAssert.EqualWithDelta(
                DistanceUtils.PointOnBearingRAD(0, 0, DistanceUtils.Dist2Radians(dist, radius),
                                                DistanceUtils.DEG_90_AS_RADS, ctx, new Point(0, 0, ctx)).X,
                distRAD, 10e-5);
        }
        private readonly double radiusDEG = DistanceUtils.ToDegrees(1);        //in degrees

        public override Point PointOnBearing(Point @from, double distDEG, double bearingDEG, SpatialContext ctx, Point reuse)
        {
            if (distDEG == 0)
            {
                if (reuse == null)
                {
                    return(from);
                }
                reuse.Reset(from.GetX(), from.GetY());
                return(reuse);
            }
            Point result = DistanceUtils.PointOnBearingRAD(
                DistanceUtils.ToRadians(from.GetY()), DistanceUtils.ToRadians(from.GetX()),
                DistanceUtils.ToRadians(distDEG),
                DistanceUtils.ToRadians(bearingDEG), ctx, reuse);//output result is in radians

            result.Reset(DistanceUtils.ToDegrees(result.GetX()), DistanceUtils.ToDegrees(result.GetY()));
            return(result);
        }
 public override double Distance(Point @from, double toX, double toY)
 {
     return(DistanceUtils.ToDegrees(DistanceLatLonRAD(DistanceUtils.ToRadians(from.GetY()),
                                                      DistanceUtils.ToRadians(from.GetX()), DistanceUtils.ToRadians(toY), DistanceUtils.ToRadians(toX))));
 }
 public override double CalcBoxByDistFromPt_yHorizAxisDEG(Point from, double distDEG, SpatialContext ctx)
 {
     return(DistanceUtils.CalcBoxByDistFromPt_latHorizAxisDEG(from.GetY(), from.GetX(), distDEG));
 }
 public override Rectangle CalcBoxByDistFromPt(Point from, double distDEG, SpatialContext ctx, Rectangle reuse)
 {
     return(DistanceUtils.CalcBoxByDistFromPtDEG(from.GetY(), from.GetX(), distDEG, ctx, reuse));
 }
 protected override double DistanceLatLonRAD(double lat1, double lon1, double lat2, double lon2)
 {
     return(DistanceUtils.DistVincentyRAD(lat1, lon1, lat2, lon2));
 }
Exemplo n.º 10
0
 protected override double DistanceLatLonRAD(double lat1, double lon1, double lat2, double lon2)
 {
     return(DistanceUtils.DistLawOfCosinesRAD(lat1, lon1, lat2, lon2));
 }
Exemplo n.º 11
0
 public override IRectangle CalcBoxByDistFromPt(IPoint from, double distDEG, SpatialContext ctx, IRectangle reuse)
 {
     return(DistanceUtils.CalcBoxByDistFromPtDEG(from.Y, from.X, distDEG, ctx, reuse));
 }