From 492475fbdd4f0b11eebe9f16935d298cc8274523 Mon Sep 17 00:00:00 2001 From: Elena Date: Sun, 6 Feb 2022 17:05:50 +0100 Subject: [PATCH] =?UTF-8?q?Avances=20exportaci=C3=B3n?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Button/ButtonLimp.cs | 20 +- Button/ButtonRec.cs | 18 +- Helper/HelperGdb.cs | 245 ++++++++++++++++-- Model/ComunDef.cs | 1 + Model/OliviaConf.cs | 5 +- Model/OliviaGlob.cs | 4 +- Model/Respuesta.cs | 4 +- Services/EjecServ.cs | 166 +++++++----- View/Configuracion/PaneConfigView.xaml.cs | 10 +- View/Limpieza/PaneLimpiezaSub2.xaml.cs | 11 +- View/Recogida/PaneRecogidaSub1.xaml.cs | 8 +- .../Limpieza/DockpaneLimpiezaViewModel.cs | 1 + .../Limpieza/PaneLimpiezaSub2ViewModel.cs | 3 +- ViewModel/PanelViewModelBase.cs | 2 + 14 files changed, 400 insertions(+), 98 deletions(-) diff --git a/Button/ButtonLimp.cs b/Button/ButtonLimp.cs index 51565d6..c27e700 100644 --- a/Button/ButtonLimp.cs +++ b/Button/ButtonLimp.cs @@ -25,14 +25,26 @@ namespace OliviaAddInPro { protected override void OnClick() { + ///////////////////////////////////////////////////// + OliviaGlob.progrDialog= new ProgressDialog( "Procesando", "Canceled", 100, false); if (OliviaGlob.TipoEjec == TiposEjecucion.Ninguno) { - OliviaGlob.SetFlagTipEjec(TiposEjecucion.Limp); - OliviaGlob.Limp = new Limpieza(); - DockpaneLimpiezaViewModel.Reset(); - DockpaneLimpiezaViewModel.Show(); + ///Comprueba que existe la red navegable configurada + if (HelperGdb.GetGdb(OliviaGlob.Paths.PathGdbNw).Result == null) + { + HelperGlobal.ponMsg("No encuentra Gdb de red navegable, cambie Configuración: " + HelperGdb.OutStr, + System.Windows.MessageBoxImage.Warning); + } + else + { + OliviaGlob.SetFlagTipEjec(TiposEjecucion.Limp); + if(OliviaGlob.Limp==null) + OliviaGlob.Limp = new Limpieza(); + DockpaneLimpiezaViewModel.Reset(); + DockpaneLimpiezaViewModel.Show(); + } } else { diff --git a/Button/ButtonRec.cs b/Button/ButtonRec.cs index 5131d2a..def4442 100644 --- a/Button/ButtonRec.cs +++ b/Button/ButtonRec.cs @@ -29,10 +29,20 @@ namespace OliviaAddInPro "Procesando", "Canceled", 100, false); if (OliviaGlob.TipoEjec==TiposEjecucion.Ninguno) { - OliviaGlob.SetFlagTipEjec(TiposEjecucion.Reco); - OliviaGlob.Reco = new Recogida(); - DockpaneRecogidaViewModel.Reset(); - DockpaneRecogidaViewModel.Show(); + ///Comprueba que existe la red navegable configurada + if (HelperGdb.GetGdb(OliviaGlob.Paths.PathGdbNw).Result == null) + { + HelperGlobal.ponMsg("No encuentra Gdb de red navegable, cambie Configuración: " + HelperGdb.OutStr, + System.Windows.MessageBoxImage.Warning); + } + else + { + OliviaGlob.SetFlagTipEjec(TiposEjecucion.Reco); + if(OliviaGlob.Reco==null) + OliviaGlob.Reco = new Recogida(); + DockpaneRecogidaViewModel.Reset(); + DockpaneRecogidaViewModel.Show(); + } } else { diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 4c5523e..a4c8ef0 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -26,6 +26,7 @@ namespace OliviaAddInPro.Helper { public static class HelperGdb { + private static string ObjectId = "OBJECTID"; private static string out_str = string.Empty; public static string OutStr { get @@ -312,7 +313,7 @@ namespace OliviaAddInPro.Helper } //Crea un filtro espacial a partir de una consulta y en todo caso, una geometría - public static ArcGIS.Core.Data.SpatialQueryFilter CreateFiler(string consulta, ArcGIS.Core.Geometry.Geometry geom, SpatialRelationship rel= SpatialRelationship.Intersects) + public static ArcGIS.Core.Data.SpatialQueryFilter CreateFiler(string consulta, ArcGIS.Core.Geometry.Geometry geom, SpatialRelationship rel= SpatialRelationship.Contains) { ArcGIS.Core.Data.SpatialQueryFilter filt =null; if (geom != null) @@ -555,7 +556,8 @@ namespace OliviaAddInPro.Helper return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { geomIni = GetGeomUnique(fclss, filter, cps); - if (geomIni != null) + return geomIni; + /*if (geomIni != null) { ArcGIS.Core.Geometry.Geometry geomSal = null; try @@ -569,7 +571,7 @@ namespace OliviaAddInPro.Helper } } else - return null; + return null;*/ })); } @@ -795,13 +797,109 @@ namespace OliviaAddInPro.Helper return res; } - public static bool ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, CancelableProgressorSource cps, out string msgOut, ProgressorSource progrDialog = null) + public static bool ExportShp2(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, CancelableProgressorSource cps) + { + if (!System.IO.Directory.Exists(outpath)) + System.IO.Directory.CreateDirectory(outpath); + FeatureClass fc = null; + ///////////////////////////////////////////////////////// + //Prepara una where_clause con las entidades que cumplen el filtro + //Abre la featureclass + try + { + fc = GetFtClass(pathLayerIn); + if (fc == null) + { + OutStr = "Error al abrir Feature Class en exportación"; + return false; + } + List ids = new List(); + cps.Status = "Aplicando filtro espacial a exportación"; + //Añade a la lista los ids que cumplen el filtro espacial + using (RowCursor cursor = fc.Search(filter)) + { + while (cursor.MoveNext()) + { + using (Feature feature = (Feature)cursor.Current) + { + ids.Add(feature.GetObjectID()); + } + } + } + if (ids.Count <= 0) + { + OutStr = "Error al aplicar filtro espacial en exportación"; + return false; + } + //convierte la lista de ids a string para la clause de la forma + //(id1, id2, id3..) + string whereClause = GetWhereClauseFromIds(ids); + + /////////////////////////////////////////////////////////// + ///Exporta + cps.Status = "Exportando datos"; + string[] args = { pathLayerIn, outpath, nameShp, whereClause }; + // execute the tool + IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, + null, cps.CancellationTokenSource.Token, + + (event_name, o) => // implement delegate and handle events + { + switch (event_name) + { + case "OnValidate": // stop execute if any warnings + //if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning)) + //_cts.Cancel(); + break; + + case "OnProgressMessage": + { + string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o }); + Debug.WriteLine(msg); + ; + //System.Windows.MessageBox.Show(msg); + //_cts.Cancel(); + } + break; + + case "OnProgressPos": + { + string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o }); + Debug.WriteLine(msg2); + var av = (int)0; + if (av > 0) + { + cps.Value = (uint)(80 * av * 0.2); + } + // if ((int)o < 0) + //System.Windows.MessageBox.Show(msg2); + //_cts.Cancel(); + break; + } + } + }).Result; + cps.Status = "Finalizando exportacion"; + + return true; + } + catch (Exception ex) + { + OutStr = "Error: " + ex.Message; + return false; + } + finally + { + Free(fc); + } + + } + + public static bool ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, CancelableProgressorSource cps, out string msgOut, ProgressorSource progrDialog = null) { msgOut = ""; if (!System.IO.Directory.Exists(outpath)) System.IO.Directory.CreateDirectory(outpath); - //FeatureClass fc = HelperGdb.GetFtClass(pathLayerIn); //fc. /* @@ -950,9 +1048,27 @@ namespace OliviaAddInPro.Helper return resp; } } + /** + * Amplía la geometría para añadirele buffer + */ + public static Respuesta BufferGeom(ArcGIS.Core.Geometry.Geometry geom, double buffer) + { + Respuesta resp = new Respuesta(); + ArcGIS.Core.Geometry.Geometry geomBuff = null; + try + { + geomBuff = GeometryEngine.Instance.Buffer(geom, buffer); + } + catch + { + + } + resp.Value = geomBuff; + return resp; + } /**Amplía la geometría para que incluya el punto - */ + */ public static Respuesta AddPtoInGeom(Coordinate2D pto, ArcGIS.Core.Geometry.Geometry geom) { Respuesta resp = new Respuesta(); @@ -973,6 +1089,22 @@ namespace OliviaAddInPro.Helper resp.Error.Add("Error al unir punto a polígono"); return resp; } + //hace la convez hull, por si no fueran conexas las zonas + ArcGIS.Core.Geometry.Geometry geom_aux= GeometryEngine.Instance.Intersection(geom_pto, geom); + if (geom_aux == null || geom_aux.IsEmpty) + { + ArcGIS.Core.Geometry.Envelope env1 = geom_sal.Extent; + ArcGIS.Core.Geometry.Envelope env2 = geom_pto.Extent; + ArcGIS.Core.Geometry.Envelope env3 = env1.Union(env2); + geom_sal = (ArcGIS.Core.Geometry.Geometry) env3; + //geom_sal = GeometryEngine.Instance.Envelope(geom_sal); + if (geom_sal == null || geom_sal.IsEmpty) + { + resp.Value = null; + resp.Error.Add("Error al hacer envolvente en unir punto al polígono"); + return resp; + } + } resp.Value = geom_sal; return resp; } @@ -985,10 +1117,30 @@ namespace OliviaAddInPro.Helper } /* * Dada una lista de ids de elemento, crea una consulta en la que se llama a todos esos elementos + * campo IN (id1, id2, id3..) */ public static string GetWhereClauseFromIds(List ids) { - string consulta, orstr; + if (ids.Count <= 0) + return string.Empty; + + string ids_str = "("; + bool first = true; + foreach (long i in ids) + { + if (first) + { + ids_str += i.ToString(); + first = false; + } + else + ids_str += "," + i.ToString(); + } + //el último + ids_str += ")"; + string whereClause = ObjectId + " IN " + ids_str; //Cambiar id a otro sitio + return whereClause; + /*string consulta, orstr; consulta = string.Empty; orstr = string.Empty; @@ -1003,15 +1155,68 @@ namespace OliviaAddInPro.Helper if (consulta == "()") consulta = string.Empty; - return consulta; + return consulta;*/ } /** * Elimina las filas indicadas del shp **/ - public static bool RemoveRowsFromShp(string shp_path, List quita) + public static bool RemoveRowsFromShp(FeatureClass fc, List quita) { - FeatureClass fc = HelperGdb.GetFtClassFromShp(shp_path).Result; + //Crea la consulta + var consulta = GetWhereClauseFromIds(quita); + + if (String.IsNullOrEmpty(consulta)) + return false; + + string message = String.Empty; + bool deletionResult = false; + + ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { + + EditOperation editOperation = new EditOperation(); + editOperation.Callback(context => + { + ArcGIS.Core.Data.QueryFilter openCutFilter = new ArcGIS.Core.Data.QueryFilter { WhereClause = consulta }; + + using (RowCursor rowCursor = fc.Search(openCutFilter, false)) + { + while (rowCursor.MoveNext()) + { + using (Row row = rowCursor.Current) + { + // In order to update the Map and/or the attribute table. Has to be called before the delete. + context.Invalidate(row); + + row.Delete(); + } + } + } + }, fc); + + try + { + deletionResult = editOperation.Execute(); + if (!deletionResult) + { + message = editOperation.ErrorMessage; + } + } + catch (GeodatabaseException exObj) + { + message = exObj.Message; + } + + }); + + if (!string.IsNullOrEmpty(message)) + { + OutStr = message; + return false; + } + else + return true; + /*FeatureClass fc = HelperGdb.GetFtClassFromShp(shp_path).Result; if (fc == null) return false; @@ -1025,7 +1230,8 @@ namespace OliviaAddInPro.Helper ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() => { string shpname = System.IO.Path.GetFileNameWithoutExtension(shp_path); - var shapeFileConnPath = new FileSystemConnectionPath(new Uri(shp_path), FileSystemDatastoreType.Shapefile); + var shapeFileConnPath = new FileSystemConnectionPath(new Uri(System.IO.Path.GetDirectoryName(shp_path)), + FileSystemDatastoreType.Shapefile); var shapefile = new FileSystemDatastore(shapeFileConnPath); using (Table table = shapefile.OpenDataset(shp_path)) { @@ -1071,6 +1277,7 @@ namespace OliviaAddInPro.Helper } else return true; + */ } /** @@ -1114,16 +1321,22 @@ namespace OliviaAddInPro.Helper Free(f); } Free(f); - Free(fc); - Free(cursor); - + Free(cursor); + + //comprueba que no se haya quedado sin ámbitos + if (quita.Count>=fc.GetCount()) + { + OutStr = "No quedan ámbitos que cumplan la geometría seleccionada."; + return false; + } + //Quita los ámbitos del shp if (quita.Count > 0) { //borra las líneas que se han indicado - if (!RemoveRowsFromShp(shp_path, quita)) + if (!RemoveRowsFromShp(fc, quita)) return false; } - + Free(fc); return true; } diff --git a/Model/ComunDef.cs b/Model/ComunDef.cs index e4d7475..8106d64 100644 --- a/Model/ComunDef.cs +++ b/Model/ComunDef.cs @@ -9,6 +9,7 @@ namespace OliviaAddInPro.Model { //************************************************************************************* //Enums y structs generales + public static int BuffExport = 1000; /** * Nombre de los campos de la cartografía de la red navegable que se consultan para la exportación */ diff --git a/Model/OliviaConf.cs b/Model/OliviaConf.cs index a66008a..d979592 100644 --- a/Model/OliviaConf.cs +++ b/Model/OliviaConf.cs @@ -6,6 +6,8 @@ using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; +using Xceed.Wpf.Toolkit.PropertyGrid; +using Xceed.Wpf.Toolkit.PropertyGrid.Editors; namespace OliviaAddInPro.Model { @@ -190,6 +192,7 @@ namespace OliviaAddInPro.Model [Category("General")] [DisplayName("Red de carreteras")] [Description("Red de carreteras que se usara para la navegación")] + //[Editor(typeof(EditorFilePickerDefinition), typeof(EditorFilePickerDefinition))] public string red_carreteras { get; set; } [Category("General")] @@ -1301,5 +1304,5 @@ namespace OliviaAddInPro.Model #endregion - } + } } diff --git a/Model/OliviaGlob.cs b/Model/OliviaGlob.cs index f7a0f74..09c629e 100644 --- a/Model/OliviaGlob.cs +++ b/Model/OliviaGlob.cs @@ -209,8 +209,6 @@ namespace OliviaAddInPro.Model Conexion.Ip = c.Ip; Conexion.TiempoOutSocket = c.TiempoOutSocket; - //buff_export = c.buffer_export; - /////////////////////////////////////// //Capas, consultas y filtros GENERALES Capas.ftclass_ejes = c.eje_via; @@ -398,7 +396,7 @@ namespace OliviaAddInPro.Model RecogidaDef.tipos_lateralidad[(int)RecogidaDef.Lateralidad.Dcha] = c.derecha; RecogidaDef.tipos_lateralidad[(int)RecogidaDef.Lateralidad.Izqda] = c.izquierda; - + ComunDef.BuffExport = c.buffer_export; //Campos de la red navegable que se leen ComunDef.CamposNW.cons_onew = c.cons_onew; ComunDef.CamposNW.cons_kph = c.cons_kph; diff --git a/Model/Respuesta.cs b/Model/Respuesta.cs index dea26fa..e8faf24 100644 --- a/Model/Respuesta.cs +++ b/Model/Respuesta.cs @@ -10,13 +10,13 @@ namespace OliviaAddInPro.Model { public T Value { get; set; } - public List Error { get; set; } + public List Error { get; set; } = new List(); public bool HasError { get { - return Error.Any(); + return Error.Any(); } } } diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index 4e5bb59..e6809fa 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -38,9 +38,8 @@ namespace OliviaAddInPro.Services public bool LanzaEjec(ModosEjec modo, CancelableProgressorSource cps, out string ErrStr) { ErrStr = string.Empty; - FeatureClass fc = null; try - { + { //Cuenta las filas que cumplen la consulta int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs); if (nelems <= 0) @@ -67,7 +66,6 @@ namespace OliviaAddInPro.Services { ErrStr = "Error al crear el filtro de exportacion de los ámbitos"; return false; - } //Termina de preparar nombre //Prepara nombre @@ -78,9 +76,10 @@ namespace OliviaAddInPro.Services com.NombreShpExport = prefNameExport + com.NombreShpExp_PrefTto +"_" + fechaHora + extShp; //exporta los datos de entrada - if (!HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, cps, out ErrStr)) + if (!HelperGdb.ExportShp2(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, cps)) + //if (!HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, cps, out ErrStr)) { - ErrStr = ErrStr+"Error al exportar los ámbitos"; + ErrStr = "Error al exportar los ámbitos: "+ HelperGdb.OutStr; return false; } //Guarda el nombre @@ -92,7 +91,8 @@ namespace OliviaAddInPro.Services } cps.Value = 80; //hace intersecciones espaciales en caso de ámbitos lineales para quitar los que tienen más parte fuera de la zona que dentro - if (((com.GeomNiv != null) || (com.GeomZon!=null)) && + //REVISAR + /*if (((com.GeomNiv != null) || (com.GeomZon != null)) && (OliviaGlob.IsReco() || (OliviaGlob.IsLimp() && (com.TipoTto < (int)LimpiezaDef.TiposTto.TtoPapeVaci)))) { if (!HelperGdb.RemoveRowsGeom(OliviaGlob.Paths.PathData, geom_export, 0.4)) @@ -100,44 +100,55 @@ namespace OliviaAddInPro.Services ErrStr = "Error al quitar los ámbitos que sobresalen: " + HelperGdb.OutStr; return false; } - } - //comprueba que no se haya quedado sin ámbitos - fc = HelperGdb.GetFtClassFromShp(OliviaGlob.Paths.PathData).Result; - if (fc==null) - { - ErrStr = HelperGdb.OutStr; - return false; - } - if(fc.GetCount() <= 0) - { - ErrStr = "No quedan ámbitos que cumplan la geometría seleccionada."; - return false; - } + }*/ /////////////////////////////////////////////////////////////////////////// - //amplia la geom para englobar las instalaciones - geom_export = HelperGdb.GetGeomConvexHull(fc, null, cps).Result; - if (!com.CoordsInstal.IsEmpty && (com.CoordsInstal.X!=0)) - { - //hay instalación - Respuesta resp; - //comprueba, si hay restricciones de circulación, que la instalación no está en ellas - if (com.GeomRestr != null) + //comprueba, si hay restricciones de circulación y hay instalación, que la instalación no está en ellas + if (!com.CoordsInstal.IsEmpty && (com.CoordsInstal.X!=0) && (com.GeomRestr != null)) + { + Respuesta resp = HelperGdb.IsPtoInGeom(com.CoordsInstal, com.GeomRestr); + if (!resp.Value && resp.HasError) { - resp = HelperGdb.IsPtoInGeom(com.CoordsInstal, com.GeomRestr); - if (!resp.Value) - { - if (resp.HasError) - ErrStr = "Error al comprobar si la instalación está contenida en el polígono de restricciones: " + resp.Error.ElementAt(0); - else - ErrStr = "Error, la instalación está en la zona restringida a la circulación "; - return false; - } + ErrStr = "Error al comprobar si la instalación está contenida en el polígono de restricciones: " + resp.Error.ElementAt(0); + return false; } - - //comprueba si la geometría de exportación contiene a la instalación - resp = HelperGdb.IsPtoInGeom(com.CoordsInstal, geom_export); - if (!resp.Value) + else if(resp.Value) //sí está contenido en las restricciones + { + ErrStr = "Error, la instalación está en la zona restringida a la circulación "; + return false; + } + + } + if (cps.CancellationTokenSource.IsCancellationRequested) + { + ErrStr = "Se ha cancelado la operación"; + return false; + } + /////////////////////////////////////////////////////////////////////////// + //exporta la red navegable (buffer, le quita las restr...) + //se obtiene la geometría a intersecar con la red, que será la que contiene + //a todos los ámbitos y la instalación, ampliada un buffer, mayor si hay + //restricciones de circulación + Geometry geom_aux = HelperGdb.BufferGeom(geom_export, com.BuffExport).Value; + if(geom_aux==null) + { + ErrStr = "Error al añadir buffer a la geometría"; + return false; + } + //quita las restricciones + geom_aux = HelperGdb.QuitaGeom(geom_aux, com.GeomRestr); + if (geom_aux == null) + { + ErrStr = "Error al intersecar con las restricciones."; + return false; + } + geom_export = geom_aux; + ////////////////////////////////////////////////////////////// + //comprueba si la geometría de exportación contiene a la instalación + if (!com.CoordsInstal.IsEmpty && (com.CoordsInstal.X != 0)) + { + Respuesta resp = HelperGdb.IsPtoInGeom(com.CoordsInstal, geom_export); + if (!resp.Value) //si no lo contiene { //ha ido mal if (resp.HasError) @@ -163,13 +174,7 @@ namespace OliviaAddInPro.Services } } } - if (cps.CancellationTokenSource.IsCancellationRequested) - { - ErrStr = "Se ha cancelado la operación"; - return false; - } - /////////////////////////////////////////////////////////////////////////// - //exporta la red navegable (buffer, le quita las restr...) + //Hace el filtro con la geometría final filtroEspacial = HelperGdb.CreateFiler(String.Empty, geom_export); if (filtroEspacial == null) { @@ -181,9 +186,10 @@ namespace OliviaAddInPro.Services com.NombreShpExportNw = prefNameExportNw + fechaHora + extShp; //exporta los datos de entrada string capaNw =System.IO.Path.Combine(OliviaGlob.Paths.PathGdbNw, OliviaGlob.Capas.ftclass_ejes); - if (!HelperGdb.ExportShp(capaNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, cps, out ErrStr)) + //if (!HelperGdb.ExportShp(capaNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, cps, out ErrStr)) + if (!HelperGdb.ExportShp2(capaNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, cps)) { - ErrStr = ErrStr + "Error al exportar la red navegable"; + ErrStr = "Error al exportar la red navegable: " + HelperGdb.OutStr; return false; } //guarda los nombres del shape @@ -200,10 +206,6 @@ namespace OliviaAddInPro.Services ErrStr = "Errores al comenzar la ejecución: " + ex.Message; return false; } - finally - { - HelperGdb.Free(fc); - } return true; } @@ -248,16 +250,18 @@ namespace OliviaAddInPro.Services cps.Value = 30; //prepara el filtro con consulta y espacial - SpatialQueryFilter filtro = HelperGdb.CreateFiler(com.ConsultaAmbs, geomAux); - - //Ahora hace la geometría de los ámbitos que cumplen la consulta - geomAmbits = HelperGdb.GetGeomConvexHull(fc, filtro, cps).Result; - if (geomAmbits == null || geomAmbits.IsEmpty) + SpatialQueryFilter filtro = HelperGdb.CreateFiler(com.ConsultaAmbs, geomAux); + if (geomAux == null) { - ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + HelperGdb.OutStr; - return null; + //Ahora hace la geometría de los ámbitos que cumplen la consulta, si no hay ya geometría + geomAmbits = HelperGdb.GetGeomConvexHull(fc, filtro, cps).Result; + if (geomAmbits == null || geomAmbits.IsEmpty) + { + ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + HelperGdb.OutStr; + return null; + } + geomAux = geomAmbits; } - geomAux = geomAmbits; cps.Value = 60; //le quita las restricciones if (com.GeomRestr != null) @@ -328,5 +332,45 @@ namespace OliviaAddInPro.Services camps[1] = LimpiezaDef.Campos.consulta_secuen; return CompruebaCampos(pathCapa, camps) == 0; } + + /** + * Borra los archivos exportados para el proceso + */ + public static void BorraFiles() + { + string[] list = null; + string capa_principal = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData); + string capa_principal_nw = System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathNW); + + try + { + if (capa_principal == null) + return; + list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal + "*"); + if (list.Length > 0) + { + foreach (string f in list) + { + if (System.IO.Path.GetExtension(f) == ".lock") + continue; + System.IO.File.Delete(f); + } + } + if (capa_principal_nw == null) + return; + list = System.IO.Directory.GetFiles(OliviaGlob.Paths.DirData, capa_principal_nw + "*"); + if (list.Length > 0) + { + foreach (string f in list) + { + System.IO.File.Delete(f); + } + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message); + } + } } } diff --git a/View/Configuracion/PaneConfigView.xaml.cs b/View/Configuracion/PaneConfigView.xaml.cs index e391b6d..d4eaa88 100644 --- a/View/Configuracion/PaneConfigView.xaml.cs +++ b/View/Configuracion/PaneConfigView.xaml.cs @@ -13,6 +13,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using OliviaAddInPro.Model; namespace OliviaAddInPro { @@ -28,9 +29,12 @@ namespace OliviaAddInPro } private void OnGuardar(object sender, RoutedEventArgs e) { - - if (DataContext is PaneConfigViewModel mod) - mod.OnGuardar(); + + if (DataContext is PaneConfigViewModel mod) + { + mod.OnGuardar(); + OliviaGlob.IniDefault(); + } } private void OnRefres(object sender, RoutedEventArgs e) diff --git a/View/Limpieza/PaneLimpiezaSub2.xaml.cs b/View/Limpieza/PaneLimpiezaSub2.xaml.cs index 6021064..904929f 100644 --- a/View/Limpieza/PaneLimpiezaSub2.xaml.cs +++ b/View/Limpieza/PaneLimpiezaSub2.xaml.cs @@ -87,9 +87,16 @@ namespace OliviaAddInPro ArcGIS.Core.Geometry.Geometry geomsal = HelperGdb.OpenGeom(HelperGdb.TiposOpenFileDlg.OpenFtrClassPoint, out texto); - if ((DataContext is PaneLimpiezaSub2ViewModel mod) && geomsal != null && geomsal is MapPoint mp) + if ((DataContext is PaneLimpiezaSub2ViewModel mod) && (geomsal != null)) { - mod.CoordsInstal = mp.Coordinate2D; + if (geomsal is MapPoint map) + mod.CoordsInstal = map.Coordinate2D; + else if (geomsal is Multipoint multip) + { + if(multip.Copy2DCoordinatesToList().Count>0) + mod.CoordsInstal = multip.Copy2DCoordinatesToList().First(); + } + } if (geomsal != null) label_capainst.Content = texto; diff --git a/View/Recogida/PaneRecogidaSub1.xaml.cs b/View/Recogida/PaneRecogidaSub1.xaml.cs index 6a5c216..dd22206 100644 --- a/View/Recogida/PaneRecogidaSub1.xaml.cs +++ b/View/Recogida/PaneRecogidaSub1.xaml.cs @@ -157,7 +157,13 @@ namespace OliviaAddInPro if ((DataContext is PaneRecogidaSub1ViewModel mod) && geomsal != null && geomsal is MapPoint mp) { - mod.CoordsPlanta = mp.Coordinate2D; + if (geomsal is MapPoint map) + mod.CoordsPlanta = map.Coordinate2D; + else if (geomsal is Multipoint multip) + { + if (multip.Copy2DCoordinatesToList().Count > 0) + mod.CoordsPlanta = multip.Copy2DCoordinatesToList().First(); + } } if (geomsal != null) label_capaplant.Content = texto; diff --git a/ViewModel/Limpieza/DockpaneLimpiezaViewModel.cs b/ViewModel/Limpieza/DockpaneLimpiezaViewModel.cs index a95768a..9ddcd53 100644 --- a/ViewModel/Limpieza/DockpaneLimpiezaViewModel.cs +++ b/ViewModel/Limpieza/DockpaneLimpiezaViewModel.cs @@ -57,6 +57,7 @@ namespace OliviaAddInPro internal static void Reset() { //HAY QUE HACER QUE SE LIMPIE TODO + } //The parameter passed to this method will be true if the Dockpane is being opened and it is false when you close the dockpane diff --git a/ViewModel/Limpieza/PaneLimpiezaSub2ViewModel.cs b/ViewModel/Limpieza/PaneLimpiezaSub2ViewModel.cs index c965537..a36335b 100644 --- a/ViewModel/Limpieza/PaneLimpiezaSub2ViewModel.cs +++ b/ViewModel/Limpieza/PaneLimpiezaSub2ViewModel.cs @@ -14,6 +14,7 @@ using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Dialogs; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Mapping; +using OliviaAddInPro.Model; namespace OliviaAddInPro { @@ -22,7 +23,7 @@ namespace OliviaAddInPro public PaneLimpiezaSub2ViewModel() { lblCapaRestr= lblCapaNiv= lblCapaZon= lblCapaInst = Resource1.String_selec_capa; - txtBuffExport = 1000; + txtBuffExport = ComunDef.BuffExport; } diff --git a/ViewModel/PanelViewModelBase.cs b/ViewModel/PanelViewModelBase.cs index 5588ef9..7f3d1e0 100644 --- a/ViewModel/PanelViewModelBase.cs +++ b/ViewModel/PanelViewModelBase.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using System.Text.RegularExpressions; using System.Runtime.InteropServices.WindowsRuntime; using OliviaAddInPro.Model; +using OliviaAddInPro.Helper; namespace OliviaAddInPro { @@ -122,6 +123,7 @@ namespace OliviaAddInPro return false; } return true; + } }