public void GetHiResMapsFromDbfList(string file, bool deepSearch = true)
        {
            List <Feature> features;
            List <string>  noCovered;

            features = PrepareLists(file, out noCovered, true);

            Downloader downloader = new Downloader();
            Recognizer reco       = new Recognizer();

            foreach (var f in features)
            {
                string    redcode = f.Attributes["REDCODE"] as string;
                RadioInfo r       = RadioInfo.ParseRedcode(redcode);
                if (skipRadios.ContainsKey(r.makeKey()) == false &&
                    noCovered.Contains(r.makeKey()) == false)
                //if (r.Prov == "02" && (r.Dpto != "01" || r.Fraccion != "01"))
                {
                    FraccionInfo fraccion = new FraccionInfo(r.Prov, r.Dpto, r.Fraccion);
                    if (r.isDone(true) == false && r.isNotRequired(true) == false && downloader.getFraccionInfo(fraccion))
                    {
                        // le recalcula el extent
                        reco.RecognizeRadio(r, false, deepSearch);
                        // le pone una proporción igual a la de la fracción
                        if (r.Geometry != null && r.GeoExtents.Width < fraccion.ExtentsEnvelope.Width * .75F &&
                            r.GeoExtents.Height < fraccion.ExtentsEnvelope.Height * .75F)
                        {
                            string extents = CalculateZoomedExtents(r, fraccion);
                            downloader.getMapaRadio(r, extents, true);
                        }
                        else
                        {
                            File.WriteAllText(r.getNotRequiredName(true), "-");
                        }
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }
            }
        }
        private static string CalculateZoomedExtents(RadioInfo r, FraccionInfo fraccion)
        {
            double fraccionRatio = fraccion.ExtentsProportion;
            double radioRatio    = r.GeoExtentsProportion;

            string   extents;
            Envelope newExtent;

            if (radioRatio < fraccionRatio)
            {
                // hay que agrandarla verticalmente
                double extra = fraccionRatio * r.GeoExtents.Width - r.GeoExtents.Height;
                newExtent = new Envelope(r.GeoExtents.MinX,
                                         r.GeoExtents.MaxX,
                                         r.GeoExtents.MinY - extra / 2,
                                         r.GeoExtents.MaxY + extra / 2);
            }
            else
            {
                // hay que agrandarla horizontalmente
                double extra = r.GeoExtents.Height / fraccionRatio - r.GeoExtents.Width;
                newExtent = new Envelope(r.GeoExtents.MinX - extra / 2,
                                         r.GeoExtents.MaxX + extra / 2,
                                         r.GeoExtents.MinY,
                                         r.GeoExtents.MaxY);
            }
            double xMargin = newExtent.Width * .4F;
            double yMargin = newExtent.Height * .4F;

            extents = (newExtent.MinX - xMargin) + " " +
                      (newExtent.MinY - yMargin) + " " +
                      (newExtent.MaxX + xMargin) + " " +
                      (newExtent.MaxY + yMargin);

            extents = extents.Replace(",", ".");
            return(extents);
        }
        public void GetMapsFromDbfList(string file)
        {
            List <Feature> features;
            List <string>  noCovered;

            features = PrepareLists(file, out noCovered);

            Downloader downloader = new Downloader();

            foreach (var f in features)
            {
                string    redcode = f.Attributes["REDCODE"] as string;
                RadioInfo r       = RadioInfo.ParseRedcode(redcode);
                if (skipRadios.ContainsKey(r.makeKey()) == false &&
                    noCovered.Contains(r.makeKey()) == false)
                {
                    FraccionInfo fraccion = new FraccionInfo(r.Prov, r.Dpto, r.Fraccion);
                    if (downloader.getFraccionInfo(fraccion))
                    {
                        downloader.getMapaRadio(r, fraccion.Extents);
                    }
                }
            }
        }
Exemple #4
0
        public bool getFraccionInfo(FraccionInfo fraccion)
        {
            var args = new NameValueCollection()
            {
                { "la", "layer_g_Provincias%7Clayer_g_Departamentos%7Clayer_g_Im%E1genes_Satelitales%7Clayer_g_Lagos_y_Lagunas%7Clayer_g_L%EDmites_Rurales%7Clayer_g_Rutas_y_Caminos%7Clayer_g_R%EDos_y_Arroyos%7Clayer_g_Fracciones_Rurales%7Clayer_g_Radios_Rurales%7Clayer_g_Localidades" }, {
                    "qProvincias", fraccion.Prov
                }, {
                    "qDepartamentos", fraccion.Dpto
                }, {
                    "qFracciones", fraccion.Fraccion
                }, {
                    "extent", "3527386.625+6810267.5+3544652.625+6827533.5"
                }, {
                    "old_mapa_x", ""
                }, {
                    "old_mapa_y", ""
                }, {
                    "mode", "13"
                }, {
                    "togglecapa", "i_selectores"
                }, {
                    "zsize", "1"
                }, {
                    "zoomdir", "pan"
                }, {
                    "ver_escala", "1"
                }, {
                    "escala", "20217000"
                }
            };

            //extent:1688948 3601619.5 5996706 7909377.5

            byte[] response;
            if (fraccion.isDone())
            {
                response = File.ReadAllBytes(fraccion.getTxtName());
            }
            else
            {
                Console.WriteLine("Getting radio list " + fraccion.makeName() + "...");
                response = Post(Context.url, args);
            }
            if (response == null)
            {
                Context.Log("timeouts", fraccion);
                return(false);
            }
            string htmlRoot = Saver(response, fraccion);
            // extra el extent
            string extent = getHidden(htmlRoot, "extent");

            if (extent == null)
            {
                File.Delete(fraccion.getTxtName());
                Context.Log("errors", "No data for fraccion " + fraccion.makeName());
                return(false);
            }

            // lista los radios
            int    i       = htmlRoot.IndexOf(">Seleccione el radio");
            int    iEnd    = htmlRoot.IndexOf("</select>", i);
            string subText = htmlRoot.Substring(i, iEnd - i);

            string[] parts = subText.Split(new string[] { "<option value=\"" }, StringSplitOptions.None);

            fraccion.Extents = extent;

            for (int n = 1; n < parts.Length; n++)
            {
                string    p   = parts[n];
                string[]  tmp = p.Split(new string[] { "\"" }, StringSplitOptions.None);
                RadioInfo ri  = new RadioInfo(fraccion);
                ri.Radio = tmp[0];
                fraccion.Radios.Add(ri);
            }
            return(true);
        }
Exemple #5
0
 public RadioInfo(FraccionInfo frac)
 {
     Prov     = frac.Prov;
     Dpto     = frac.Dpto;
     Fraccion = frac.Fraccion;
 }