private List <ScanModel> GetNearbyScans(ScanModel scan)
        {
            var builder = new FilterDefinitionBuilder <ScanModel>();
            var filter  = builder.Near(S => S.Kinematics.Location, scan.Kinematics.Location, minDistance: 0.0, maxDistance: DistanceThreshold);

            var nearby_scans = m_scanCollection.Find(filter).ToList();

            return(nearby_scans);
        }
Ejemplo n.º 2
0
        public async Task <PDVEntity> GetNearst(double longt, double lat)
        {
            var coord = new GeoJson2DCoordinates(longt, lat);
            var geo   = new GeoJsonPoint <GeoJson2DCoordinates>(coord);

            var filterBuiler  = new FilterDefinitionBuilder <PDVEntity>();
            var filterInAreas = filterBuiler.GeoIntersects(p => p.coverageArea, geo);
            var filterNear    = filterBuiler.Near(p => p.address, geo);

            var filter = filterBuiler.And(filterInAreas, filterNear);

            var collection = Context.GetCollection <PDVEntity>(TypeName);
            var indexKey   = new IndexKeysDefinitionBuilder <PDVEntity>().Geo2DSphere(p => p.address);
            var index      = new CreateIndexModel <PDVEntity>(indexKey);

            collection.Indexes.CreateOne(index);

            var list = await Context.GetCollection <PDVEntity>(TypeName).FindAsync(filter);

            return(list.FirstOrDefault());
        }
Ejemplo n.º 3
0
        public static FilterDefinition <RestaurantEntity> GetSearchFilter(Dictionary <string, string> QueryParameters)
        {
            FilterDefinition <RestaurantEntity> searchFilter;

            if (QueryParameters.Count == 0)
            {
                BsonDocument nofilter = new BsonDocument();
                return(nofilter);
            }


            searchFilter = Builders <RestaurantEntity> .Filter.Where(x => x.Name != null);

            var filter     = Builders <RestaurantEntity> .Filter;
            var searchTags = new List <string>();

            int distanceInMeter    = 1000;
            int minDistanceinMeter = 0;

            double latitude  = 0;
            double longitude = 0;



            foreach (var param in QueryParameters)
            {
                if (param.Key == "value" && CheckValue(typeof(string), param.Value))
                {
                    var array = param.Value.ToLower().Trim().Split(',');
                    if (array.Length == 1 && array[0] != String.Empty)
                    {
                        searchTags.AddRange(array);
                        searchFilter &= filter.In("SearchTags", searchTags);
                    }
                }

                else if (param.Key == "costupperlimit" && CheckValue(typeof(int), Convert.ToInt32(param.Value)))
                {
                    searchFilter &= filter.Where(x => x.CostUpperLimit <= Convert.ToInt32(param.Value));
                }
                else if (param.Key == "costlowerlimit" && CheckValue(typeof(int), Convert.ToInt32(param.Value)))
                {
                    searchFilter &= filter.Where(x => x.CostLowerLimit >= Convert.ToInt32(param.Value));
                }
                else if (param.Key == "lat" && CheckValue(typeof(double), Convert.ToDouble(param.Value)))
                {
                    latitude = Convert.ToDouble(param.Value);
                }
                else if (param.Key == "lon" && CheckValue(typeof(double), Convert.ToDouble(param.Value)))
                {
                    longitude = Convert.ToDouble(param.Value);
                }
                else if (param.Key == "distance" && CheckValue(typeof(int), Convert.ToInt32(param.Value)))
                {
                    distanceInMeter = Convert.ToInt32(param.Value);
                }
            }

            //FIXME : someday, i m gonna come to this segment and find out a way to query text and geonear together
            if (latitude != 0 && longitude != 0)
            {
                GeoJsonPoint <GeoJson2DGeographicCoordinates> Point   = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(new GeoJson2DGeographicCoordinates(longitude, latitude));
                FilterDefinitionBuilder <RestaurantEntity>    builder = new FilterDefinitionBuilder <RestaurantEntity>();
                searchFilter &= builder.Near <GeoJson2DGeographicCoordinates>(x => x.GeoPoint, Point, distanceInMeter);
            }

            return(searchFilter);
        }
        public async Task <TrainingPosition> GetRandomAsync(string type)
        {
            double x = rnd.NextDouble();
            double y = rnd.NextDouble();
            FilterDefinitionBuilder <TrainingPosition> filterBuilder = Builders <TrainingPosition> .Filter;
            FilterDefinition <TrainingPosition>        filter        = filterBuilder.Eq("type", type) & filterBuilder.Near("location", x, y);
            var found = positionCollection.Find(filter);

            if (found == null)
            {
                return(null);
            }
            else
            {
                return(await found.Limit(1).FirstAsync());
            }
        }
Ejemplo n.º 5
0
 //
 // 摘要:
 //     Tests that the value of the named element is near some location (see $near and
 //     $nearSphere).
 //
 // 参数:
 //   name:
 //     The name of the element to test.
 //
 //   x:
 //     The x value of the origin.
 //
 //   y:
 //     The y value of the origin.
 //
 //   maxDistance:
 //     The max distance for a document to be included in the results.
 //
 //   spherical:
 //     Whether to do a spherical search.
 //
 // 返回结果:
 //     The builder (so method calls can be chained).
 public static FilterDefinition <BsonDocument> Near(string name, double x, double y, double maxDistance, bool spherical)
 {
     return(filter.Near(name, x, y, maxDistance));
 }