public void TestNearWithGeoJsonWithSpherical() { if (_primary.Supports(FeatureId.GeoJson)) { var point = GeoJson.Point(GeoJson.Geographic(40, 18)); var query = Query.Near("loc", point, 42, true); var expected = "{ 'loc' : { '$nearSphere' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }".Replace("'", "\""); Assert.AreEqual(expected, query.ToJson()); var collection = LegacyTestConfiguration.Collection; collection.Drop(); collection.CreateIndex(IndexKeys.GeoSpatialSpherical("loc")); collection.Insert(new BsonDocument { { "_id", 1 }, { "loc", GeoJson.Point(GeoJson.Geographic(1, 1)).ToBsonDocument() } }); collection.Insert(new BsonDocument { { "_id", 2 }, { "loc", GeoJson.Point(GeoJson.Geographic(2, 2)).ToBsonDocument() } }); var circumferenceOfTheEarth = 40075000; // meters at the equator, approx var metersPerDegree = circumferenceOfTheEarth / 360.0; query = Query.Near("loc", GeoJson.Point(GeoJson.Geographic(0, 0)), 2.0 * metersPerDegree, true); var results = collection.Find(query).ToList(); Assert.AreEqual(1, results.Count); Assert.AreEqual(1, results[0]["_id"].ToInt32()); } }
public void TestGeoSpatialSpherical() { var keys = IndexKeys.GeoSpatialSpherical("a"); string expected = "{ \"a\" : \"2dsphere\" }"; Assert.Equal(expected, keys.ToJson()); }
public void TestGeoSpatialSphericalAscending() { var keys = IndexKeys.GeoSpatialSpherical("a").Ascending("b"); string expected = "{ \"a\" : \"2dsphere\", \"b\" : 1 }"; Assert.AreEqual(expected, keys.ToJson()); }
public void TestGeoSpatialSphericalAscending() { var keys = IndexKeys <Test> .GeoSpatialSpherical(x => x.A).Ascending(x => x.B); string expected = "{ \"a\" : \"2dsphere\", \"b\" : 1 }"; Assert.Equal(expected, keys.ToJson()); }
public void TestGeoSpatialSpherical_Typed() { var keys = IndexKeys <Test> .GeoSpatialSpherical(x => x.A); string expected = "{ \"a\" : \"2dsphere\" }"; Assert.AreEqual(expected, keys.ToJson()); }
public static void BuildGeospatialIndex(MongoCollection _table, string _column, string _indexName) { IndexKeysBuilder ikb = IndexKeys.GeoSpatialSpherical(_column); IMongoIndexOptions options = GetIndexOptions(_indexName, false); _table.CreateIndex(ikb, options); }
public MongoIndexKeysWarpper GeoSpatialSpherical(string name) { if (MongoIndexKeys == null) { MongoIndexKeys = IndexKeys.GeoSpatialSpherical(name); } else { MongoIndexKeys = MongoIndexKeys.GeoSpatialSpherical(name); } return(this); }
public QueryBuilderGeoJsonIntegrationTests() { var db = LegacyTestConfiguration.Database; _collection = db.GetCollection <GeoClass>("geo"); _collection.Drop(); _collection.CreateIndex(IndexKeys <GeoClass> .GeoSpatialSpherical(x => x.Location)); _collection.CreateIndex(IndexKeys <GeoClass> .GeoSpatialSpherical(x => x.Surrounding)); var doc = new GeoClass { Id = 1, Location = GeoJson.Point(GeoJson.Geographic(40.5, 18.5)), Surrounding = GeoJson.Polygon( GeoJson.Geographic(40, 18), GeoJson.Geographic(40, 19), GeoJson.Geographic(41, 19), GeoJson.Geographic(40, 18)) }; _collection.Save(doc); }
public void SetUp() { var db = Configuration.TestDatabase; _collection = db.GetCollection <GeoClass>("geo"); _collection.Drop(); _collection.EnsureIndex(IndexKeys <GeoClass> .GeoSpatialSpherical(x => x.Location)); _collection.EnsureIndex(IndexKeys <GeoClass> .GeoSpatialSpherical(x => x.Surrounding)); var doc = new GeoClass { Id = 1, Location = GeoJson.Point(GeoJson.Geographic(40.5, 18.5)), Surrounding = GeoJson.Polygon( GeoJson.Geographic(40, 18), GeoJson.Geographic(40, 19), GeoJson.Geographic(41, 19), GeoJson.Geographic(40, 18)) }; _collection.Save(doc); }
private void EnsureIndex() { this.Nodes.EnsureIndex(IndexKeys.GeoSpatialSpherical("LatLong")); this.Ways.EnsureIndex(IndexKeys.GeoSpatial("Nodes")); }
/// <summary> /// Perform full or partial repopulation of POI Mirror in MongoDB /// </summary> /// <returns></returns> public async Task <MirrorStatus> PopulatePOIMirror(CacheUpdateStrategy updateStrategy) { var dataModel = new Data.OCMEntities(); if (!database.CollectionExists("poi")) { database.CreateCollection("poi"); } if (updateStrategy != CacheUpdateStrategy.All) { if (!database.CollectionExists("reference")) { database.CreateCollection("reference"); } if (!database.CollectionExists("status")) { database.CreateCollection("status"); } if (!database.CollectionExists("poi")) { database.CreateCollection("poi"); } } CoreReferenceData coreRefData = new ReferenceDataManager().GetCoreReferenceData(false); if (coreRefData != null) { database.DropCollection("reference"); //problems clearing data from collection... var reference = database.GetCollection <CoreReferenceData>("reference"); var query = new QueryDocument(); reference.Remove(query, RemoveFlags.None); Thread.Sleep(300); reference.Insert(coreRefData); } var poiList = GetPOIListToUpdate(dataModel, updateStrategy); var poiCollection = database.GetCollection <POIMongoDB>("poi"); if (poiList != null && poiList.Any()) { if (updateStrategy == CacheUpdateStrategy.All) { poiCollection.RemoveAll(); } RemoveAllPOI(poiList, poiCollection); Thread.Sleep(300); InsertAllPOI(poiList, poiCollection); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .GeoSpatialSpherical(x => x.SpatialPosition)); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateLastStatusUpdate)); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateCreated)); if (updateStrategy == CacheUpdateStrategy.All) { poiCollection.ReIndex(); } } long numPOIInMasterDB = dataModel.ChargePoints.LongCount(); return(RefreshMirrorStatus(poiCollection.Count(), 1, numPOIInMasterDB)); }
/// <summary> /// Perform full or partial repopulation of POI Mirror in MongoDB /// </summary> /// <returns></returns> public async Task <MirrorStatus> PopulatePOIMirror(CacheUpdateStrategy updateStrategy) { if (!database.CollectionExists("poi")) { database.CreateCollection("poi"); } if (updateStrategy != CacheUpdateStrategy.All) { CoreReferenceData coreRefData = new ReferenceDataManager().GetCoreReferenceData(); if (!database.CollectionExists("reference")) { database.CreateCollection("reference"); } if (!database.CollectionExists("status")) { database.CreateCollection("status"); } if (coreRefData != null) { var reference = database.GetCollection <CoreReferenceData>("reference"); reference.RemoveAll(); reference.Insert(coreRefData); } } var poiList = GetPOIListToUpdate(updateStrategy); var poiCollection = database.GetCollection <POIMongoDB>("poi"); if (poiList != null && poiList.Any()) { if (updateStrategy == CacheUpdateStrategy.All) { poiCollection.RemoveAll(); } RemoveAllPOI(poiList, poiCollection); Thread.Sleep(300); InsertAllPOI(poiList, poiCollection); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .GeoSpatialSpherical(x => x.SpatialPosition)); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateLastStatusUpdate)); poiCollection.CreateIndex(IndexKeys <POIMongoDB> .Descending(x => x.DateCreated)); } var statusCollection = database.GetCollection <MirrorStatus>("status"); statusCollection.RemoveAll(); //new status MirrorStatus status = new MirrorStatus(); //status.ID = Guid.NewGuid().ToString(); status.Description = "MongoDB Cache of Open Charge Map POI Database"; status.LastUpdated = DateTime.UtcNow; status.TotalPOI = poiCollection.Count(); status.StatusCode = HttpStatusCode.OK; if (poiList != null) { status.NumPOILastUpdated = poiList.Count; } else { status.NumPOILastUpdated = 0; } statusCollection.Insert(status); return(status); }