Ejemplo n.º 1
0
        public List <string> GetListOfZipCodes(ProfileListFilterModel filter)
        {
            var result = new List <string>();

            //var filterDefinition = Builders<LocationLookup>.Filter.Ne(p=>p.Supervisor, null);

            if (!string.IsNullOrEmpty(filter.mfz))
            {
                var location = GetLongLat(filter.mfz);
                var point    = new GeoJson2DGeographicCoordinates(location.lg, location.lt);
                var pnt      = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(point);
                //Expression<Func<Profile,Profile>> fieldExpression = p => p.Supervisor.Addresses.Where(_ => _.Type.Equals("Primary"));

                FieldDefinition <LocationLookup, string> field = "LocationLookup.Location";

                //_context.Locations.Collection.Indexes.CreateOne(Builders<LocationLookup>.IndexKeys.Geo2DSphere(field));

                //var filterDefinition = Builders<LocationLookup>.Filter.NearSphere(p => p.Location, pnt, filter.mfd*10);
                var filterDefinition = Builders <LocationLookup> .Filter.NearSphere(field, pnt, filter.mfd *500);

                var foo = _context.Locations.Collection.Find(filterDefinition);
                //var s = "";
            }

            return(result);
        }
Ejemplo n.º 2
0
 public Infectado(DateTime dataNascimento, int genero, double latitude, double longitude)
 {
     DataNascimento = dataNascimento;
     Genero         = (Genero)genero;
     Localizacao    = new GeoJson2DGeographicCoordinates(longitude, latitude);
     DataCadastro   = DateTime.Now;
 }
        public async Task <Location> CreateAsync(Location location)
        {
            AddressData address = new AddressData
            {
                Address = location.Address1,
                City    = location.City,
                State   = location.StateProvince,
                Country = "United States",
                Zip     = location.Zip
            };

            try
            {
                string   apikey             = System.Environment.GetEnvironmentVariable("GEO_API_KEY");
                var      gls                = new GoogleLocationService(apikey);
                MapPoint coordinates        = gls.GetLatLongFromAddress(address);
                var      geoJsonCoordinates = new GeoJson2DGeographicCoordinates(coordinates.Longitude, coordinates.Latitude);
                location.Coordinates = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(geoJsonCoordinates);
            }
            catch (System.Net.WebException ex)
            {
                Console.WriteLine("Error getting coordinates {0}", ex.Message);
            }
            await _locations.InsertOneAsync(location);

            return(location);
        }
Ejemplo n.º 4
0
 public Infected(long cpf, DateTime dateBirth, string genre, double latitude, double longitude)
 {
     Cpf               = cpf;
     DateBith          = dateBirth;
     Genre             = genre;
     this.Localization = new GeoJson2DGeographicCoordinates(latitude, longitude);
 }
Ejemplo n.º 5
0
        public async Task ShouldGetDiscountsInProximity()
        {
            //given
            var centerPoint  = new GeoJson2DGeographicCoordinates(-74.00629342, 40.71416726);
            var near50mPoint = new GeoJson2DGeographicCoordinates(-74.00566041, 40.71420792);
            var far100mPoint = new GeoJson2DGeographicCoordinates(-74.0049094, 40.71415913);
            var nearBranch   = await CreatePartner(1, 1);

            nearBranch.Location = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(near50mPoint);
            var farBranch = await CreatePartner(1, 1);

            farBranch.Location = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(far100mPoint);
            await _collectionProvider.GetCollection <Branch>().InsertManyAsync(new[] { nearBranch, farBranch });

            //when
            var discountsNear75m = await CreateService().GetAllDiscountsInProximityAsync(centerPoint.Longitude, centerPoint.Latitude, 75);

            //then
            var discountNear75m = discountsNear75m.SingleOrDefault();

            Assert.IsNotNull(discountNear75m);
            Assert.AreEqual(nearBranch.Id, discountNear75m.Id);
            Assert.AreEqual(nearBranch.PartnerId, discountNear75m.PartnerId);
            Assert.AreEqual(nearBranch.Location.Coordinates.Longitude, discountNear75m.Location.Coordinates.Longitude);
            Assert.AreEqual(nearBranch.Location.Coordinates.Latitude, discountNear75m.Location.Coordinates.Latitude);
            Assert.IsTrue(AreLocalizableTextPropertiesEqual(nearBranch.Name, discountNear75m.Name));
            Assert.IsTrue(AreEntityCollectionsEqual(nearBranch.Discounts, discountNear75m.Discounts));
        }
