Esempio n. 1
0
 public FrmAnadeElemento(DireccionPuntoSOB listaObservada, IGeocodificador geocodificador)
 {
     InitializeComponent();
     _listaObservada = listaObservada;
     _dp             = new DireccionPunto();
     _geocodificador = geocodificador;
 }
Esempio n. 2
0
        private void btnGeoCodifica_Click(object sender, EventArgs e)
        {
            DireccionPunto dp = _geocodificador.GetCoordenadas(txtDireccion.Text);

            _dp = new DireccionPunto();
            _flagReferenciando = true;
            if (dp != null)
            {
                _dp.key       = dp.Direccion;
                _dp.Direccion = dp.Direccion;
                _dp.Latitud   = dp.Latitud;
                _dp.Longitud  = dp.Longitud;
                ((GeocodificadorBase)_geocodificador).utm30Ntransformacion(dp);
                _dp.X                    = dp.X;
                _dp.Y                    = dp.Y;
                _dp.Pais                 = dp.Pais;
                _dp.Municipio            = dp.Municipio;
                _dp.NivelRegional2       = dp.NivelRegional2;
                _dp.NivelRegional1       = dp.NivelRegional1;
                txtLat.Text              = Convert.ToString(_dp.Latitud);
                txtLon.Text              = Convert.ToString(_dp.Longitud);
                txtX.Text                = Convert.ToString(_dp.X);
                txtY.Text                = Convert.ToString(_dp.Y);
                labPais.Text             = dp.Pais;
                labProvincia.Text        = dp.NivelRegional2;
                labRegion.Text           = dp.NivelRegional1;
                labMunicipio.Text        = dp.Municipio;
                _dp.IsGeocodificado      = true;
                _dp.GeoreferenciadorDeno = _geocodificador.Deno;
                labGeo.Text              = _dp.GeoreferenciadorDeno;
            }
            _flagReferenciando = false;
        }
Esempio n. 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="dp"></param>
        private void anadeElementoListaVista(DireccionPunto dp)
        {
            if (items.Count == 1)
            {
                listView1.Items.Clear();
            }

            var it = new ListViewItem {
                Name = dp.Direccion, Text = dp.Direccion, Tag = dp.key
            };

            it.SubItems.Add(dp.Latitud.ToString(CultureInfo.InvariantCulture));
            it.SubItems.Add(dp.Longitud.ToString(CultureInfo.InvariantCulture));
            it.SubItems.Add(dp.X.ToString(CultureInfo.InvariantCulture));
            it.SubItems.Add(dp.Y.ToString(CultureInfo.InvariantCulture));
            it.SubItems.Add(dp.Municipio);
            it.SubItems.Add(dp.NivelRegional2);
            it.SubItems.Add(dp.NivelRegional1);
            it.SubItems.Add(dp.Pais);
            it.SubItems.Add(dp.GeoreferenciadorDeno);

            it.BackColor = !dp.IsGeocodificado ? Color.Yellow : Color.White;

            listView1.Items.Add(it);
        }
Esempio n. 4
0
 public FrmModificaElemento(DireccionPuntoSOB listaObservada, string key, IGeocodificador geocodificador)
 {
     InitializeComponent();
     _listaObservada = listaObservada;
     _dp             = listaObservada[key];
     _geocodificador = geocodificador;
 }
Esempio n. 5
0
        public override DireccionPunto GetCoordenadas(string direccion)
        {
            try
            {
                double lat, lon;

                // Asignamos las opciones
                ConfidenceFilter[] filters = new ConfidenceFilter[1];
                filters[0] = new ConfidenceFilter();
                filters[0].MinimumConfidence = GeocodeService.Confidence.High;

                // Añadimos los filtros
                GeocodeOptions geocodeOptions = new GeocodeOptions();
                geocodeOptions.Filters = filters;
                geocodeRequest.Options = geocodeOptions;

                geocodeRequest.Query = direccion;

                // Realizamos la petición
                GeocodeServiceClient geocodeService  = new GeocodeServiceClient("BasicHttpBinding_IGeocodeService");
                GeocodeResponse      geocodeResponse = geocodeService.Geocode(geocodeRequest);
                DireccionPunto       dp = new DireccionPunto();

                if (geocodeResponse.Results.Length > 0)
                {
                    lat               = geocodeResponse.Results[0].Locations[0].Latitude;
                    lon               = geocodeResponse.Results[0].Locations[0].Longitude;
                    dp.Direccion      = direccion;
                    dp.Latitud        = lat;
                    dp.Longitud       = lon;
                    dp.Pais           = geocodeResponse.Results[0].Address.CountryRegion;
                    dp.NivelRegional2 = geocodeResponse.Results[0].Address.District;
                    dp.NivelRegional1 = geocodeResponse.Results[0].Address.AdminDistrict;
                    dp.Municipio      = geocodeResponse.Results[0].Address.Locality;
                }
                else
                {
                    dp.Latitud  = double.NaN;
                    dp.Longitud = double.NaN;
                }
                utm30Ntransformacion(dp);
                dp.IsGeocodificado = true;
                return(dp);
            }
            catch (Exception ex)
            {
                RaiseMensajeEvent("Bing MAPS - " + ex.Message);
                return(null);
            }
        }
