Ejemplo n.º 1
0
        public async Task <LocationCoordinates> FindLocationCoordinates(string location)
        {
            var geocoder = new ForwardGeocoder();
            var request  = new ForwardGeocodeRequest
            {
                queryString = location,
                BreakdownAddressElements = true,
                ShowExtraTags            = false,
                ShowAlternativeNames     = false,
                ShowGeoJSON = false
            };

            var result = await geocoder.Geocode(request);

            var response = result.FirstOrDefault();

            if (result.Length > 0 && response != null)
            {
                return(new LocationCoordinates
                {
                    Latitude = response.Latitude,
                    Longitude = response.Longitude
                });
            }

            return(null);
        }
Ejemplo n.º 2
0
        public async Task <ICollection <MapDataDto> > GetAtmLocations(ICollection <ATM> atms)
        {
            var t       = new ForwardGeocoder();
            var atmData = new List <MapDataDto>(atms.Count);

            foreach (var atm in atms)
            {
                var request = new ForwardGeocodeRequest()
                {
                    queryString  = atm.Address,
                    LimitResults = 1
                };
                var response = await t.Geocode(request);

                MapLocation location = null;
                if (response.Length > 0)
                {
                    location = new MapLocation()
                    {
                        Latitude  = response[0].Latitude,
                        Longitude = response[0].Longitude
                    };
                }

                var tmp = new MapDataDto
                {
                    Atm      = atm,
                    Location = location
                };
                atmData.Add(tmp);
            }

            return(atmData);
        }
Ejemplo n.º 3
0
        public async Task <List <GeoUser> > GeoReverse(string place)
        {
            try
            {
                var geoReverse = new ForwardGeocoder();
                var result     = await geoReverse.Geocode(new Nominatim.API.Models.ForwardGeocodeRequest
                {
                    queryString = place
                });

                if (result.Length > 0)
                {
                    var geoCode = result[0];
                    return(new List <GeoUser>()
                    {
                        new GeoUser()
                        {
                            DisplayName = geoCode.DisplayName,
                            Id = geoCode.PlaceID.ToString(),
                            Importance = geoCode.Importance,
                            Lat = geoCode.Latitude,
                            Lon = geoCode.Longitude,
                            Type = geoCode.ClassType
                        }
                    });
                }
                return(null);;
            }
            catch (Exception ex)
            {
                return(null);
            }
        }
Ejemplo n.º 4
0
        public void CalcGeocodeResponse()
        {
            //if (address == _address)
            //     return GeocodeResponse;

            //SetAddress(address);

            ForwardGeocoder fg = new ForwardGeocoder();
            //ForwardGeocodeRequest fgr = new ForwardGeocodeRequest();
            Task <GeocodeResponse[]> ar = fg.Geocode(new ForwardGeocodeRequest
            {
                queryString              = Address,
                DedupeResults            = true,
                BreakdownAddressElements = true,
                ShowExtraTags            = true,
                ShowAlternativeNames     = true,
                ShowGeoJSON              = true
            });

            ar.Wait();

            if (ar.Result.Length == 0)
            {
                GeocodeResponse = null;
            }
            else
            {
                GeocodeResponse = ar.Result[0];
            }
        }
Ejemplo n.º 5
0
        public Location EncodeAddress(string address)
        {
            var geocoder = new ForwardGeocoder();

            var request = geocoder.Geocode(new ForwardGeocodeRequest
            {
                queryString = address,

                BreakdownAddressElements = true,
                ShowExtraTags            = true,
                ShowAlternativeNames     = true,
                ShowGeoJSON = true
            });

            request.Wait();

            var result = request.Result.FirstOrDefault();

            if (result == null)
            {
                return(null);
            }
            Location location = new Location(result.Latitude, result.Longitude);

            return(location);
        }