Ejemplo n.º 6
0
 public Curado(long id, string sexo, DateTime dataNascimento, double latitude, double longitude)
 {
     this.Id             = id;
     this.Sexo           = sexo;
     this.DataNascimento = dataNascimento;
     this.Localizacao    = new GeoJson2DGeographicCoordinates(longitude, latitude);
 }
Ejemplo n.º 7
0
 public Infectado(DateTime dataNascimento, int idade, string sexo, double latitute, double longitude)
 {
     DataNascimento = dataNascimento;
     Sexo           = sexo;
     Localizacao    = new GeoJson2DGeographicCoordinates(latitute, longitude);
     Idade          = idade;
 }
Ejemplo n.º 8
0
 public Infectado(int userId, DateTime dataNascimento, string sexo, double latitude, double longitude)
 {
     this.UserId         = userId;
     this.DataNascimento = dataNascimento;
     this.Sexo           = sexo;
     this.Localizacao    = new GeoJson2DGeographicCoordinates(longitude, latitude);
 }
Ejemplo n.º 9
0
 public Infectado(DateTime dataNascimento, string sexo, double latitude, double longitude)
 {
     Id             = Guid.NewGuid();
     DataNascimento = dataNascimento;
     Sexo           = sexo;
     Localizacao    = new GeoJson2DGeographicCoordinates(longitude, latitude);
 }
Ejemplo n.º 10
0
        static async Task MainAsync(string[] args)
        {
            var conexaoAeroporto = new conectandoMongoDBGeo();
            var listaAeroportos  = await conexaoAeroporto.Airports.Find(new BsonDocument()).ToListAsync();

            Console.WriteLine("Listando todos os aeroportos");

            foreach (var doc in listaAeroportos)
            {
                Console.WriteLine(doc.name);
            }
            Console.WriteLine("");
            Console.WriteLine("");
            Console.WriteLine("");

            var ponto       = new GeoJson2DGeographicCoordinates(-118.325258, 34.103212);
            var localizacao = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(ponto);

            var construtor     = Builders <Aeroporto> .Filter;
            var filtro_builder = construtor.NearSphere(x => x.loc, localizacao, 100000);

            listaAeroportos = await conexaoAeroporto.Airports.Find(filtro_builder).ToListAsync();

            Console.WriteLine("Listando todos os aeroportos proximo de mim");
            foreach (var doc in listaAeroportos)
            {
                Console.WriteLine(doc.name);
            }
            Console.WriteLine("");
        }
Ejemplo n.º 11
0
 public Personage(string nome, string sexo, DateTime dataNascimento, double latitude, double longitude)
 {
     Nome           = nome;
     Sexo           = sexo;
     DataNascimento = dataNascimento;
     Localizacao    = new GeoJson2DGeographicCoordinates(latitude, longitude);
 }
Ejemplo n.º 12
0
 public Infected(string cpf, DateTime dataNascimento, string sexo, double latitude, double longitude)
 {
     Cpf            = cpf;
     DataNascimento = dataNascimento;
     Sexo           = sexo;
     Localizacao    = new GeoJson2DGeographicCoordinates(longitude, latitude);
 }
Ejemplo n.º 13
0
 public Artist(string name, string[] musicalGender, string title, double longitude, double latitude, string id = null)
 {
     Name          = name;
     MusicalGender = musicalGender;
     Title         = title;
     Localization  = new GeoJson2DGeographicCoordinates(longitude, latitude);
     Id            = id;
 }
Ejemplo n.º 14
0
        public static GeoLocation ToGeoLocation(this GeoJson2DGeographicCoordinates geoJson2DGeographicCoordinates) =>
        geoJson2DGeographicCoordinates != null
                ? new GeoLocation
        {
            Latitude = geoJson2DGeographicCoordinates.Latitude, Longitude = geoJson2DGeographicCoordinates.Longitude
        }

                : null;
Ejemplo n.º 15
0
 public Infectado(DateTime dataNascimento,
                  string sexo,
                  GeoJson2DGeographicCoordinates localizacao)
 {
     this.DataNascimento = dataNascimento;
     this.Sexo           = sexo;
     this.Localizacao    = localizacao;
 }
Ejemplo n.º 16
0
 public static GeoCoordinate ToGeoCoordinate(this GeoJson2DGeographicCoordinates geoJsonCoordinate)
 {
     if (geoJsonCoordinate == null)
     {
         return(null);
     }
     return(new GeoCoordinate(geoJsonCoordinate.Latitude, geoJsonCoordinate.Longitude));
 }
 public CellInfoMongoModel(CellInfoSaveRequest x)
 {
     OperatorName = x.OperatorName;
     CellType     = x.CellType;
     Level        = x.Level;
     IMEI         = x.IMEI;
     Timestamp    = x.Timestamp;
     Location     = new GeoJson2DGeographicCoordinates((double)x.Longitude, (double)x.Latitude);
 }