Esempio n. 6
0
        private void btnAnade_Click(object sender, EventArgs e)
        {
            try
            {
                DireccionPunto ndp = new DireccionPunto();
                ndp.Direccion            = txtDireccion.Text;
                ndp.Latitud              = Convert.ToDouble(txtLat.Text);
                ndp.Longitud             = Convert.ToDouble(txtLon.Text);
                ndp.X                    = Convert.ToDouble(txtX.Text);
                ndp.Y                    = Convert.ToDouble(txtY.Text);
                ndp.IsGeocodificado      = _dp.IsGeocodificado;
                ndp.GeoreferenciadorDeno = _dp.GeoreferenciadorDeno;
                ndp.Municipio            = _dp.Municipio;
                ndp.NivelRegional1       = _dp.NivelRegional1;
                ndp.NivelRegional2       = _dp.NivelRegional2;
                ndp.Pais                 = _dp.Pais;
                if (String.IsNullOrEmpty(_dp.key))
                {
                    _dp.key = txtDireccion.Text;
                }
                ndp.key = _dp.key;
                String key = _dp.key;

                if (_listaObservada.ContainsKey(_dp.key))
                {
                    int i = 1;
                    while (_listaObservada.ContainsKey(ndp.key))
                    {
                        ndp.key = key + "_" + Convert.ToString(i);
                        i++;
                    }
                    _listaObservada.Add(ndp.key, ndp);
                }
                else
                {
                    _listaObservada.Add(ndp.key, ndp);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error", "Verifique los campos numéricos : " + ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 7
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void listView1_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.Delete)
     {
         if (listView1.SelectedItems.Count == 1)
         {
             DireccionPunto dp = items[(string)listView1.SelectedItems[0].Tag];
             if (
                 MessageBox.Show(
                     String.Format("Atencion:\n Va a eliminar : {0}, {1} {2} {3} {4}\n Lat : {5} \n Lon : {6}",
                                   dp.Direccion, dp.Municipio, dp.NivelRegional2, dp.NivelRegional1, dp.Pais,
                                   Convert.ToString(dp.Latitud), Convert.ToString(dp.Longitud)),
                     Resources.msg_Confirmación_de_Borrado, MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) ==
                 DialogResult.Yes)
             {
                 items.Remove(dp.key);
             }
         }
     }
 }
Esempio n. 8
0
        public void utm30Ntransformacion(DireccionPunto dp)
        {
            double lat = dp.Latitud;
            double lon = dp.Longitud;

            if (!double.IsNaN(lat))
            {
                try
                {
                    //string wktTo = "PROJCS[\"ED50 / UTM zone 30N\",GEOGCS[\"ED50\",DATUM[\"D_European_1950\",SPHEROID[\"International_1924\",6378388,297]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-3],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]";
                    //string wktTo = "PROJCS[\"WGS_1984_UTM_Zone_30N\",GEOGCS[\"GCS_WGS_1984\",DATUM[\"D_WGS_1984\",SPHEROID[\"WGS_1984\",6378137,298.257223563]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",-3],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",0],UNIT[\"Meter\",1]]";

                    string wktTo = GeoToMap.Properties.Settings.Default.Proyeccion;

                    ICoordinateSystem sistema1 = GeographicCoordinateSystem.WGS84;

                    CoordinateTransformationFactory factoriaTransformaciones = new CoordinateTransformationFactory();

                    ICoordinateSystem sistema2 =
                        (ICoordinateSystem)SharpMap.Converters.WellKnownText.CoordinateSystemWktReader.Parse(wktTo);

                    ICoordinateTransformation transformacion =
                        factoriaTransformaciones.CreateFromCoordinateSystems(sistema1, sistema2);

                    double[] coords = transformacion.MathTransform.Transform(new double[] { lon, lat });

                    //Proyeccion

                    dp.X = coords[0];
                    dp.Y = coords[1];
                }
                catch (Exception ex)
                {
                    RaiseMensajeEvent(String.Format("ERROR EN LA TRANSFORMACIÓN DE COORDENADAS: {0}", ex.Message));
                }
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Aunque List<RegistroModel> es una variable global, en el próximo incremento de geoToMap, el
 /// proceso de georreferenciación se desagregará.
 /// </summary>
 /// <param name="codificador"></param>
 /// <param name="direcciones"></param>
 private void ProcesoLoteGeoreferenciacion(IGeocodificador codificador, List <RegistroModel> direcciones)
 {
     try
     {
         BeginInvoke(new DlgMensaje(escribeConsolaNegro),
                     new object[]
         {
             String.Format("Se han leído {0} direcciones",
                           direcciones.Count.ToString(CultureInfo.InvariantCulture))
         });
         int i = 0;
         items.Clear();
         BeginInvoke(new DlgVoid(() => listView1.Items.Clear()));
         foreach (RegistroModel registro in direcciones)
         {
             if (!String.IsNullOrEmpty(registro.Direccion))
             {
                 int i1 = i;
                 BeginInvoke(
                     new DlgVoid(
                         () => progressBar1.Value = (int)(((double)(i1 + 1) / (double)direcciones.Count) * 100)));
                 i++;
                 DireccionPunto dp = codificador.GetCoordenadas(registro.Direccion);
                 if (dp != null)
                 {
                     dp.key = registro.Id;
                     Invoke(new DlgVoid(() => items.Add(dp.key, dp)));
                     //TO DO Posible efecto secundario EVITAR!!!
                     registro.Id = dp.key;
                 }
             }
         }
     }
     catch (Exception ex)
     {
     }
 }
        public override DireccionPunto GetCoordenadas(string direccion)
        {
            try
            {
                DireccionPunto dp      = new DireccionPunto();
                WebRequest     request = WebRequest.Create(string.Format(sUrl1, HttpUtility.UrlEncode(direccion)));
                request.Method = "GET";
                WebResponse response = request.GetResponse();
                Stream      stream   = response.GetResponseStream();
                if (stream != null)
                {
                    StreamReader sr   = new StreamReader(stream);
                    XDocument    xdoc = XDocument.Load(sr);

                    List <XElement> Place = (from nReg in xdoc.Descendants()
                                             where nReg.Name == "place"
                                             select nReg).ToList();

                    string sLat =
                        (from nReg in Place.Attributes() where nReg.Name == "lat" select nReg.Value).FirstOrDefault();
                    string sLong =
                        (from nReg in Place.Attributes() where nReg.Name == "lon" select nReg.Value).FirstOrDefault();
                    double lat = 0.0;
                    double lon = 0.0;

                    if (!string.IsNullOrEmpty(sLat))
                    {
                        lat = double.Parse(sLat, CultureInfo.InvariantCulture);
                    }

                    if (!string.IsNullOrEmpty(sLong))
                    {
                        lon = double.Parse(sLong, CultureInfo.InvariantCulture);
                    }

                    string pais      = "";
                    string localidad =
                        Place.Descendants().Where(obj => obj.Name == "city").Select(obj => obj.Value).FirstOrDefault();
                    string provincia =
                        Place.Descendants().Where(obj => obj.Name == "county").Select(obj => obj.Value).FirstOrDefault();
                    string region =
                        Place.Descendants().Where(obj => obj.Name == "state").Select(obj => obj.Value).FirstOrDefault();
                    var paisNodo =
                        Place.Descendants().Where(obj => obj.Name == "country_code").Select(obj => obj.Value).
                        FirstOrDefault();
                    if (
                        paisNodo != null)
                    {
                        pais = paisNodo.ToUpperInvariant();
                    }
                    dp.Latitud        = lat;
                    dp.Longitud       = lon;
                    dp.Municipio      = localidad;
                    dp.NivelRegional2 = provincia;
                    dp.NivelRegional1 = region;
                    dp.Pais           = pais;
                    Console.WriteLine(Place.FirstOrDefault());
                    dp.IsGeocodificado = true;
                    return(dp);
                }
                return(null);
            }
            catch (Exception ex)
            {
                RaiseMensajeEvent(ex.Message);
                return(null);
            }
        }
Esempio n. 11
0
        public override DireccionPunto GetCoordenadas(string direccion)
        {
            try
            {
                DireccionPunto dp = new DireccionPunto();
                string         lat = "", lon = "";
                WebRequest     request = WebRequest.Create(string.Format(sUrl1, HttpUtility.UrlEncode(direccion)));
                request.Method = "GET";
                WebResponse response = request.GetResponse();
                Stream      stream   = response.GetResponseStream();
                if (stream != null)
                {
                    StreamReader sr   = new StreamReader(stream);
                    XDocument    xdoc = XDocument.Load(sr);

                    String status =
                        (from nReg in xdoc.Descendants() where nReg.Name == "status" select nReg.Value).FirstOrDefault();

                    if (status == "OVER_QUERY_LIMIT")
                    {
                        RaiseMensajeEvent("Over Query recibido desde Google Maps. Esperamos 2 segundos");
                        Thread.Sleep(2000);
                        return(this.GetCoordenadas(direccion));
                    }

                    IEnumerable <XElement> AddressComponents = from nReg in xdoc.Descendants()
                                                               where nReg.Name == "address_component"
                                                               select nReg;

                    //Localidad de salida
                    IEnumerable <XElement> municipioNodos = (from nReg in xdoc.Descendants()
                                                             where nReg.Name == "type" && nReg.Value == "locality"
                                                             select
                                                             nReg.ElementsBeforeSelf().FirstOrDefault(
                                                                 obj => obj.Name == "long_name")).Where(
                        obj => obj != null);

                    var nombreMunicipio = municipioNodos.FirstOrDefault();
                    if (nombreMunicipio != null)
                    {
                        dp.Municipio = nombreMunicipio.Value;
                    }


                    //Provincia
                    IEnumerable <XElement> provinciaNodos = (from nReg in xdoc.Descendants()
                                                             where
                                                             nReg.Name == "type" &&
                                                             nReg.Value == "administrative_area_level_2"
                                                             select
                                                             nReg.ElementsBeforeSelf().FirstOrDefault(
                                                                 obj => obj.Name == "long_name")).Where(
                        obj => obj != null);

                    var nombreProvincia = provinciaNodos.FirstOrDefault();
                    if (nombreProvincia != null)
                    {
                        dp.NivelRegional2 = nombreProvincia.Value;
                    }


                    //Region
                    IEnumerable <XElement> regionNodos = (from nReg in xdoc.Descendants()
                                                          where
                                                          nReg.Name == "type" &&
                                                          nReg.Value == "administrative_area_level_1"
                                                          select
                                                          nReg.ElementsBeforeSelf().FirstOrDefault(
                                                              obj => obj.Name == "short_name")).Where(
                        obj => obj != null);

                    var nombreRegion = regionNodos.FirstOrDefault();
                    if (nombreRegion != null)
                    {
                        dp.NivelRegional1 = nombreRegion.Value;
                    }


                    //Pais
                    IEnumerable <XElement> paisNodos = (from nReg in xdoc.Descendants()
                                                        where nReg.Name == "type" && nReg.Value == "country"
                                                        select
                                                        nReg.ElementsBeforeSelf().FirstOrDefault(
                                                            obj => obj.Name == "short_name")).Where(
                        obj => obj != null);

                    var nombrePais = paisNodos.FirstOrDefault();
                    if (nombrePais != null)
                    {
                        dp.Pais = nombrePais.Value;
                    }


                    IEnumerable <XElement> xgeometry = from nReg in xdoc.Descendants()
                                                       where nReg.Name == "location"
                                                       select nReg;

                    XElement xLatLong = xgeometry.FirstOrDefault();
                    if (xLatLong != null)
                    {
                        var firstOrDefault = xLatLong.Descendants().FirstOrDefault(obj => obj.Name == "lat");
                        if (firstOrDefault != null)
                        {
                            lat = firstOrDefault.Value;
                        }
                        var orDefault = xLatLong.Descendants().FirstOrDefault(obj => obj.Name == "lng");
                        if (orDefault != null)
                        {
                            lon = orDefault.Value;
                        }
                    }
                    dp.Direccion = direccion;
                    if (!String.IsNullOrEmpty(lat))
                    {
                        dp.Latitud = Double.Parse(lat.Replace('.', ','));
                    }

                    if (!String.IsNullOrEmpty(lon))
                    {
                        dp.Longitud = Convert.ToDouble(lon.Replace('.', ','));
                    }

                    utm30Ntransformacion(dp);

                    dp.IsGeocodificado = true;

                    return(dp);
                }
                return(null);
            }
            catch (Exception ex)
            {
                RaiseMensajeEvent(ex.Message);
                return(null);
            }
        }