Exemplo n.º 1
0
 /// <summary>
 /// Adds a proximity-based constraint for finding objects with keys whose GeoPoint
 /// values are near the given point.
 /// </summary>
 /// <param name="key">The key that the AVGeoPoint is stored in.</param>
 /// <param name="point">The reference AVGeoPoint.</param>
 /// <returns>A new query with the additional constraint.</returns>
 public AVQuery <T> WhereNear(string key, AVGeoPoint point)
 {
     return(new AVQuery <T>(this, where : new Dictionary <string, object> {
         { key, new Dictionary <string, object> {
               { "$nearSphere", point }
           } }
     }));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a proximity-based constraint for finding objects with keys whose GeoPoint
 /// values are near the given point.
 /// </summary>
 /// <param name="key">The key that the AVGeoPoint is stored in.</param>
 /// <param name="point">The reference AVGeoPoint.</param>
 /// <returns>A new query with the additional constraint.</returns>
 public virtual S WhereNear(string key, AVGeoPoint point)
 {
     return(CreateInstance(this, where : new Dictionary <string, object> {
         { key, new Dictionary <string, object> {
               { "$nearSphere", point }
           } }
     }));
 }
Exemplo n.º 3
0
        public void TestGeoDistanceInRadians()
        {
            var d2r = Math.PI / 180.0;
              var pointA = new AVGeoPoint();
              var pointB = new AVGeoPoint();

              // Zero
              Assert.AreEqual(0.0, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(0.0, pointB.DistanceTo(pointA).Radians, 0.00001);

              // Wrap Long
              pointA.Longitude = 179.0;
              pointB.Longitude = -179.0;
              Assert.AreEqual(2 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(2 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001);

              // North South Lat
              pointA.Latitude = 89.0;
              pointA.Longitude = 0;
              pointB.Latitude = -89.0;
              pointB.Longitude = 0;
              Assert.AreEqual(178 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(178 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001);

              // Long wrap Lat
              pointA.Latitude = 89.0;
              pointA.Longitude = 0;
              pointB.Latitude = -89.0;
              pointB.Longitude = 179.999;
              Assert.AreEqual(180 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(180 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001);

              pointA.Latitude = 79.0;
              pointA.Longitude = 90.0;
              pointB.Latitude = -79.0;
              pointB.Longitude = -90.0;
              Assert.AreEqual(180 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(180 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001);

              // Wrap near pole - somewhat ill conditioned case due to pole proximity
              pointA.Latitude = 85.0;
              pointA.Longitude = 90.0;
              pointB.Latitude = 85.0;
              pointB.Longitude = -90.0;
              Assert.AreEqual(10 * d2r, pointA.DistanceTo(pointB).Radians, 0.00001);
              Assert.AreEqual(10 * d2r, pointB.DistanceTo(pointA).Radians, 0.00001);

              // Reference cities

              // Sydney, Australia
              pointA.Latitude = -34.0;
              pointA.Longitude = 151.0;
              // Buenos Aires, Argentina
              pointB.Latitude = -34.5;
              pointB.Longitude = -58.35;
              Assert.AreEqual(1.85, pointA.DistanceTo(pointB).Radians, 0.01);
              Assert.AreEqual(1.85, pointB.DistanceTo(pointA).Radians, 0.01);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds a proximity-based constraint for finding objects with keys whose GeoPoint
 /// values are near the given point and within the maximum distance given.
 /// </summary>
 /// <param name="key">The key that the AVGeoPoint is stored in.</param>
 /// <param name="point">The reference AVGeoPoint.</param>
 /// <param name="maxDistance">The maximum distance (in radians) of results to return.</param>
 /// <returns>A new query with the additional constraint.</returns>
 public AVQuery <T> WhereWithinDistance(
     string key, AVGeoPoint point, AVGeoDistance maxDistance)
 {
     return(new AVQuery <T>(WhereNear(key, point), where : new Dictionary <string, object> {
         { key, new Dictionary <string, object> {
               { "$maxDistance", maxDistance.Radians }
           } }
     }));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Adds a proximity-based constraint for finding objects with keys whose GeoPoint
        /// values are near the given point and within the maximum distance given.
        /// </summary>
        /// <param name="key">The key that the AVGeoPoint is stored in.</param>
        /// <param name="point">The reference AVGeoPoint.</param>
        /// <param name="maxDistance">The maximum distance (in radians) of results to return.</param>
        /// <returns>A new query with the additional constraint.</returns>
        public virtual S WhereWithinDistance(
            string key, AVGeoPoint point, AVGeoDistance maxDistance)
        {
            S avQuery = this.WhereNear(key, point);

            return(CreateInstance(avQuery, where : new Dictionary <string, object> {
                { key, new Dictionary <string, object> {
                      { "$maxDistance", maxDistance.Radians }
                  } }
            }));
        }
Exemplo n.º 6
0
        public void TestGeoPointConstructor()
        {
            var point = new AVGeoPoint();
              Assert.AreEqual(0.0, point.Latitude);
              Assert.AreEqual(0.0, point.Longitude);

              point = new AVGeoPoint(42, 36);
              Assert.AreEqual(42.0, point.Latitude);
              Assert.AreEqual(36.0, point.Longitude);

              point.Latitude = 12;
              point.Longitude = 24;
              Assert.AreEqual(12.0, point.Latitude);
              Assert.AreEqual(24.0, point.Longitude);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Add a constraint to the query that requires a particular key's coordinates to be
 /// contained within a given rectangular geographic bounding box.
 /// </summary>
 /// <param name="key">The key to be constrained.</param>
 /// <param name="southwest">The lower-left inclusive corner of the box.</param>
 /// <param name="northeast">The upper-right inclusive corner of the box.</param>
 /// <returns>A new query with the additional constraint.</returns>
 public AVQuery <T> WhereWithinGeoBox(string key,
                                      AVGeoPoint southwest,
                                      AVGeoPoint northeast)
 {
     return(new AVQuery <T>(this, where : new Dictionary <string, object> {
         {
             key,
             new Dictionary <string, object> {
                 {
                     "$within",
                     new Dictionary <string, object> {
                         { "$box", new[] { southwest, northeast } }
                     }
                 }
             }
         }
     }));
 }
Exemplo n.º 8
0
        /// <summary>
        /// Get the distance in radians between this point and another GeoPoint. This is the smallest angular
        /// distance between the two points.
        /// </summary>
        /// <param name="point">GeoPoint describing the other point being measured against.</param>
        /// <returns>The distance in between the two points.</returns>
        public AVGeoDistance DistanceTo(AVGeoPoint point)
        {
            double d2r              = Math.PI / 180; // radian conversion factor
            double lat1rad          = Latitude * d2r;
            double long1rad         = longitude * d2r;
            double lat2rad          = point.Latitude * d2r;
            double long2rad         = point.Longitude * d2r;
            double deltaLat         = lat1rad - lat2rad;
            double deltaLong        = long1rad - long2rad;
            double sinDeltaLatDiv2  = Math.Sin(deltaLat / 2);
            double sinDeltaLongDiv2 = Math.Sin(deltaLong / 2);
            // Square of half the straight line chord distance between both points.
            // [0.0, 1.0]
            double a = sinDeltaLatDiv2 * sinDeltaLatDiv2 +
                       Math.Cos(lat1rad) * Math.Cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;

            a = Math.Min(1.0, a);
            return(new AVGeoDistance(2 * Math.Asin(Math.Sqrt(a))));
        }
Exemplo n.º 9
0
 /// <summary>
 /// Add a constraint to the query that requires a particular key's coordinates to be
 /// contained within a given rectangular geographic bounding box.
 /// </summary>
 /// <param name="key">The key to be constrained.</param>
 /// <param name="southwest">The lower-left inclusive corner of the box.</param>
 /// <param name="northeast">The upper-right inclusive corner of the box.</param>
 /// <returns>A new query with the additional constraint.</returns>
 public virtual S WhereWithinGeoBox(string key,
                                    AVGeoPoint southwest,
                                    AVGeoPoint northeast)
 {
     return(CreateInstance(this, where : new Dictionary <string, object>
     {
         {
             key,
             new Dictionary <string, object>
             {
                 {
                     "$within",
                     new Dictionary <string, object> {
                         { "$box", new[] { southwest, northeast } }
                     }
                 }
             }
         }
     }));
 }
Exemplo n.º 10
0
 /// <summary>
 /// Get the distance in radians between this point and another GeoPoint. This is the smallest angular
 /// distance between the two points.
 /// </summary>
 /// <param name="point">GeoPoint describing the other point being measured against.</param>
 /// <returns>The distance in between the two points.</returns>
 public AVGeoDistance DistanceTo(AVGeoPoint point)
 {
     double d2r = Math.PI / 180; // radian conversion factor
       double lat1rad = Latitude * d2r;
       double long1rad = longitude * d2r;
       double lat2rad = point.Latitude * d2r;
       double long2rad = point.Longitude * d2r;
       double deltaLat = lat1rad - lat2rad;
       double deltaLong = long1rad - long2rad;
       double sinDeltaLatDiv2 = Math.Sin(deltaLat / 2);
       double sinDeltaLongDiv2 = Math.Sin(deltaLong / 2);
       // Square of half the straight line chord distance between both points.
       // [0.0, 1.0]
       double a = sinDeltaLatDiv2 * sinDeltaLatDiv2 +
     Math.Cos(lat1rad) * Math.Cos(lat2rad) * sinDeltaLongDiv2 * sinDeltaLongDiv2;
       a = Math.Min(1.0, a);
       return new AVGeoDistance(2 * Math.Asin(Math.Sqrt(a)));
 }
Exemplo n.º 11
0
 public void TestGeoPointCultureInvariantParsing()
 {
     var originalCulture = Thread.CurrentThread.CurrentCulture;
       foreach (var c in CultureInfo.GetCultures(CultureTypes.AllCultures)) {
     Thread.CurrentThread.CurrentCulture = c;
     var point = new AVGeoPoint(1.234, 1.234);
     var serialized = Json.Encode(
       new Dictionary<string, object> {
     { "point", NoObjectsEncoder.Instance.Encode(point) }
       });
     var deserialized = AVDecoder.Instance.Decode(Json.Parse(serialized)) as IDictionary<string, object>;
     var pointAgain = (AVGeoPoint)deserialized["point"];
     Assert.AreEqual(1.234, pointAgain.Latitude);
     Assert.AreEqual(1.234, pointAgain.Longitude);
       }
 }
Exemplo n.º 12
0
 public void TestEncodeParseGeoPoint()
 {
     AVGeoPoint point = new AVGeoPoint(3.22, 32.2);
       IDictionary<string, object> value = ParseEncoderTestClass.Instance.Encode(point) as IDictionary<string, object>;
       Assert.AreEqual("GeoPoint", value["__type"]);
       Assert.AreEqual(3.22, value["latitude"]);
       Assert.AreEqual(32.2, value["longitude"]);
 }