From 407d06bf0012141b0426473b23cd38ef2645f7c6 Mon Sep 17 00:00:00 2001 From: Elena Date: Fri, 13 Jan 2023 13:24:23 +0100 Subject: [PATCH] Modificaciones para exportar OID y otras de nombres de campos --- Model/OliviaConf.cs | 11 ++-- Model/Recogida.cs | 2 +- Model/TratamientoComun.cs | 57 ++++++++++++++++++-- Services/EjecServ.cs | 110 +++++++++++++++++++++----------------- Services/RecogidaServ.cs | 15 +++--- 5 files changed, 129 insertions(+), 66 deletions(-) diff --git a/Model/OliviaConf.cs b/Model/OliviaConf.cs index b1def84..e28b30f 100644 --- a/Model/OliviaConf.cs +++ b/Model/OliviaConf.cs @@ -263,6 +263,12 @@ namespace OliviaAddInPro.Model [DisplayName("Ignorar aislados")] [Description("Indica si por defecto se van a ignorar elementos aislados")] public bool Igno_ais { get; set; } + + [Category("General")] + [PropertyOrder(9)] + [DisplayName("Campo para exportar ID")] + [Description("Nombre del campo que indica el ID del ámbito")] + public string id { get; set; } #endregion #region 02CamposLimp @@ -378,11 +384,6 @@ namespace OliviaAddInPro.Model #endregion #region 04CamposRecogida - [Category("Campos Recogida")] - [DisplayName("ID")] - [Description("Nombre del campo que indica el ID del contenedor")] - public string id { get; set; } - [Category("Campos Recogida")] [DisplayName("Tipo de carga")] [Description("Nombre del campo que indica el tipo de carga")] diff --git a/Model/Recogida.cs b/Model/Recogida.cs index 20d2e74..8dd0b52 100644 --- a/Model/Recogida.cs +++ b/Model/Recogida.cs @@ -164,7 +164,7 @@ namespace OliviaAddInPro.Model public override string[] GetCampos(string capa=null) { string[] camps = { - RecogidaDef.campos_def.cons_id, + //RecogidaDef.campos_def.cons_id, RecogidaDef.campos_def.cons_nomrec, RecogidaDef.campos_def.cons_lateral , RecogidaDef.campos_def.cons_fracc, diff --git a/Model/TratamientoComun.cs b/Model/TratamientoComun.cs index 4c3b784..c59a7ab 100644 --- a/Model/TratamientoComun.cs +++ b/Model/TratamientoComun.cs @@ -137,6 +137,8 @@ namespace OliviaAddInPro.Model set { err_str = value; } } + private ObservableCollection nombCamposOrig = new ObservableCollection(); + /** * Para la ventana de progreso */ @@ -202,10 +204,30 @@ namespace OliviaAddInPro.Model return null; } + /** * Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp */ - public Respuesta RestauraNomCampos(string nombFtClass) + public virtual string[] GetCamposOrig() + { + string[] camps = null; + + if (nombCamposOrig.Count > 0) + { + camps = new string[nombCamposOrig.Count]; + for (int i=0;i RestauraNomCampos(string nombFtClass) { int LENGTHCAMPSHP = 10; Respuesta resp = new Respuesta { Value = false }; @@ -213,7 +235,9 @@ namespace OliviaAddInPro.Model if (fc == null) return resp; //////////////////////////////////////////////////////// - string[] camps = GetCampos(); + string[] camps = GetCamposOrig(); + if (camps == null) + return resp; ObservableCollection fields = HelperGdb.GetFieldsSync(fc); HelperGdb.Free(fc); @@ -228,7 +252,9 @@ namespace OliviaAddInPro.Model { if (camps[i].Length <= LENGTHCAMPSHP) continue; - campTrunc = camps[i].Substring(0, LENGTHCAMPSHP); + if (EstaRepeNomb(fields, camps[i])) + continue; + campTrunc = camps[i].Substring(0, LENGTHCAMPSHP); //si tiene más de 10 caracteres, lo ha truncado al exportar //busca el nombre actual del campo en la fc indx = fields.IndexOf(campTrunc); @@ -251,5 +277,30 @@ namespace OliviaAddInPro.Model return resp; } + + private bool EstaRepeNomb(ObservableCollection fields, string nomb) + { + foreach( string fnomb in fields) + { + if (string.Compare(fnomb, nomb, true)==0) + return true; + } + return false; + } + + /** + * Guarda el nombre de los campos originales para luego restaurarlos + */ + public void GuardaNombCamposOrig(string pathFtClass) + { + FeatureClass fc = HelperGdb.GetFtClassSync(pathFtClass); + if (fc != null) + { + nombCamposOrig = HelperGdb.GetFieldsSync(fc); + } + else + nombCamposOrig = new ObservableCollection(); + HelperGdb.Free(fc); + } } } diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index f4e014c..ea1ba57 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -78,6 +78,12 @@ namespace OliviaAddInPro.Services ErrStr = Resource1.String_cancel_progreso; return false; } + + ////////////////////////////////////////////// + ///Se guarda el nombre de los campos originales + /// + com.GuardaNombCamposOrig(com.CapaElems); + //Cuenta las filas que cumplen la consulta int nelems = HelperGdb.GetNumElemsSync(com.CapaElems, com.ConsultaAmbs); if (nelems <= 0) @@ -535,67 +541,71 @@ namespace OliviaAddInPro.Services ///////////////////////////////////////////////////// //Coge los ids de la capa de la que ha exportado - FeatureClass fc_orig = HelperGdb.GetFtClassSync(pathCapaOrig); - if (fc_orig == null) - return false; - List ids = new List(); - //Añade a la lista los ids que cumplen el filtro espacial - try + using (FeatureClass fc_orig = HelperGdb.GetFtClassSync(pathCapaOrig)) { - ids = fc_orig.Select(filter, SelectionType.ObjectID, SelectionOption.Normal).GetObjectIDs().ToList(); - } - catch - { - ids = new List(); - } - //Comprueba que hay tantos ids como elementos en el shp - FeatureClass fc_shp = HelperGdb.GetFtClassSync(pathCapa); - if (fc_shp == null) - return false; - int nelem_shp = HelperGdb.GetNumElemsSync(fc_shp); - if (nelem_shp != ids.Count) - return false; - - ///////////////////////////////////////////////////// - //ahora rellena las columnas - try - { - using (RowCursor rc_shp = fc_shp.Search()) + if (fc_orig == null) + return false; + List ids = new List(); + //Añade a la lista los ids que cumplen el filtro espacial + try { - if (rc_shp == null) + ids = fc_orig.Select(filter, SelectionType.ObjectID, SelectionOption.Normal).GetObjectIDs().ToList(); + } + catch + { + ids = new List(); + } + //Comprueba que hay tantos ids como elementos en el shp + using (FeatureClass fc_shp = HelperGdb.GetFtClassSync(pathCapa)) + { + if (fc_shp == null) + return false; + int nelem_shp = HelperGdb.GetNumElemsSync(fc_shp); + if (nelem_shp != ids.Count) return false; - var modifyOp = new ArcGIS.Desktop.Editing.EditOperation(); - modifyOp.Name = "Actualiza OID"; - bool ex = false; - //modifyOp.Callback((context) => - //{ - int i = 0; - while (rc_shp.MoveNext() && i < ids.Count) + ///////////////////////////////////////////////////// + //ahora rellena las columnas + try { - using (Row rowshp = rc_shp.Current) + using (RowCursor rc_shp = fc_shp.Search()) { - //context.Invalidate(rowshp); - // modify and execute - modifyOp.Modify(rowshp, ComunDef.CamposCom.camp_oid, ids[i++]); - rowshp.Store(); - //context.Invalidate(rowshp); + if (rc_shp == null) + return false; + + var modifyOp = new ArcGIS.Desktop.Editing.EditOperation(); + modifyOp.Name = "Actualiza OID"; + bool ex = false; + //modifyOp.Callback((context) => + //{ + int i = 0; + while (rc_shp.MoveNext() && i < ids.Count) + { + using (Row rowshp = rc_shp.Current) + { + //context.Invalidate(rowshp); + // modify and execute + modifyOp.Modify(rowshp, ComunDef.CamposCom.camp_oid, ids[i++]); + rowshp.Store(); + //context.Invalidate(rowshp); + } + } + //}, fc_shp); + ex = modifyOp.Execute(); + ArcGIS.Desktop.Core.Project.Current.SaveEditsAsync(); + if (ex && modifyOp.IsDone) + return true; + else + return false; } } - //}, fc_shp); - ex = modifyOp.Execute(); - ArcGIS.Desktop.Core.Project.Current.SaveEditsAsync(); - if (ex && modifyOp.IsDone) - return true; - else + catch + { return false; + } + return true; } } - catch - { - return false; - } - return true; } /** diff --git a/Services/RecogidaServ.cs b/Services/RecogidaServ.cs index d8f0301..df8df10 100644 --- a/Services/RecogidaServ.cs +++ b/Services/RecogidaServ.cs @@ -28,15 +28,16 @@ namespace OliviaAddInPro.Services */ public int CompruebaCamposReco(string pathCapa) { - int NCAMPS = 6; + int NCAMPS = 5; string[] camps; camps = new string[NCAMPS]; - camps[0] = RecogidaDef.campos_def.cons_id; - camps[1] = RecogidaDef.campos_def.cons_fracc; - camps[2] = RecogidaDef.campos_def.cons_nomrec; - camps[3] = RecogidaDef.campos_def.cons_lateral; - camps[4] = RecogidaDef.campos_def.cons_uds; - camps[5] = RecogidaDef.campos_def.cons_kgrec; + + camps[0] = RecogidaDef.campos_def.cons_fracc; + camps[1] = RecogidaDef.campos_def.cons_nomrec; + camps[2] = RecogidaDef.campos_def.cons_lateral; + camps[3] = RecogidaDef.campos_def.cons_uds; + camps[4] = RecogidaDef.campos_def.cons_kgrec; + //camps[5] = RecogidaDef.campos_def.cons_id; int compCamp = HelperGdb.CheckFileds(pathCapa, camps); ErrStr = HelperGdb.OutStr; if (compCamp == 0)