Ejemplo n.º 18
0
        public Cluster FindNearestCluster(GeoJson2DGeographicCoordinates location, int distance, ZoomLevel zoomLevel)
        {
            var point    = GeoJson.Point(GeoJson.Geographic(location.Longitude, location.Latitude));
            var clusters = _db.GetCollection <Cluster>("Clusters");
            var query    = Query.And(Query <Cluster> .Near(a => a.Location, point, (double)distance),
                                     Query <Cluster> .EQ(a => a.ZoomLevel, zoomLevel));

            return(clusters.Find(query).First());
        }
Ejemplo n.º 19
0
        public static GeoJsonPoint <GeoJson2DGeographicCoordinates> GetJsonPoint(double x, double y)
        {
            GeoJson2DGeographicCoordinates output = GetCoordinates(x, y);

            if (output == null)
            {
                return(null);
            }

            return(new GeoJsonPoint <GeoJson2DGeographicCoordinates>(output));
        }
Ejemplo n.º 20
0
        public static bool Contains(this Bounds bbox, GeoJson2DGeographicCoordinates point)
        {
            bool inLatRange = (bbox.LeftTop.Latitude > bbox.RightBottom.Latitude) ?
                              (point.Latitude <= bbox.LeftTop.Latitude && point.Latitude >= bbox.RightBottom.Latitude) :
                              (point.Latitude <= bbox.LeftTop.Latitude || point.Latitude >= bbox.RightBottom.Latitude);
            bool inLngRange = (bbox.LeftTop.Longitude < bbox.RightBottom.Longitude) ?
                              (point.Longitude >= bbox.LeftTop.Longitude && point.Longitude <= bbox.RightBottom.Longitude) :
                              (point.Longitude >= bbox.LeftTop.Longitude || point.Longitude <= bbox.RightBottom.Longitude);

            return(inLatRange && inLngRange);
        }
Ejemplo n.º 21
0
        private static double CalculateDistanceBetween(GeoJson2DGeographicCoordinates p1, GeoJson2DGeographicCoordinates p2)
        {
            var dLat = DegToRad(p2.Latitude - p1.Latitude);
            var dLng = DegToRad(p2.Longitude - p1.Longitude);
            var x    =
                Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
                Math.Cos(DegToRad(p1.Latitude)) * Math.Cos(DegToRad(p2.Latitude)) *
                Math.Sin(dLng / 2) * Math.Sin(dLng / 2);
            var arc = 2 * Math.Atan2(Math.Sqrt(x), Math.Sqrt(1 - x));

            return(EarthRadius * arc);
        }
Ejemplo n.º 22
0
        /// <summary>
        /// perform $nearSphere query
        // http://docs.mongodb.org/manual/reference/operator/query/nearSphere/
        /// </summary>
        /// <typeparam name="T">Collection to perform the query on</typeparam>
        /// <param name="geoField">path to the Geo document within main document. e.g. For Places document: "Geo", For Collection document: "Place.Geo"</param>
        /// <param name="longitude">Longitude of the point, near to which to perform the search</param>
        /// <param name="latitude">Latitude of the point, near to which to perform the search</param>
        /// <param name="maxDistance">Max distance from the point to search. In Meters</param>
        /// <returns>List of T</returns>
        public List <T> GeoNear <T>(string geoField, double longitude, double latitude, double maxDistance) where T : class, new()
        {
            GeoJson2DGeographicCoordinates coordinates = new GeoJson2DGeographicCoordinates(longitude, latitude);

            MongoDB.Driver.GeoJsonObjectModel.GeoJsonPoint <GeoJson2DGeographicCoordinates> point = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(coordinates);
            IMongoQuery nearQuery = Query.Near(geoField, point, maxDistance, true);

            var      collection = mongoDb.GetCollection <T>(GetTypeName(typeof(T)));
            var      query      = collection.Find(nearQuery);
            List <T> listings   = query.ToList();

            return(listings);
        }