Ejemplo n.º 6
0
        public async Task <Models.GeocodeResponse> GetGeocoderAsync(Models.QueueItemGeocodeRequest command)
        {
            var client = new ForwardGeocoder();

            var queryString = !command.Request.Country.IsNullOrEmpty() ? command.Request.Country + ", " : "";

            queryString += !command.Request.State.IsNullOrEmpty() ? command.Request.State + ", " : "";
            queryString += !command.Request.City.IsNullOrEmpty() ? command.Request.City + ", " : "";
            queryString += !command.Request.Street.IsNullOrEmpty() ? command.Request.Street + " " : "";
            queryString += !command.Request.Number.IsNullOrEmpty() ? command.Request.Number: "";

            var result = await client.Geocode(new ForwardGeocodeRequest()
            {
                queryString = queryString,
                BreakdownAddressElements = true,
                ShowExtraTags            = true,
                ShowAlternativeNames     = true,
                ShowGeoJSON = true
            });

            if (result.Length < 1)
            {
                return(null);
            }

            var r = result.FirstOrDefault();

            return(new Models.GeocodeResponse()
            {
                Id = command.Id,
                Latitude = r.Latitude,
                Longitude = r.Longitude
            });
        }
Ejemplo n.º 7
0
        public async Task <Location> Find(string address)
        {
            var geocoder = new ForwardGeocoder();

            GeocodeResponse[] responses = await geocoder.Geocode(new ForwardGeocodeRequest
            {
                queryString = address,

                BreakdownAddressElements = true,
                ShowExtraTags            = false,
                ShowAlternativeNames     = false,
                ShowGeoJSON = true,
            });

            GeocodeResponse location = responses.FirstOrDefault();

            if (location is null)
            {
                throw new Exception($"Address not found: {address}");
            }

            return(new Location()
            {
                Coordinate = new Position(location.Latitude, location.Longitude),
                Address = address
            });
        }
Ejemplo n.º 8
0
        public static GeocodeResponse GetAdressDetails(string query)
        {
            ForwardGeocoder       geocoder = new ForwardGeocoder();
            ForwardGeocodeRequest request  = new ForwardGeocodeRequest()
            {
                queryString  = query,
                LimitResults = 1,
                ShowGeoJSON  = true
            };
            var geocodeResponses = geocoder.Geocode(request);

            geocodeResponses.Wait();
            return(geocodeResponses.Result == null ? null : geocodeResponses.Result[0]);
        }
        public async Task <Tuple <double, double> > AddressToLocation(string address)
        {
            var geocoder = new ForwardGeocoder();
            var request  = await geocoder.Geocode(new ForwardGeocodeRequest
            {
                queryString = address
            });

            if (request.Length < 1)
            {
                return(null);
            }

            return(new Tuple <double, double> (request[0].Latitude, request[0].Longitude));
        }
