public void RecognizeRadioPolygon(RadioInfo r, bool deepSearch = true) { Console.Write("Analyzing " + r.makeKey() + "..."); string file = r.getGifName(); string fileHiRes = r.getGifName(true); Image pImage = null; bool useHiRes = File.Exists(fileHiRes); if (useHiRes) { pImage = Bitmap.FromFile(fileHiRes); } else { pImage = Bitmap.FromFile(file); } var polygon = RecognizeImagePolygon(pImage); r.Polygon = polygon; r.ImageExtents = pImage.Size; r.Extents = Downloader.ReadExtents(r.getTxtName(useHiRes)); if (pImage != null) { pImage.Dispose(); } Console.WriteLine("Done."); }
private void RecognizeRadioGeometry(RadioInfo radio, bool project = true) { if (radio.Polygon.Count == 0 || radio.Polygon[0].Count == 0) { return; } radio.TotalPerimeter = 0; List <List <Coordinate> > puntosTotal = new List <List <Coordinate> >(); double xMin = double.MaxValue, xMax = double.MinValue, yMin = double.MaxValue, yMax = double.MinValue; foreach (var polygon in radio.Polygon) { List <Coordinate> puntos = CreatePointsSet(radio, project, ref xMin, ref xMax, ref yMin, ref yMax, polygon); puntosTotal.Add(puntos); } /////// GeometryFactory fc = new GeometryFactory(); if (puntosTotal.Count > 1) { List <IPolygon> geoms = new List <IPolygon>(); foreach (var puntos in puntosTotal) { geoms.Add(fc.CreatePolygon(puntos.ToArray())); } radio.Geometry = fc.CreateMultiPolygon(geoms.ToArray()); } else { radio.Geometry = fc.CreatePolygon(puntosTotal[0].ToArray()); } radio.GeoExtents = new Envelope(xMin, xMax, yMin, yMax); }
public static RadioInfo ParseRedcode(string redcode) { var ret = new RadioInfo(); ret.Prov = redcode.Substring(0, 2); ret.Dpto = redcode.Substring(2, 3); ret.Fraccion = redcode.Substring(5, 2); ret.Radio = redcode.Substring(7, 2); return(ret); }
private static List <Coordinate> CreatePointsSet(RadioInfo radio, bool project, ref double xMin, ref double xMax, ref double yMin, ref double yMax, Polygon polygon) { if (polygon[0] != polygon[polygon.Count - 1]) { if (polygon.Count == 2) { // le hace triángulo polygon.Add(new System.Drawing.Point(polygon[0].X, polygon[1].Y)); } polygon.Add(polygon[0]); } ////////////////////// Coordinate from = radio.GetFrom(); Coordinate to = radio.GetTo(); double xScale = (to.X - from.X) / radio.ImageExtents.Width; double yScale = (to.Y - from.Y) / radio.ImageExtents.Height; List <Coordinate> puntos = new List <Coordinate>(); IPoint lastP = null; foreach (System.Drawing.Point p in polygon) { var newPoint = new NetTopologySuite.Geometries.Point(xScale * p.X + from.X, yScale * (radio.ImageExtents.Height - p.Y) + from.Y); IPoint point; if (project) { point = Projections.UnprojectPoint(newPoint, Context.Projection); } else { point = newPoint; } xMin = Math.Min(point.X, xMin); xMax = Math.Max(point.X, xMax); yMin = Math.Min(point.Y, yMin); yMax = Math.Max(point.Y, yMax); puntos.Add(new Coordinate(point.X, point.Y)); if (lastP != null) { radio.TotalPerimeter += PolygonFinder.EuclideanDist(point, lastP); } lastP = point; } return(puntos); }
public static RadioInfo FromFeature(NetTopologySuite.Features.Feature f) { var ret = new RadioInfo(); string prov = f.Attributes["PROV"] as string; string dpto = f.Attributes["DEPTO"] as string; string frac = f.Attributes["FRAC"] as string; string rad = f.Attributes["RADIO"] as string; ret.Prov = prov; ret.Dpto = dpto; ret.Fraccion = frac; ret.Radio = rad; return(ret); }
public void loadSkipRadios(string file) { Console.WriteLine("Cargando radios conocidos..."); List <Feature> features = FileReaders.ReadDbasefile(file); foreach (var f in features) { RadioInfo ri = RadioInfo.FromFeature(f); if (ri.Radio != "" && ri.Fraccion != "" && ri.Radio != "00" && ri.Fraccion != "00") { skipRadios[ri.makeKey()] = true; } } Console.WriteLine(features.Count + " radios agregados."); }
public static RadioInfo FromFeatureRedcode(NetTopologySuite.Features.Feature f, string redcodeField = "REDCODE") { var ret = new RadioInfo(); string data = f.Attributes[redcodeField] as string; string prov = data.Substring(0, 2); string dpto = data.Substring(2, 3); string frac = data.Substring(5, 2); string rad = data.Substring(7, 2); ret.Prov = prov; ret.Dpto = dpto; ret.Fraccion = frac; ret.Radio = rad; return(ret); }
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 bool ShouldAddFeature(Feature f) { string redcode = f.Attributes["REDCODE"] as string; RadioInfo r = RadioInfo.ParseRedcode(redcode); if (String.IsNullOrEmpty(this.ProvFilter)) { return(true); } if (this.ProvFilter != r.Prov) { return(false); } if (String.IsNullOrEmpty(this.DptoFilter)) { return(true); } if (this.DptoFilter != r.Dpto) { return(false); } if (String.IsNullOrEmpty(this.FracFilter)) { return(true); } if (this.FracFilter != r.Fraccion) { return(false); } if (String.IsNullOrEmpty(this.RadioFilter)) { return(true); } if (this.RadioFilter != r.Radio) { return(false); } else { return(true); } }
private List <Feature> PrepareLists(string file, out List <string> noCovered, bool hiRes = false) { List <Feature> allFeatures = new List <Feature>(); allFeatures = FileReaders.ReadDbasefile(file); var features = FilterFeatures(allFeatures); Console.WriteLine(""); Console.WriteLine("Calculando radios pendientes..."); int total = 0; int pendientes = 0; noCovered = new List <string>(); string nocoveredFile = Context.ResolveFilename("no_covered.txt"); if (File.Exists(nocoveredFile)) { noCovered.AddRange(File.ReadAllLines(nocoveredFile)); } foreach (var f in features) { string redcode = f.Attributes["REDCODE"] as string; RadioInfo r = RadioInfo.ParseRedcode(redcode); if (skipRadios.ContainsKey(r.makeKey()) == false) { total++; string name = r.makeName(); if (!r.isDone(hiRes) && !r.isNotRequired(hiRes) && noCovered.Contains(r.makeKey()) == false) { pendientes++; } } } Console.WriteLine("Pendientes: " + pendientes + "."); Console.WriteLine("Descubiertos sin cobertura: " + noCovered.Count + "."); Console.WriteLine("Total: " + total + "."); return(features); }
public static List <RadioInfo> ReadRadiosFromFolder(string folder) { List <RadioInfo> radios = new List <RadioInfo>(); foreach (string file in Directory.GetFiles(folder, "*.gif")) { string name = Path.GetFileNameWithoutExtension(file); name = name.Replace("prov", ""); string[] parts = name.Split('-'); if (parts.Length == 4) { RadioInfo r1 = new RadioInfo(); r1.Prov = parts[0]; r1.Dpto = parts[1]; r1.Fraccion = parts[2]; r1.Radio = parts[3]; radios.Add(r1); } } return(radios); }
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); } } } }
public void getMapaRadio(RadioInfo radio, string extent, bool useHiResNames = false) { mapCount++; if (radio.isDone(useHiResNames)) { if (mapCount % 50 == 0) { Console.Write("."); } return; } Console.WriteLine("Getting MAP " + radio.makeName() + " (" + mapCount.ToString() + ")..."); //return; List <string> radios = new List <string>(); var args = new NameValueCollection() { { "la", "" }, { "qProvincias", radio.Prov }, { "qDepartamentos", radio.Dpto }, { "qFracciones", radio.Fraccion }, { "qRadios", radio.Radio }, { "extent", extent }, { "old_mapa_x", "" }, { "old_mapa_y", "" }, { "mode", "14" }, { "togglecapa", "i_selectores" }, { "zsize", "1" }, { "zoomdir", "pan" }, { "ver_escala", "2" }, { "escala", "26000" } }; //extent:1688948 3601619.5 5996706 7909377.5 // 4026334.96104 6061347.65263 4031832.35085 6066845.04243 retry3: var response = Post(Context.url, args); if (response == null) { Context.Log("timeouts", radio); return; } string htmlRoot = Saver(response, radio, useHiResNames); var notFound = htmlRoot.IndexOf("No encontré cobertura para"); if (notFound > 0) { Context.Log("no_covered", radio.makeKey()); return; } Console.WriteLine("Gotfile!"); int i = htmlRoot.IndexOf("/temp/image"); if (i == -1) { Context.Log("errors", "No map for radio " + radio.makeName()); return; } int iEnd = htmlRoot.IndexOf(".gif", i); string gif = Context.url2 + htmlRoot.Substring(i, iEnd - i + 4); var argument = gif; byte[] response2 = null; using (WebDownload client = new WebDownload()) { int tries = 0; retry2: try { response2 = client.DownloadData(gif); Thread.Sleep(1 * 1000); } catch { tries++; if (tries == 8) { throw; } Thread.Sleep(30 * 1000); goto retry3; } } GifSaver(response2, radio, useHiResNames); //Process.Start("iexplore.exe", argument); //MessageBox.Show("Traje " + radios.Count.ToString() + " radios"); }
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); }
public void RecognizeRadio(RadioInfo r, bool project = true, bool deepSearch = true) { RecognizeRadioPolygon(r, deepSearch); RecognizeRadioGeometry(r, project); }