private void cmdGeoNear_Click(object sender, EventArgs e) { var GeoOption = new GeoNearArgs(); GeoOption.DistanceMultiplier = (double.Parse(NumDistanceMultiplier.Text)); GeoOption.MaxDistance = (double.Parse(NumMaxDistance.Text)); GeoOption.Spherical = (chkSpherical.Checked); GeoOption.Limit = (int)(NumResultCount.Value); GeoOption.Near = new XYPoint(double.Parse(NumGeoX.Text), double.Parse(NumGeoY.Text)); try { BsonDocument mGeoNearAs = SystemManager.GetCurrentCollection().GeoNearAs<BsonDocument>(GeoOption).Response; MongoDbHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); } catch (Exception ex) { SystemManager.ExceptionDeal(ex); } }
private void cmdGeoNear_Click(object sender, EventArgs e) { var geoOption = new GeoNearArgs(); geoOption.DistanceMultiplier = double.Parse(NumDistanceMultiplier.Text); geoOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoOption.Spherical = chkSpherical.Checked; geoOption.Limit = (int) NumResultCount.Value; geoOption.Near = new XYPoint(double.Parse(NumGeoX.Text), double.Parse(NumGeoY.Text)); try { var mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoNearAs<BsonDocument>(geoOption).Response; UiHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); } catch (Exception ex) { Utility.ExceptionDeal(ex); } }
public void TestGeoNearWithMaxTime() { if (_primary.Supports(FeatureId.MaxTime)) { using (var failpoint = new FailPoint(FailPointName.MaxTimeAlwaysTimeout, _server, _primary)) { if (failpoint.IsSupported()) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new BsonDocument("loc", new BsonArray { 0, 0 })); _collection.EnsureIndex(IndexKeys.GeoSpatial("loc")); failpoint.SetAlwaysOn(); var args = new GeoNearArgs { Near = GeoNearPoint.From(0, 0), MaxTime = TimeSpan.FromMilliseconds(1) }; Assert.Throws<ExecutionTimeoutException>(() => _collection.GeoNearAs<BsonDocument>(args)); } } } }
public void TestGeoNearWithGeoJsonPoints() { if (_server.BuildInfo.Version >= new Version(2, 4, 0, 0)) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new PlaceGeoJson { Location = GeoJson.Point(GeoJson.Geographic(-74.0, 40.74)), Name = "10gen", Type = "Office" }); _collection.Insert(new PlaceGeoJson { Location = GeoJson.Point(GeoJson.Geographic(-74.0, 41.73)), Name = "Three", Type = "Coffee" }); _collection.Insert(new PlaceGeoJson { Location = GeoJson.Point(GeoJson.Geographic(-75.0, 40.74)), Name = "Two", Type = "Coffee" }); _collection.EnsureIndex(IndexKeys.GeoSpatialSpherical("Location")); var args = new GeoNearArgs { Near = GeoNearPoint.From(GeoJson.Point(GeoJson.Geographic(-74.0, 40.74))), Spherical = true }; var result = _collection.GeoNearAs<PlaceGeoJson>(args); var hits = result.Hits; var hit0 = hits[0].Document; Assert.AreEqual(-74.0, hit0.Location.Coordinates.Longitude); Assert.AreEqual(40.74, hit0.Location.Coordinates.Latitude); Assert.AreEqual("10gen", hit0.Name); Assert.AreEqual("Office", hit0.Type); // with spherical true "Two" is considerably closer than "Three" var hit1 = hits[1].Document; Assert.AreEqual(-75.0, hit1.Location.Coordinates.Longitude); Assert.AreEqual(40.74, hit1.Location.Coordinates.Latitude); Assert.AreEqual("Two", hit1.Name); Assert.AreEqual("Coffee", hit1.Type); var hit2 = hits[2].Document; Assert.AreEqual(-74.0, hit2.Location.Coordinates.Longitude); Assert.AreEqual(41.73, hit2.Location.Coordinates.Latitude); Assert.AreEqual("Three", hit2.Name); Assert.AreEqual("Coffee", hit2.Type); } }
public void TestGeoNearSphericalTrue() { if (_server.BuildInfo.Version >= new Version(1, 7, 0, 0)) { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { -74.0, 40.74 }, Name = "10gen", Type = "Office" }); _collection.Insert(new Place { Location = new[] { -75.0, 40.74 }, Name = "Two", Type = "Coffee" }); _collection.Insert(new Place { Location = new[] { -74.0, 41.73 }, Name = "Three", Type = "Coffee" }); _collection.EnsureIndex(IndexKeys.GeoSpatial("Location")); var args = new GeoNearArgs { Near = GeoNearPoint.From(-74.0, 40.74), Limit = 100, Spherical = true }; var result = _collection.GeoNearAs<Place>(args); Assert.IsTrue(result.Ok); Assert.AreEqual(_collection.FullName, result.Namespace); Assert.IsTrue(result.Stats.AverageDistance >= 0.0); Assert.IsTrue(result.Stats.BTreeLocations >= 0); Assert.IsTrue(result.Stats.Duration >= TimeSpan.Zero); Assert.IsTrue(result.Stats.MaxDistance >= 0.0); Assert.IsTrue(result.Stats.NumberScanned >= 0); Assert.IsTrue(result.Stats.ObjectsLoaded >= 0); Assert.AreEqual(3, result.Hits.Count); var hit0 = result.Hits[0]; Assert.IsTrue(hit0.Distance == 0.0); Assert.AreEqual(-74.0, hit0.RawDocument["Location"][0].AsDouble); Assert.AreEqual(40.74, hit0.RawDocument["Location"][1].AsDouble); Assert.AreEqual("10gen", hit0.RawDocument["Name"].AsString); Assert.AreEqual("Office", hit0.RawDocument["Type"].AsString); // with spherical true "Two" is considerably closer than "Three" var hit1 = result.Hits[1]; Assert.IsTrue(hit1.Distance > 0.0); Assert.AreEqual(-75.0, hit1.RawDocument["Location"][0].AsDouble); Assert.AreEqual(40.74, hit1.RawDocument["Location"][1].AsDouble); Assert.AreEqual("Two", hit1.RawDocument["Name"].AsString); Assert.AreEqual("Coffee", hit1.RawDocument["Type"].AsString); var hit2 = result.Hits[2]; Assert.IsTrue(hit2.Distance > 0.0); Assert.IsTrue(hit2.Distance > hit1.Distance); Assert.AreEqual(-74.0, hit2.RawDocument["Location"][0].AsDouble); Assert.AreEqual(41.73, hit2.RawDocument["Location"][1].AsDouble); Assert.AreEqual("Three", hit2.RawDocument["Name"].AsString); Assert.AreEqual("Coffee", hit2.RawDocument["Type"].AsString); } }
public void TestGeoNearGeneric() { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { 1.0, 1.0 }, Name = "One", Type = "Museum" }); _collection.Insert(new Place { Location = new[] { 1.0, 2.0 }, Name = "Two", Type = "Coffee" }); _collection.Insert(new Place { Location = new[] { 1.0, 3.0 }, Name = "Three", Type = "Library" }); _collection.Insert(new Place { Location = new[] { 1.0, 4.0 }, Name = "Four", Type = "Museum" }); _collection.Insert(new Place { Location = new[] { 1.0, 5.0 }, Name = "Five", Type = "Coffee" }); _collection.EnsureIndex(IndexKeys.GeoSpatial("Location")); var args = new GeoNearArgs { Near = GeoNearPoint.From(0, 0), Limit = 100, DistanceMultiplier = 1, MaxDistance = 100 }; var result = _collection.GeoNearAs<Place>(args); Assert.IsTrue(result.Ok); Assert.AreEqual(_collection.FullName, result.Namespace); Assert.IsTrue(result.Stats.AverageDistance >= 0.0); Assert.IsTrue(result.Stats.BTreeLocations >= 0); Assert.IsTrue(result.Stats.Duration >= TimeSpan.Zero); Assert.IsTrue(result.Stats.MaxDistance >= 0.0); Assert.IsTrue(result.Stats.NumberScanned >= 0); Assert.IsTrue(result.Stats.ObjectsLoaded >= 0); Assert.AreEqual(5, result.Hits.Count); Assert.IsTrue(result.Hits[0].Distance > 1.0); Assert.AreEqual(1.0, result.Hits[0].RawDocument["Location"][0].AsDouble); Assert.AreEqual(1.0, result.Hits[0].RawDocument["Location"][1].AsDouble); Assert.AreEqual("One", result.Hits[0].RawDocument["Name"].AsString); Assert.AreEqual("Museum", result.Hits[0].RawDocument["Type"].AsString); var place = result.Hits[1].Document; Assert.AreEqual(1.0, place.Location[0]); Assert.AreEqual(2.0, place.Location[1]); Assert.AreEqual("Two", place.Name); Assert.AreEqual("Coffee", place.Type); }
public void TestGeoNearSphericalFalse() { if (_collection.Exists()) { _collection.Drop(); } _collection.Insert(new Place { Location = new[] { -74.0, 40.74 }, Name = "10gen", Type = "Office" }); _collection.Insert(new Place { Location = new[] { -75.0, 40.74 }, Name = "Two", Type = "Coffee" }); _collection.Insert(new Place { Location = new[] { -74.0, 41.73 }, Name = "Three", Type = "Coffee" }); _collection.CreateIndex(IndexKeys.GeoSpatial("Location")); var args = new GeoNearArgs { Near = new XYPoint(-74.0, 40.74), Limit = 100, Spherical = false }; var result = _collection.GeoNearAs<Place>(args); Assert.IsTrue(result.Ok); Assert.AreEqual(_collection.FullName, result.Namespace); Assert.IsTrue(result.Stats.AverageDistance >= 0.0); #pragma warning disable 618 Assert.IsTrue(result.Stats.BTreeLocations >= -1); #pragma warning restore Assert.IsTrue(result.Stats.Duration >= TimeSpan.Zero); Assert.IsTrue(result.Stats.MaxDistance >= 0.0); #pragma warning disable 618 Assert.IsTrue(result.Stats.NumberScanned >= -1); #pragma warning restore Assert.IsTrue(result.Stats.ObjectsLoaded >= 0); Assert.AreEqual(3, result.Hits.Count); var hit0 = result.Hits[0]; Assert.IsTrue(hit0.Distance == 0.0); Assert.AreEqual(-74.0, hit0.RawDocument["Location"][0].AsDouble); Assert.AreEqual(40.74, hit0.RawDocument["Location"][1].AsDouble); Assert.AreEqual("10gen", hit0.RawDocument["Name"].AsString); Assert.AreEqual("Office", hit0.RawDocument["Type"].AsString); // with spherical false "Three" is slightly closer than "Two" var hit1 = result.Hits[1]; Assert.IsTrue(hit1.Distance > 0.0); Assert.AreEqual(-74.0, hit1.RawDocument["Location"][0].AsDouble); Assert.AreEqual(41.73, hit1.RawDocument["Location"][1].AsDouble); Assert.AreEqual("Three", hit1.RawDocument["Name"].AsString); Assert.AreEqual("Coffee", hit1.RawDocument["Type"].AsString); var hit2 = result.Hits[2]; Assert.IsTrue(hit2.Distance > 0.0); Assert.IsTrue(hit2.Distance > hit1.Distance); Assert.AreEqual(-75.0, hit2.RawDocument["Location"][0].AsDouble); Assert.AreEqual(40.74, hit2.RawDocument["Location"][1].AsDouble); Assert.AreEqual("Two", hit2.RawDocument["Name"].AsString); Assert.AreEqual("Coffee", hit2.RawDocument["Type"].AsString); }
private void cmdGeoNear_Click(object sender, EventArgs e) { BsonDocument mGeoNearAs = null; bool IsHaystack = chkHaystack.Checked; try { if (IsHaystack) { var geoSearchOption = new GeoHaystackSearchArgs(); geoSearchOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoSearchOption.Limit = (int)NumResultCount.Value; geoSearchOption.Near = point; // GeoHaystackSearch mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoHaystackSearchAs<BsonDocument>(geoSearchOption).Response; } else { var geoOption = new GeoNearArgs(); geoOption.DistanceMultiplier = double.Parse(NumDistanceMultiplier.Text); geoOption.MaxDistance = double.Parse(NumMaxDistance.Text); geoOption.Spherical = chkSpherical.Checked; geoOption.Limit = (int)NumResultCount.Value; if (radGeoJSON.Checked) { geoOption.Near = new GeoJsonPoint<GeoJson2DCoordinates>(new GeoJson2DCoordinates(point.X, point.Y)); } else { geoOption.Near = point; } //GeoNearAs mGeoNearAs = RuntimeMongoDbContext.GetCurrentCollection().GeoNearAs<BsonDocument>(geoOption).Response; } } catch (Exception ex) { Utility.ExceptionDeal(ex); return; } UiHelper.FillDataToTreeView("Result", trvGeoResult, mGeoNearAs); trvGeoResult.DatatreeView.Nodes[0].Expand(); }