Ejemplo n.º 23
0
        private static double FastCalculateDistanceBetween(GeoJson2DGeographicCoordinates p1, GeoJson2DGeographicCoordinates p2)
        {
            var lat1 = DegToRad(p1.Latitude);
            var lat2 = DegToRad(p2.Latitude);

            var lng1 = DegToRad(p1.Longitude);
            var lng2 = DegToRad(p2.Longitude);

            var x = (lng2 - lng1) * Math.Cos((lat1 + lat2) / 2);
            var y = lat2 - lat1;

            return(Math.Sqrt(x * x + y * y) * EarthRadius);
        }
        public ActionResult UpdateInfected(string id, [FromBody] InfectedDto dto)
        {
            // Faz o filtro baseado no Id
            var filter = Builders <Infected> .Filter.Where(_ => _.Id == id);

            //Atualiza também a location para não ter inconsistência de dados
            var location = new GeoJson2DGeographicCoordinates(dto.Longitude, dto.Latitude);

            var update = Builders <Infected> .Update.Set("name", dto.Name).Set("dateBirth", dto.DateBirth).Set("sex", dto.Sex.ToUpper())
                         .Set("location", location).Set("latitude", dto.Latitude).Set("longitude", dto.Longitude).CurrentDate("lastModified");

            _infectedsCollection.UpdateOne(filter, update); // Atualiza um documento

            return(Ok("Atualizado com sucesso!"));          // Resposta
        }
Ejemplo n.º 25
0
        public static async Task Main(string[] args)
        {
            var coordenadas = new GeoJson2DGeographicCoordinates(-118.325258, 34.103212);
            var localizacao = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(coordenadas);

            var filtro = Builders <Aeroporto> .Filter.NearSphere(e => e.Loc, localizacao, 100000);

            var lista = await MongoDbConnector.AirportsCollection.Find(filtro).ToListAsync();

            foreach (var elemento in lista)
            {
                Console.WriteLine(elemento.ToJson <Aeroporto>());
            }
            Console.ReadKey();
        }
Ejemplo n.º 26
0
        public List <Entity> NearQuery(double Lat, double Long)
        {
            // We initialize the database
            DataBase db = new DataBase();

            double distance = 1000;
            var    g        = new GeoJson2DGeographicCoordinates(Long, Lat);

            var query         = Query.Near <GeoJson2DGeographicCoordinates>("Position", new GeoJsonPoint <GeoJson2DGeographicCoordinates>(g), distance);
            var resultsCursor = db.collection.Find(query);

            // This sends the results to a list
            var results = resultsCursor.ToList();

            return(results);
        }
Ejemplo n.º 27
0
 public Location(
     string street,
     uint number,
     string state,
     string country,
     string city,
     GeoJson2DGeographicCoordinates coordinates
     )
 {
     this.Street      = street;
     this.Number      = number;
     this.State       = state;
     this.Country     = country;
     this.City        = city;
     this.Coordinates = coordinates;
 }
Ejemplo n.º 28
0
        /// <inheritdoc/>
        public Location GetLocationInByLatitudeAndLongitude(double latitude, double longitude)
        {
            var geoJson2DGeographicCoordinates = new GeoJson2DGeographicCoordinates(longitude, latitude);
            var geoJsonPoint     = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(geoJson2DGeographicCoordinates);
            var filterDefinition = Builders <Location>
                                   .Filter
                                   .GeoIntersects(p => p.Geometry, geoJsonPoint);

            var projectionDefinitionBuilder =
                Builders <Location> .Projection;
            var projectionDefinition = projectionDefinitionBuilder
                                       .Exclude(a => a.Geometry);

            return(_collection.Find(filterDefinition)
                   .Project <Location>(projectionDefinition)
                   .FirstOrDefault());
        }
Ejemplo n.º 29
0
        public async Task <Partner> GetByCoordinates(double latitude, double longitude)
        {
            var coordinates = new GeoJson2DGeographicCoordinates(longitude, latitude);
            var point       = new GeoJsonPoint <GeoJson2DGeographicCoordinates>(coordinates);
            var filter      = Builders <PartnerMongoDb> .Filter.GeoIntersects(x => x.CoverageArea, point);

            var partnerDb = await _collection.Find(filter).FirstOrDefaultAsync();

            if (partnerDb == null)
            {
                return(default(Partner));
            }

            var partner = partnerDb.ToPartnerEntity();

            return(partner);
        }
Ejemplo n.º 30
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            GeoJson2DGeographicCoordinates coords;
            var token = JToken.Load(reader);

            if (reader.TokenType == JsonToken.String && ((string)reader.Value) == String.Empty)
            {
                coords = new GeoJson2DGeographicCoordinates(0, 0);
            }
            else
            {
                var tmp = JsonConvert.DeserializeObject <GeoJsonPointSerializationHelper>(token.ToString());
                coords = new GeoJson2DGeographicCoordinates(tmp.coordinates[0], tmp.coordinates[1]);
            }

            return(new GeoJsonPoint <GeoJson2DGeographicCoordinates>(coords));
        }