Ejemplo n.º 10
0
        public void TestSuccessfulForwardGeocode()
        {
            var x = new ForwardGeocoder();

            var r = x.Geocode(new ForwardGeocodeRequest {
                queryString = "1600 Pennsylvania Avenue, Washington, DC",

                BreakdownAddressElements = true,
                ShowExtraTags            = true,
                ShowAlternativeNames     = true,
                ShowGeoJSON = true
            });

            r.Wait();

            Assert.IsTrue(r.Result.Length > 0);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Esta funcion busca a traves de las direccion proporcionada por el objeto LocalizadorData
        /// la latitud y la longitud de dicha direccion.
        /// </summary>
        /// <param name="LD"></param>
        /// <returns>LD</returns>
        public static LocalizadorData Find(LocalizadorData LD)
        {
            ForwardGeocodeRequest d = new ForwardGeocodeRequest();
            GeocodeResponse       g = new GeocodeResponse();

            d.City          = LD.ciudad;
            d.Country       = LD.pais;
            d.StreetAddress = LD.calle + " " + LD.numero.ToString();
            d.County        = LD.provincia;
            ForwardGeocoder          FG = new ForwardGeocoder();
            Task <GeocodeResponse[]> r  = FG.Geocode(d);

            g           = r.Result[0];
            LD.latitud  = g.Latitude;
            LD.longitud = g.Longitude;
            return(LD);
        }
Ejemplo n.º 12
0
        static async Task <Coordinates> GetCoordinatesAsync(string query)
        {
            var geocoder = new ForwardGeocoder();
            var request  = new ForwardGeocodeRequest()
            {
                queryString = query
            };

            var result = await geocoder.Geocode(request);

            if (result.Length > 0)
            {
                var geocodeResponse = result.First();
                var tags            = geocodeResponse.ExtraTags;
                return(new Coordinates(geocodeResponse.Latitude, geocodeResponse.Longitude));
            }
            return(null);
        }
Ejemplo n.º 13
0
        public Location AddressToLocation(string address)
        {
            var geocoder = new ForwardGeocoder();
            var request  = geocoder.Geocode(new ForwardGeocodeRequest
            {
                queryString = address
            });

            request.Wait();

            if (request.Status != System.Threading.Tasks.TaskStatus.RanToCompletion)
            {
                return(null);
            }

            if (request.Result.Length < 1)
            {
                return(null);
            }

            return(new Location(request.Result[0].Latitude, request.Result[0].Longitude));
        }
Ejemplo n.º 14
0
        public Message Buscar(Message msg)
        {
            ForwardGeocodeRequest FGR     = new ForwardGeocodeRequest();
            GeocodeResponse       request = new GeocodeResponse();

            try
            {
                FGR.City          = msg.ciudad;
                FGR.Country       = msg.pais;
                FGR.StreetAddress = msg.calle + " " + msg.numero.ToString();
                FGR.County        = msg.provincia;
                ForwardGeocoder          FG       = new ForwardGeocoder();
                Task <GeocodeResponse[]> response = FG.Geocode(FGR);
                request      = response.Result[0];
                msg.latitud  = request.Latitude;
                msg.longitud = request.Longitude;
            }
            catch (Exception ex)
            {
                var error = ex.Message;
            }

            return(msg);
        }
Ejemplo n.º 15
0
        public async Task GeocoderAdress(Adress adress)
        {
            var a = new ForwardGeocoder();
            var r = a.Geocode(new ForwardGeocodeRequest
            {
                queryString = string.Format("{0} {1},{2},{3},{4}", adress.Calle, adress.Numero, adress.Ciudad, adress.Provincia, adress.Pais),

                BreakdownAddressElements = true,
                ShowExtraTags            = true,
                ShowAlternativeNames     = true,
                ShowGeoJSON = true
            });

            r.Wait();


            var coord = new Coordinates();

            coord.Latitud     = r.Result[0].Latitude.ToString();
            coord.Longitud    = r.Result[0].Longitude.ToString();
            coord.IdOperacion = adress.IdOperacion;
            coord.Estado      = "TERMINADO";
            SendMessage(coord);
        }
Ejemplo n.º 16
0
        public ProcessPoint IdentifyCoordinatePoint(ProcessPoint point)
        {
            try
            {
                var x = new ForwardGeocoder();

                var r = x.Geocode(new ForwardGeocodeRequest
                {
                    queryString = point.addressDb.Get(),//"1600 Pennsylvania Avenue, Washington, DC",

                    BreakdownAddressElements = true,
                    ShowExtraTags            = true,
                    ShowAlternativeNames     = true,
                    ShowGeoJSON = true
                });

                r.Wait();

                return(point);
                //WebClientExtended client = new WebClientExtended();

                //if (Convert.ToBoolean(ConfigurationManager.AppSettings["isProxy"]))
                //{
                //    string Host = ConfigurationManager.AppSettings["ProxyHost"];
                //    int Port = Convert.ToInt32(ConfigurationManager.AppSettings["ProxyPort"]);
                //    System.Net.WebProxy wp = new System.Net.WebProxy(Host, Port);
                //    client.Proxy = wp;
                //}

                //string ep = string.Format(ConfigurationManager.AppSettings["OSMApiPath"]);
                ////string url = string.Format("{0}{1}&format=xml&addressdetails=1", ep, System.Convert.ToBase64String(
                ////    System.Text.Encoding.Default.GetBytes(point.SourceAddress)
                ////    ));

                //string url = string.Format("{0}{1}&format=xml&addressdetails=1", ep, HttpUtility.UrlEncode(point.SourceAddress));

                ////url = HttpUtility.UrlEncode(url);

                //string st = System.Text.Encoding.UTF8.GetString(client.DownloadData(url));

                //XmlSerializer serializer = new XmlSerializer(typeof(Searchresults));

                //using (TextReader tr = new StringReader(st))
                //{
                //    Searchresults result = (Searchresults)serializer.Deserialize(tr);
                //    if (result.Place != null)
                //    {
                //        point.Coordinate = new Coordinate(result.Place.Lat, result.Place.Lon);
                //        point.FormattedAddress = result.Place.Display_name;
                //        point.SetSearchEngineStatus("OK");
                //        point.Conteiner = (object)result.Place;
                //        point.SearchEngine = SearchEngine.Osm;
                //        //point.PStatus = ProcessStatus.;
                //    }
                //    else
                //    {
                //        point.SetSearchEngineStatus("ZERO_RESULTS");
                //    }

                //    //XmlSerializer smr = new XmlSerializer(typeof(Searchresults));
                //    //using (StringWriter tw = new StringWriter())
                //    //{
                //    //    smr.Serialize(tw, result);
                //    //    point.Xml = tw.ToString();
                //    //}

                //    _logger.Info(string.Format("{0} SearchEngineStatus:{5}, {1} {2} Lat={3}, Lng={4}",
                //        point.CardId.ToString(),
                //        "Point Get OSM:",
                //        point.FormattedAddress,
                //        point.Coordinate != null ? point.Coordinate.Lat : "none",
                //        point.Coordinate != null ? point.Coordinate.Lng : "none",
                //        point.PStatus.ToString()
                //    ));

                //    point.Save(hdb);

                //    _logger.Info(string.Format("{0} {1}", point.CardId.ToString(), "Point Set Data in DB"));

                //    return point;
                //}
            } catch (Exception ex)
            {
                return(point);
            }
        }
Ejemplo n.º 17
0
        static void Main(string[] args)
        {
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.QueueDeclare(queue: "ApiGeo", durable: false, exclusive: false, autoDelete: false, arguments: null);
                    channel.BasicQos(0, 1, false);
                    var consumer = new EventingBasicConsumer(channel);
                    channel.BasicConsume(queue: "ApiGeo", autoAck: false, consumer: consumer);

                    consumer.Received += (model, ea) =>
                    {
                        string response = null;

                        var body       = ea.Body.ToArray();
                        var props      = ea.BasicProperties;
                        var replyProps = channel.CreateBasicProperties();
                        replyProps.CorrelationId = props.CorrelationId;

                        try
                        {
                            var jsonModel = Encoding.UTF8.GetString(ea.Body.ToArray());
                            var objGeo    = JsonSerializer.Deserialize(jsonModel, typeof(Geo));
                            if (objGeo is Geo)
                            {
                                var geo = (Geo)objGeo;
                                var x   = new ForwardGeocoder();
                                var r   = x.Geocode(new ForwardGeocodeRequest
                                {
                                    queryString = geo.Numero.ToString() + " " + geo.Calle + ", " + geo.Ciudad + " " + geo.CodigoPostal + ", " + geo.Provincia + ", " + geo.Pais,
                                    BreakdownAddressElements = true,
                                    ShowExtraTags            = true,
                                    ShowAlternativeNames     = true,
                                    ShowGeoJSON = true
                                });
                                r.Wait();
                                geo.Latitud  = r.Result[0].Latitude;
                                geo.Longitud = r.Result[0].Longitude;

                                response = JsonSerializer.Serialize(geo, typeof(Geo));
                            }
                        }
                        catch (Exception e)
                        {
                            response = "";
                        }
                        finally
                        {
                            var responseBytes = Encoding.UTF8.GetBytes(response);
                            channel.BasicPublish(exchange: "", routingKey: props.ReplyTo, basicProperties: replyProps, body: responseBytes);
                            channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
                        }
                    };
                    Console.ReadLine();
                }
        }
Ejemplo n.º 18
0
 public OsmProxyService(ICachedResponseStore cacheStore, ForwardGeocoder geocoder)
 {
     _cacheStore = cacheStore;
     _geocoder   = geocoder;
 }