From 2c58d7e8891e0d65f782aa49e5d24b371502ec41 Mon Sep 17 00:00:00 2001 From: Gerardo Date: Sun, 14 Nov 2021 01:39:56 +0100 Subject: [PATCH] Configuraciones y pruebas --- Button/ButtonLimp.cs | 1 + Helper/HelperGdb.cs | 130 +++++++++++++++--- Model/OliviaGlob.cs | 3 +- Model/TratamientoComun.cs | 8 ++ OliviaAddInPro.csproj | 2 +- Services/EjecServ.cs | 65 ++++----- Services/LimpiezaServ.cs | 15 +- View/Limpieza/PaneLimpiezaSub2.xaml.cs | 21 ++- View/Limpieza/PaneLimpiezaSub3.xaml | 2 +- {Images => View/Limpieza}/openfolder.png | Bin View/openfolder.png | Bin 611 -> 0 bytes ViewModel/DockpaneRecogidaViewModel.cs | 7 +- .../Limpieza/DockpaneLimpiezaViewModel.cs | 16 ++- .../Limpieza/PaneLimpiezaSub3ViewModel.cs | 6 +- 14 files changed, 203 insertions(+), 73 deletions(-) rename {Images => View/Limpieza}/openfolder.png (100%) delete mode 100644 View/openfolder.png diff --git a/Button/ButtonLimp.cs b/Button/ButtonLimp.cs index 9e64e53..ff71c56 100644 --- a/Button/ButtonLimp.cs +++ b/Button/ButtonLimp.cs @@ -29,6 +29,7 @@ namespace OliviaAddInPro { OliviaGlob.TipoEjec = TiposEjecucion.Limp; OliviaGlob.Limp = new Limpieza(); + DockpaneLimpiezaViewModel.Reset(); DockpaneLimpiezaViewModel.Show(); } else diff --git a/Helper/HelperGdb.cs b/Helper/HelperGdb.cs index 0e0a086..837b200 100644 --- a/Helper/HelperGdb.cs +++ b/Helper/HelperGdb.cs @@ -14,6 +14,11 @@ using ArcGIS.Desktop.Mapping; using ArcGIS.Core.Internal.CIM; using ArcGIS.Desktop.Internal.Layouts.Utilities; +using ArcGIS.Desktop.Core.Geoprocessing; +using ArcGIS.Desktop.Framework.Threading.Tasks; +using ArcGIS.Desktop.Editing; +using OliviaAddInPro.Model; + namespace OliviaAddInPro.Helper { public static class HelperGdb @@ -42,6 +47,8 @@ namespace OliviaAddInPro.Helper } set { texto_sal = value; } } + public static string SHP_EXT = ".shp"; + public static string GDB_EXT = ".gdb"; [Flags] public enum TiposOpenFileDlg @@ -136,11 +143,10 @@ namespace OliviaAddInPro.Helper { string pathGdb = string.Empty; int i = 0; - string gdbext = ".gdb"; - if(path.Contains(gdbext)) + if(path.Contains(GDB_EXT)) { - i = path.IndexOf(gdbext, 0, path.Length); - pathGdb = path.Substring(0, i + 4); + i = path.IndexOf(GDB_EXT, 0, path.Length); + pathGdb = path.Substring(0,i + 4); } return pathGdb; @@ -187,7 +193,7 @@ namespace OliviaAddInPro.Helper { ftclss = GetFtClassFromShp(pathFtClss).Result; } - + Free(gdb); return ftclss; } @@ -219,7 +225,7 @@ namespace OliviaAddInPro.Helper ReiniciaOutStr(); return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { - if (pathShp.Contains(".shp")) + if (pathShp.Contains(SHP_EXT)) { try { @@ -425,25 +431,29 @@ namespace OliviaAddInPro.Helper * Forma la envolvente convexa, el mínimo polígono, * que contiene los ámbitos para exportar, a partir de ahí la red navegable ampliando a un buffer */ - public static ArcGIS.Core.Geometry.Geometry GetGeomConvexHull(FeatureClass fclss, ArcGIS.Core.Data.QueryFilter filter) + public static Task GetGeomConvexHull(FeatureClass fclss, ArcGIS.Core.Data.QueryFilter filter) { ArcGIS.Core.Geometry.Geometry geomIni = null; - geomIni = GetGeomUnica(fclss, filter); - if (geomIni != null) + + return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { - ArcGIS.Core.Geometry.Geometry geomSal = null; - try + geomIni = GetGeomUnica(fclss, filter); + if (geomIni != null) { - geomSal = GeometryEngine.Instance.ConvexHull(geomIni); - return geomSal; + ArcGIS.Core.Geometry.Geometry geomSal = null; + try + { + geomSal = GeometryEngine.Instance.ConvexHull(geomIni); + return geomSal; + } + catch + { + return null; + } } - catch - { + else return null; - } - } - else - return null; + })); } /* @@ -490,7 +500,7 @@ namespace OliviaAddInPro.Helper bool ok = true; ReiniciaOutStr(); string txtsal = string.Empty; - + ReiniciaOutStr(); return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { try @@ -551,6 +561,7 @@ namespace OliviaAddInPro.Helper public static Task GetNumElems(FeatureClass fc, string consulta = "") { int n = -1; + ReiniciaOutStr(); return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => { try @@ -588,5 +599,84 @@ namespace OliviaAddInPro.Helper Free(fc); return n; } + + public static async Task ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, ProgressDialog progrDialog = null) + { + if (!System.IO.Directory.Exists(outpath)) + System.IO.Directory.CreateDirectory(outpath); + ReiniciaOutStr(); + string dirPath; + string fclassName = System.IO.Path.GetFileName(pathLayerIn); + IReadOnlyList parameters = null; + FeatureClass featureClass = null; + var fin = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func)(() => + { + if (string.IsNullOrEmpty(fclassName)) + return false; + + try + { + if (System.IO.Path.GetExtension(pathLayerIn).Equals(".shp")) + { + dirPath = System.IO.Path.GetDirectoryName(pathLayerIn); + //es un shape de entrada + FileSystemConnectionPath fileConnection = new FileSystemConnectionPath(new Uri(dirPath), FileSystemDatastoreType.Shapefile); + using (FileSystemDatastore shapefile = new FileSystemDatastore(fileConnection)) + { + featureClass = shapefile.OpenDataset(fclassName); + } + } + else + { + dirPath = GetPathGdb(pathLayerIn); + //es una feature class de una gdb + using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(dirPath)))) + { + featureClass = fileGeodatabase.OpenDataset(fclassName); + } + } + if (featureClass == null) + return false; + + //Selection selFeatures = featureClass.Select(filter, SelectionType.ObjectID, SelectionOption.Normal); + // make a value array of strings to be passed to ExecuteToolAsync + parameters = Geoprocessing.MakeValueArray(pathLayerIn, outpath, nameShp); + } + catch + { + OutStr = "Ha ocurrido un error al convertir a shape"; + return false; + } + return true; + })); + if(!fin.Result || parameters==null) + { + OutStr = "Ha ocurrido un error al convertir a shape"; + return false; + } + + /*ObservableCollection parameters = new ObservableCollection(); + parameters.Add(pathLayerIn); + parameters.Add(outpath); + parameters.Add(nameShp);*/ + var progSrc = new CancelableProgressorSource(progrDialog); + // execute the tool + IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", parameters, + null, new CancelableProgressorSource(progrDialog).Progressor, GPExecuteToolFlags.GPThread).Result; + + Free(featureClass); + if (string.IsNullOrEmpty(gpResult.ReturnValue)) + { + OutStr = "Ha ocurrido un error en la herramienta de GeoProcesamiento: " + gpResult.ErrorMessages; + return false; + } + else + { + OutStr = "Ok: " + gpResult.ReturnValue; + return true; + } + + } + } } diff --git a/Model/OliviaGlob.cs b/Model/OliviaGlob.cs index 1d7f307..c1b2853 100644 --- a/Model/OliviaGlob.cs +++ b/Model/OliviaGlob.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using OliviaAddInPro.Services; using ArcGIS.Core.Geometry; +using ArcGIS.Desktop.Framework.Threading.Tasks; namespace OliviaAddInPro.Model { @@ -65,7 +66,7 @@ namespace OliviaAddInPro.Model } public static EjecServ Serv { get; } = new EjecServ(); public static SpatialReference SpatRef { get; set; } = null; - + public static ProgressDialog progrDialog { get; set; } = null; #endregion Properties public static void Inicia() diff --git a/Model/TratamientoComun.cs b/Model/TratamientoComun.cs index 1df6233..0900481 100644 --- a/Model/TratamientoComun.cs +++ b/Model/TratamientoComun.cs @@ -14,6 +14,14 @@ namespace OliviaAddInPro.Model * Capa de ámbitos */ public string CapaElems { get; set; } = string.Empty; + /** + * Nombre dle shp exportado de datos + */ + public string NombreShpExport { get; set; } = string.Empty; + /** + * Nombre dle shp exportado de nw + */ + public string NombreShpExportNw { get; set; } = string.Empty; /** * Velocidad de desplazamiento, en km/h. Si es 0, es determinada por la vía */ diff --git a/OliviaAddInPro.csproj b/OliviaAddInPro.csproj index f19240f..750b376 100644 --- a/OliviaAddInPro.csproj +++ b/OliviaAddInPro.csproj @@ -317,7 +317,7 @@ - + diff --git a/Services/EjecServ.cs b/Services/EjecServ.cs index e3bf487..46ab33c 100644 --- a/Services/EjecServ.cs +++ b/Services/EjecServ.cs @@ -8,6 +8,8 @@ using ArcGIS.Core.Data; using ArcGIS.Core.Geometry; using OliviaAddInPro.Helper; using ArcGIS.Core.Internal.Data; +using ArcGIS.Desktop.Framework.Threading.Tasks; +using System.Windows; namespace OliviaAddInPro.Services { @@ -25,6 +27,8 @@ namespace OliviaAddInPro.Services public string name_export_nw = "nw_"; public string ErrStr = ""; + SpatialQueryFilter filtroEspacial = null; + SpatialReference spatRef = null; public TratamientoComun com; /** * Acciones para comenzar ejecución @@ -37,6 +41,7 @@ namespace OliviaAddInPro.Services //esconde el pane OliviaGlob.ShowHidePane(false); + ErrStr = string.Empty; //Cuenta las filas que cumplen la consulta int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs); @@ -50,20 +55,24 @@ namespace OliviaAddInPro.Services Geometry geom_export = null; if (!fue_mal) { - geom_export = GetGeomAmbitsExport(); + geom_export = GetGeomAmbitsExport(); + if (geom_export == null || geom_export.IsEmpty) + { + ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + ErrStr; + fue_mal = true; + } + if (geom_export == null || geom_export.IsEmpty) { fue_mal = true; } } - //mira spatialreference de los datos de entrada - GetSpatialRef(geom_export); - - //crea el filtro de exportación - SpatialQueryFilter filtroEspacial = null; + //crea el filtro de exportación if (!fue_mal) { + //mira spatialreference de los datos de entrada + spatRef = geom_export.SpatialReference; filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export); if (filtroEspacial == null) { @@ -82,7 +91,8 @@ namespace OliviaAddInPro.Services OliviaGlob.ShowHidePane(true); return false; - } + } + /** * Prepara la geometría para exportar los ámbitos @@ -90,6 +100,7 @@ namespace OliviaAddInPro.Services public Geometry GetGeomAmbitsExport() { Geometry geomAux = null; + ErrStr = string.Empty; FeatureClass fc = HelperGdb.GetFtClass(com.CapaElems); QueryFilter filtro = new QueryFilter { WhereClause = com.ConsultaAmbs }; if (fc == null) @@ -97,18 +108,11 @@ namespace OliviaAddInPro.Services ErrStr = "No se ha podido abrir la clase " + com.CapaElems; return null; } - //comprueba que haya elementos que cumplen la consulta - int nElem = HelperGdb.GetNumElems(fc, com.ConsultaAmbs).Result; - if (nElem <= 0) - { - ErrStr = "No existen ámbitos que cumplan las condiciones dadas " + com.ConsultaAmbs; - return null; - } //Primero hace la geometría de los ámbitos que cumplen la consulta - geomAux = HelperGdb.GetGeomConvexHull(fc, filtro); + geomAux = HelperGdb.GetGeomConvexHull(fc, filtro).Result; if (geomAux == null || geomAux.IsEmpty) { - ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs; + ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + HelperGdb.OutStr; return null; } //Hace la intersección de dicha geometría con las zonas @@ -153,7 +157,7 @@ namespace OliviaAddInPro.Services return null; } } - + HelperGdb.Free(fc); return geomAux; } @@ -185,27 +189,26 @@ namespace OliviaAddInPro.Services return str; } - /** - * Coge spatial reference de los datos a exportar - */ - public void GetSpatialRef(Geometry geom) - { - OliviaGlob.SpatRef = geom.SpatialReference; - } - /** * Exporta y lanza proceso y ventana de proceso */ public void Ejecuta(ModosEjec modo) { + //lanza ventana de progreso + OliviaGlob.progrDialog = new ProgressDialog("Exportando Datos", "Cancelar", 100); + OliviaGlob.progrDialog.Show(); - } + //exporta los datos de entrada + bool res=HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, OliviaGlob.progrDialog).Result; + if(!res) + { + string msg = HelperGdb.OutStr; + if (!string.IsNullOrEmpty(msg)) + msg = "Han ocurrido errores al convertir a shape."; + HelperGlobal.ponMsg(msg); + } - /** - * Exporta los datos de entrada y el nw - */ - public void Exporta(ModosEjec modo) - { + } diff --git a/Services/LimpiezaServ.cs b/Services/LimpiezaServ.cs index e944cab..6d0c703 100644 --- a/Services/LimpiezaServ.cs +++ b/Services/LimpiezaServ.cs @@ -27,8 +27,10 @@ namespace OliviaAddInPro.Services */ public bool Sectoriza() { + com = (TratamientoComun)limp; string nombFileAmbs = string.Empty; //Prepara consulta + ErrStr = string.Empty; if (!PreparaConsulta(out nombFileAmbs)) { ErrStr = "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs; @@ -37,14 +39,12 @@ namespace OliviaAddInPro.Services //Prepara nombre string fechaHora = string.Empty; - string nombreDatExport = string.Empty; //se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles) fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss"); //Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp - nombreDatExport = prefNameExport + "T" + limp.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp; + limp.NombreShpExport = prefNameExport + "T" + limp.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp; //comienza ejecucion - com = (TratamientoComun)limp; if(!ComienzaEjec(ModosEjec.Sectoriza)) { return false; @@ -68,7 +68,8 @@ namespace OliviaAddInPro.Services public bool Planifica() { //se asegura que tiene todo para planif - if(!CompruebaPlanif()) + ErrStr = string.Empty; + if (!CompruebaPlanif()) { ErrStr = "En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, necesarias para planificar"; return false; @@ -114,7 +115,6 @@ namespace OliviaAddInPro.Services */ public bool CompruebaPlanif() { - string path = null; //si ha importado no hace falta que compruebe, seguro que las tiene if (OliviaGlob.IsConfig2()) @@ -122,6 +122,9 @@ namespace OliviaAddInPro.Services if (ComprCamposPlanif(limp.CapaElems)) return true; + return false; + /* + string path = null; if (!HelperGlobal.ponMsg("En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, " + "necesarias para planificar. ¿Desea utilizar la sectorización de otra capa?",MessageBoxImage.Question,"OLIVIA", MessageBoxButton.YesNo)) @@ -142,7 +145,7 @@ namespace OliviaAddInPro.Services //almacena la info de secto auxiliar limp.CapaAuxPlanif = path; - return true; + return true;*/ } public bool ComprCamposPlanif(string pathCapa) diff --git a/View/Limpieza/PaneLimpiezaSub2.xaml.cs b/View/Limpieza/PaneLimpiezaSub2.xaml.cs index 58424c0..dd0b77b 100644 --- a/View/Limpieza/PaneLimpiezaSub2.xaml.cs +++ b/View/Limpieza/PaneLimpiezaSub2.xaml.cs @@ -89,7 +89,10 @@ namespace OliviaAddInPro { mod.GeomRestr = geom; } - label_caparestr.Content = texto; + if (geom != null) + label_caparestr.Content = texto; + else + label_caparestr.Content =Resource1.String_selec_capa; } private void button_capaniv_Click(object sender, RoutedEventArgs e) @@ -100,7 +103,10 @@ namespace OliviaAddInPro { mod.GeomNiv = geom; } - label_capaniv.Content = texto; + if (geom != null) + label_capaniv.Content = texto; + else + label_capaniv.Content = Resource1.String_selec_capa; } private void button_capazon_Click(object sender, RoutedEventArgs e) @@ -111,7 +117,11 @@ namespace OliviaAddInPro { mod.GeomZon = geom; } - label_capazon.Content = texto; + + if (geom != null) + label_capazon.Content = texto; + else + label_capazon.Content = Resource1.String_selec_capa; } private void button_capainst_Click(object sender, RoutedEventArgs e) @@ -124,7 +134,10 @@ namespace OliviaAddInPro { mod.CoordsInstal = mp.Coordinate2D; } - label_capainst.Content = texto; + if (geomsal != null) + label_capainst.Content = texto; + else + label_capainst.Content = Resource1.String_selec_capa; } } } diff --git a/View/Limpieza/PaneLimpiezaSub3.xaml b/View/Limpieza/PaneLimpiezaSub3.xaml index 458a3f7..d06585d 100644 --- a/View/Limpieza/PaneLimpiezaSub3.xaml +++ b/View/Limpieza/PaneLimpiezaSub3.xaml @@ -35,7 +35,7 @@