private Dictionary <string, int> ValidateItems() { if (!fileAdded) { return(null); } Progress.Caption = "Obteniendo geografía padre"; Dictionary <string, int> ci = null; if (iParent != "") { //Trae todos los items de la geografía padre para asociar. ci = context.Data.Session.Query <GeographyItem>() .Where(x => x.Geography.Id == current.Parent.Id) .Select(x => new { Id = x.Id.Value, x.Code }) .ToDictionary(x => x.Code, x => x.Id); } Progress.Caption = "Validando ítems"; ShapeOperations.ValidateParentAndShapes(Progress, ci, Basename + ".shp", iCode, iParent); if (dbfMissingFilename != null) { Progress.Caption = "Validando ítems faltantes"; ShapeOperations.ValidateParentAndShapes(Progress, ci, dbfMissingFilename, iCode, iParent); } return(ci); }
private Dictionary <string, int> ValidateItems() { if (!fileAdded) { return(null); } Progress.Caption = "Validando ítems"; Dictionary <string, int> ci = null; if (iParent != null) { // No es países. Trae todos los items de la clipping padre para asociar. ci = context.Data.Session.Query <ClippingRegionItem>() .Where(x => x.ClippingRegion.Id == current.Parent.Id) .Select(x => new { Id = x.Id.Value, x.Code }) .ToDictionary(x => x.Code, x => x.Id); } ShapeOperations.ValidateParentAndShapes(Progress, ci, Basename + ".shp", iCode, iParent, skipOrphans); return(ci); }
private static void ValidateFeatures(Progress Progress, Dictionary <string, int> items, string codeColumn, string iParent, List <NetTopologySuite.Features.Feature> features, bool checkFeatures = true, bool skipOrphans = false) { Progress.Total = features.Count; List <string> invalid = new List <string>(); List <string> noParent = new List <string>(); int row = 1; List <string> emptyCenter = new List <string>(); foreach (var feature in features) { object ocode = feature.Attributes[codeColumn]; string code = (ocode == null ? null : ocode.ToString()); if (string.IsNullOrEmpty(code)) { throw new MessageException("El valor para el código no puede se nulo. Fila: " + row.ToString()); } row++; if (checkFeatures && feature.Geometry.IsValid == false) { invalid.Add(code); } if (checkFeatures && feature.Geometry.Centroid.IsEmpty) { emptyCenter.Add(code); } if (items != null) { object oParent = feature.Attributes[iParent]; string parent = (oParent == null ? null : oParent.ToString()); if (!items.ContainsKey(parent)) { if (!skipOrphans) { if (parent != code) { noParent.Add(code + "=>" + parent); } else { noParent.Add(code); } } } } if (noParent.Count > maxErrors || invalid.Count > maxErrors) { break; } Progress.Increment(); } if (invalid.Count > 0 || noParent.Count > 0 || emptyCenter.Count > 0) { string message = ""; if (noParent.Count > 0) { message += "Hay " + noParent.Count + " " + ItemPlural(invalid.Count) + " ítems existentes en el DBF que no se encuentran en el archivo SAV. " + ": " + FirstOrAll(noParent.Count, maxErrors) + ": \n" + string.Join(", ", noParent.Take(maxErrors)) + " (" + codeColumn + ")" + "\nValores de ejemplo esperados: " + GetFirstKeys(items); } if (emptyCenter.Count > 0) { if (message != "") { message += "\n\n"; } message += "Hay " + emptyCenter.Count + " " + ShapeOperations.ItemPlural(emptyCenter.Count) + " con centroides vacíos. " + ShapeOperations.FirstOrAll(emptyCenter.Count, ShapeOperations.maxErrors) + ": \n" + string.Join(", ", emptyCenter.Take(ShapeOperations.maxErrors)) + " (" + codeColumn + ")";; } if (invalid.Count > 0) { if (message != "") { message += "\n\n"; } message += "Hay " + invalid.Count + " " + ItemPlural(invalid.Count) + " con geometrías inválidas. " + FirstOrAll(invalid.Count, maxErrors) + ": \n" + string.Join(", ", invalid.Take(maxErrors)) + " (" + codeColumn + ")"; } throw new MessageException(message); } }