Avances en importación
parent
7ab639b800
commit
d267229f9e
|
|
@ -22,6 +22,7 @@ using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using OliviaAddInPro.View;
|
using OliviaAddInPro.View;
|
||||||
using OliviaAddInPro.Model.contract;
|
using OliviaAddInPro.Model.contract;
|
||||||
|
using ArcGIS.Core.Data.DDL;
|
||||||
|
|
||||||
namespace OliviaAddInPro.Helper
|
namespace OliviaAddInPro.Helper
|
||||||
{
|
{
|
||||||
|
|
@ -115,13 +116,36 @@ namespace OliviaAddInPro.Helper
|
||||||
/**
|
/**
|
||||||
* Devuelve el sistema de coordenadas de una capa
|
* Devuelve el sistema de coordenadas de una capa
|
||||||
*/
|
*/
|
||||||
public static int GetCoorSys(string ftclasspath)
|
public static ArcGIS.Core.Geometry.SpatialReference GetSpatRef(FeatureClass fc)
|
||||||
{
|
{
|
||||||
FeatureClass fc = GetFtClass(ftclasspath);
|
|
||||||
if (fc == null)
|
if (fc == null)
|
||||||
return -1;
|
return null;
|
||||||
ArcGIS.Core.Geometry.SpatialReference spatref = fc.GetDefinition().GetSpatialReference();
|
ArcGIS.Core.Geometry.SpatialReference spatref = fc.GetDefinition().GetSpatialReference();
|
||||||
return spatref.Wkid;
|
return spatref;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Devuelve el sistema de coordenadas de un dataset
|
||||||
|
*/
|
||||||
|
public static ArcGIS.Core.Geometry.SpatialReference GetSpatRef(string gdbName, string dataset)
|
||||||
|
{
|
||||||
|
if (gdbName == null || string.IsNullOrEmpty(dataset))
|
||||||
|
return null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Geodatabase gdb = GetGdb(gdbName).Result;
|
||||||
|
if (gdb == null)
|
||||||
|
return null;
|
||||||
|
FeatureClassDefinition fcdef = gdb.GetDefinition<FeatureClassDefinition>(dataset);
|
||||||
|
ArcGIS.Core.Geometry.SpatialReference spatref = fcdef.GetSpatialReference();
|
||||||
|
Free(gdb);
|
||||||
|
Free(fcdef);
|
||||||
|
return spatref;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass
|
//Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass
|
||||||
|
|
@ -1448,10 +1472,31 @@ namespace OliviaAddInPro.Helper
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cierra todas las capas abiertas
|
||||||
|
*/
|
||||||
|
public static bool CloseAllLayers()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var lyrs = MapView.Active.Map.Layers;
|
||||||
|
foreach (FeatureLayer fl in lyrs)
|
||||||
|
{
|
||||||
|
if (fl != null)
|
||||||
|
MapView.Active.Map.RemoveLayer(fl);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saca diálogo para guardar un archivo
|
* Saca diálogo para guardar un archivo
|
||||||
*/
|
*/
|
||||||
public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_)
|
public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_, BrowseProjectFilter brwsFilt=null)
|
||||||
{
|
{
|
||||||
//Display the filter in an Open Item dialog
|
//Display the filter in an Open Item dialog
|
||||||
SaveItemDialog dlg = new SaveItemDialog
|
SaveItemDialog dlg = new SaveItemDialog
|
||||||
|
|
@ -1465,6 +1510,8 @@ namespace OliviaAddInPro.Helper
|
||||||
dlg.Filter = filt_;
|
dlg.Filter = filt_;
|
||||||
if (!string.IsNullOrEmpty(ext_))
|
if (!string.IsNullOrEmpty(ext_))
|
||||||
dlg.DefaultExt = ext_;
|
dlg.DefaultExt = ext_;
|
||||||
|
if (brwsFilt != null)
|
||||||
|
dlg.BrowseFilter = brwsFilt;
|
||||||
|
|
||||||
bool? ok = dlg.ShowDialog();
|
bool? ok = dlg.ShowDialog();
|
||||||
|
|
||||||
|
|
@ -1473,5 +1520,170 @@ namespace OliviaAddInPro.Helper
|
||||||
else
|
else
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comprueva si una GDB contiene un Dataset
|
||||||
|
*/
|
||||||
|
public static bool CheckDataset(Geodatabase gdb, string datasetName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
FeatureClass ftclss = gdb.OpenDataset<FeatureClass>(datasetName);
|
||||||
|
ftclss.Dispose();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Crea un FeatureDataset con el nombre dado y la spatialrefernece dada en la gdb dada
|
||||||
|
* Devuelve 0 si no hay que crear nada o si lo ha creado bien, 2 si existe el dataset pero con otra referencia espacial, 1 si da error
|
||||||
|
*/
|
||||||
|
public static Respuesta<int> CreateDataset(string gdbPath, string datasetName, ArcGIS.Core.Geometry.SpatialReference spatref, out string datasetNameOut)
|
||||||
|
{
|
||||||
|
Respuesta<int> res = new Respuesta<int> { Value = 1 };
|
||||||
|
datasetNameOut = string.Empty;
|
||||||
|
Geodatabase gdb = null;
|
||||||
|
FeatureDatasetDefinition featureDatasetDefinition = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
gdb = GetGdb(gdbPath).Result;
|
||||||
|
if(gdb==null)
|
||||||
|
{
|
||||||
|
res.Value = 1;
|
||||||
|
res.Error.Add("Error al abrir la gdb " + gdbPath);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
//comprueba si extiste ya el dataset
|
||||||
|
if(CheckDataset(gdb,datasetName))
|
||||||
|
{
|
||||||
|
//comprueba si tiene la misma referencia espacial
|
||||||
|
featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName);
|
||||||
|
if (featureDatasetDefinition.GetSpatialReference().Equals(spatref))
|
||||||
|
{
|
||||||
|
res.Value = 0; //no hay nada que crear, existe y coincide la spatial ref
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//crea un nuevo dataset y avisa
|
||||||
|
datasetName = datasetName + "_1";
|
||||||
|
datasetNameOut = datasetName;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//no existe, lo crea
|
||||||
|
SchemaBuilder schemaBuilder = new SchemaBuilder(gdb);
|
||||||
|
// Create a FeatureDataset
|
||||||
|
FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref);
|
||||||
|
schemaBuilder.Create(featureDatasetDescription);
|
||||||
|
|
||||||
|
// Build status
|
||||||
|
bool buildStatus = schemaBuilder.Build();
|
||||||
|
if(buildStatus)//ha ido bien
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(datasetNameOut))
|
||||||
|
res.Value = 0;
|
||||||
|
else
|
||||||
|
res.Value = 2;//avisa
|
||||||
|
}
|
||||||
|
else// Build errors
|
||||||
|
{
|
||||||
|
res.Value = 1;
|
||||||
|
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
res.Value = 1;
|
||||||
|
res.Error.Add("Errores al crear el Dataset "+datasetName + " " +ex.Message);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Free(featureDatasetDefinition);
|
||||||
|
Free(gdb);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Importa el shp en la gdb y el dataset, como una featureclass
|
||||||
|
*/
|
||||||
|
public static Respuesta<bool> ImportShp(string nom_shp, string Gdb_dataset, string namefc)
|
||||||
|
{
|
||||||
|
var res = new Respuesta<bool> { Value = false };
|
||||||
|
string[] args = { nom_shp, Gdb_dataset, namefc};
|
||||||
|
// execute the tool
|
||||||
|
FeatureClass fc = GetFtClassFromShp(nom_shp).Result;
|
||||||
|
if (fc == null)
|
||||||
|
return res;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
|
||||||
|
var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: spatref);
|
||||||
|
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args,
|
||||||
|
environments, null, null).Result;
|
||||||
|
if (gpResult.IsCanceled)
|
||||||
|
{
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
if (gpResult.IsFailed)
|
||||||
|
{
|
||||||
|
string msg;
|
||||||
|
if (gpResult.ErrorMessages != null)
|
||||||
|
msg = gpResult.ErrorMessages.First().Text;
|
||||||
|
else
|
||||||
|
msg = "Errores en la importación";
|
||||||
|
res.Error.Add("Error: " + msg);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
res.Value = true;
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
res.Error.Add("Error: " + ex.Message);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
Free(fc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Borrar una feature class de un dataset
|
||||||
|
*/
|
||||||
|
public static Respuesta<bool> DeleteFeatureClass(string gdbPath, string featureClassPath)
|
||||||
|
{
|
||||||
|
var res = new Respuesta<bool> { Value = false };
|
||||||
|
FeatureClass ftclss = GetFtClass(featureClassPath);
|
||||||
|
if (ftclss == null)
|
||||||
|
return res;
|
||||||
|
Geodatabase gdb = GetGdb(gdbPath).Result;
|
||||||
|
if (gdb == null)
|
||||||
|
return res;
|
||||||
|
// Create a FeatureClassDescription object
|
||||||
|
FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition());
|
||||||
|
// Create a SchemaBuilder object
|
||||||
|
SchemaBuilder schemaBuilder = new SchemaBuilder(gdb);
|
||||||
|
// Add the deletion fo the feature class to our list of DDL tasks
|
||||||
|
schemaBuilder.Delete(featureClassDescription);
|
||||||
|
// Execute the DDL
|
||||||
|
bool success = schemaBuilder.Build();
|
||||||
|
if (success)
|
||||||
|
res.Value = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||||
|
}
|
||||||
|
Free(gdb);
|
||||||
|
Free(ftclss);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,12 @@ namespace OliviaAddInPro.Model
|
||||||
OliviaGlob.ShowHidePane(false);
|
OliviaGlob.ShowHidePane(false);
|
||||||
//comienza ejecución
|
//comienza ejecución
|
||||||
Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta;
|
Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta;
|
||||||
|
//pone los flags
|
||||||
|
if (modo == ModosEjec.Sectoriza)
|
||||||
|
OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecSecto);
|
||||||
|
else if (modo == ModosEjec.Planifica || modo == ModosEjec.SoloPlanifica)
|
||||||
|
OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecPlanif);
|
||||||
|
//llama ejecuta
|
||||||
EjecutaAsync(modo, ac);
|
EjecutaAsync(modo, ac);
|
||||||
}
|
}
|
||||||
public async void EjecutaAsync(ModosEjec modo, Action<Respuesta<TiposEjecucion>, TratamientoComun> ffin)
|
public async void EjecutaAsync(ModosEjec modo, Action<Respuesta<TiposEjecucion>, TratamientoComun> ffin)
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,22 @@ namespace OliviaAddInPro.Services
|
||||||
public class EjecServ
|
public class EjecServ
|
||||||
{
|
{
|
||||||
//Cadenas de nombres internos para la exportación/importación de los archivos
|
//Cadenas de nombres internos para la exportación/importación de los archivos
|
||||||
public string prefNameExport = "data_";
|
public string PREF_NAME_EXPORT = "data_";
|
||||||
public string extShp = ".shp";
|
public string EXT_SHP = ".shp";
|
||||||
public string prefNameExportNw = "nw_";
|
public string PREF_NAME_EXPORT_NW = "nw_";
|
||||||
|
public string NAME_CSV = "_L";
|
||||||
|
public string EXT_CSV = ".csv";
|
||||||
|
public string NAME_RUTA2 = "_R2";
|
||||||
|
public string NAME_RUTA2_OUT = "_Viajes";
|
||||||
|
public string NAME_AUX = "_aux";
|
||||||
|
public string NAME_SECT = "_Sector";
|
||||||
|
public string NAME_CONTROL_OUT = "_Control";
|
||||||
|
public string NAME_CONTROL = "_C";
|
||||||
|
public string NAME_RUTA_OUT = "_Ruta";
|
||||||
|
public string NAME_RUTA = "_R";
|
||||||
|
public string NAME_RUTA_AUX = "_Raux";
|
||||||
|
public string NAME_INSTAL = "_I";
|
||||||
|
public string NAME_INSTAL_OUT = "_Instalacion";
|
||||||
|
|
||||||
public string ErrStr = "";
|
public string ErrStr = "";
|
||||||
SpatialQueryFilter filtroEspacial = null;
|
SpatialQueryFilter filtroEspacial = null;
|
||||||
|
|
@ -87,7 +100,7 @@ namespace OliviaAddInPro.Services
|
||||||
//se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles)
|
//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");
|
fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss");
|
||||||
//Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp
|
//Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp
|
||||||
com.NombreShpExport = prefNameExport + com.NombreShpExp_PrefTto + "_" + fechaHora + extShp;
|
com.NombreShpExport = PREF_NAME_EXPORT + com.NombreShpExp_PrefTto + "_" + fechaHora + EXT_SHP;
|
||||||
|
|
||||||
com.ProgrSrc.IncMessage(10, "Exportando ámbitos de trabajo");
|
com.ProgrSrc.IncMessage(10, "Exportando ámbitos de trabajo");
|
||||||
|
|
||||||
|
|
@ -228,7 +241,7 @@ namespace OliviaAddInPro.Services
|
||||||
com.ProgrSrc.IncMessage(10, "Exportando red navegable");//60%
|
com.ProgrSrc.IncMessage(10, "Exportando red navegable");//60%
|
||||||
|
|
||||||
//Prepara nombre de exportación
|
//Prepara nombre de exportación
|
||||||
com.NombreShpExportNw = prefNameExportNw + fechaHora + extShp;
|
com.NombreShpExportNw = PREF_NAME_EXPORT_NW + fechaHora + EXT_SHP;
|
||||||
//exporta los datos de entrada
|
//exporta los datos de entrada
|
||||||
if (!HelperGdb.ExportShp2(OliviaGlob.Paths.PathGdbNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, com.ProgrSrc._ProgrSrc, spatRefData,100))
|
if (!HelperGdb.ExportShp2(OliviaGlob.Paths.PathGdbNw, filtroEspacial, com.NombreShpExportNw, OliviaGlob.Paths.DirData, com.ProgrSrc._ProgrSrc, spatRefData,100))
|
||||||
{
|
{
|
||||||
|
|
@ -362,45 +375,206 @@ namespace OliviaAddInPro.Services
|
||||||
/**
|
/**
|
||||||
* Realiza las funciones de importación de la sectorización
|
* Realiza las funciones de importación de la sectorización
|
||||||
*/
|
*/
|
||||||
public Respuesta<bool> ImportSecto(string GdbFileName)
|
public Respuesta<string> ImportSecto(string GdbFileName)
|
||||||
{
|
{
|
||||||
var res = new Respuesta<bool> { Value = false };
|
/*var res = new Respuesta<string> { Value = string.Empty };
|
||||||
|
return res;*/
|
||||||
|
return Import(GdbFileName, 0);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Realiza las funciones de importación, modo 0 secto, modo 1 planif
|
||||||
|
*/
|
||||||
|
public Respuesta<string> Import(string GdbFileName, int modo)
|
||||||
|
{
|
||||||
|
var res = new Respuesta<string> { Value = string.Empty };
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
string path_shape = OliviaGlob.Paths.PathData;
|
||||||
|
string dir_shp = System.IO.Path.GetDirectoryName(path_shape);
|
||||||
|
string shapefile = System.IO.Path.GetFileNameWithoutExtension(path_shape);
|
||||||
|
int ind = shapefile.IndexOf("_", 0);
|
||||||
|
string prefijo = shapefile.Substring(ind + 1, 1);
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////////
|
||||||
|
//decodifica el nombre del shapefile para asignarle el correspondiente nombre en la GDB a la que se importa el shape
|
||||||
|
string tratamiento = string.Empty;
|
||||||
|
string ambitos = string.Empty;
|
||||||
|
com.decode_gdb(shapefile, out tratamiento, out ambitos); //supsuestamente distingue si es limpieza o recogida
|
||||||
/*
|
/*
|
||||||
try
|
if (prefijo == "T")
|
||||||
{
|
{
|
||||||
//temp
|
com.decode_gdb(shapefile, out tratamiento, out ambitos);
|
||||||
string name;
|
|
||||||
res = import_secto_fin(GdbFileName, out name);
|
|
||||||
if (!res.Value)
|
|
||||||
{
|
|
||||||
res.Error.Add("Error al importar resultados.");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
res = pinta_sectores(GdbFileName, name, 4);
|
|
||||||
if (!res.Value)
|
|
||||||
{
|
|
||||||
res.Error.Add("Error al pintar sectores.");
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception)
|
else if (prefijo == "F")
|
||||||
{
|
{
|
||||||
res.Error.Add("Se ha cancelado la importación de resultados.");
|
com.decode_gdb(shapefile, out tratamiento, out ambitos);
|
||||||
|
}*/
|
||||||
|
if(string.IsNullOrEmpty(tratamiento) || string.IsNullOrEmpty(ambitos))
|
||||||
|
{
|
||||||
|
res.Error.Add(string.Format("Nombre del archivo a importar erróneo. No se reconoce el prefijo introducido: {0}", prefijo));
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
res.Value = true;
|
|
||||||
return res;*/
|
|
||||||
|
|
||||||
|
bool reco_o_limp_con_instala = (prefijo == "F") ||
|
||||||
|
((prefijo == "T") && !com.CoordsInstal.Equals(new Coordinate2D(0, 0)));
|
||||||
|
bool reco_tramos = System.IO.File.Exists(System.IO.Path.Combine(dir_shp, shapefile + NAME_RUTA2 + EXT_SHP));
|
||||||
|
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//crea el dataset o comprueba si existe
|
||||||
|
string datasetNameOut = string.Empty;
|
||||||
|
var resp = HelperGdb.CreateDataset(GdbFileName, tratamiento, spatRefData, out datasetNameOut);
|
||||||
|
string err_spatref = "Atención, no coincide la proyección de las FeatureClass del Dataset ya creado con la del FeatureClass a importar";
|
||||||
|
if (resp.Value == 1)
|
||||||
|
{
|
||||||
|
res.Error.Add("Error al crear el Dataset para importar" + tratamiento);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
else if (resp.Value == 2)
|
||||||
|
{
|
||||||
|
//avisa
|
||||||
|
HelperGlobal.ponMsg(err_spatref +", se ha creado un nuevo dataset "+ datasetNameOut );
|
||||||
|
tratamiento = datasetNameOut;
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//pregunta a ver si se quiere ese nombre u otro
|
||||||
|
bool replace = false;
|
||||||
|
string dataset = tratamiento;
|
||||||
|
|
||||||
|
string ambitos_aux = HelperGdb.SaveFileDlg("Guardar Feature Class como...", GdbFileName + "\\" + tratamiento + "\\" + ambitos, null, null,
|
||||||
|
new ArcGIS.Desktop.Core.BrowseProjectFilter());
|
||||||
|
if (!string.IsNullOrEmpty(ambitos_aux))
|
||||||
|
{
|
||||||
|
//sustituye los ámbitos por los elegidos
|
||||||
|
ambitos = System.IO.Path.GetFileNameWithoutExtension(ambitos_aux);
|
||||||
|
replace = System.IO.File.Exists(ambitos_aux);
|
||||||
|
dataset = System.IO.Path.GetDirectoryName(ambitos_aux) ;
|
||||||
|
}
|
||||||
|
//comprueba si la proyección es la misma la del dataset que la que llega
|
||||||
|
if (!dataset.Equals(tratamiento))
|
||||||
|
{
|
||||||
|
//ha cambiado de dataset al elegir
|
||||||
|
//comprueba las proyecciones
|
||||||
|
if (!HelperGdb.GetSpatRef(GdbFileName, dataset).Equals(spatRefData))
|
||||||
|
{
|
||||||
|
//avisa
|
||||||
|
HelperGlobal.ponMsg(err_spatref);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//todo ok, se pone a importar
|
||||||
|
string err_st=string.Empty;
|
||||||
|
string name = ambitos;
|
||||||
|
string path_import = GdbFileName + "\\" + dataset + "\\" + ambitos;
|
||||||
|
int NIMPORT;
|
||||||
|
string[] noms_shp = null;
|
||||||
|
string[] noms_gdb = null;
|
||||||
|
int i;
|
||||||
|
int ii = 0;
|
||||||
|
NIMPORT = 0;
|
||||||
|
if (modo == 0) //sectoriza
|
||||||
|
{
|
||||||
|
NIMPORT = 2;
|
||||||
|
noms_shp = new string[NIMPORT];
|
||||||
|
noms_gdb = new string[NIMPORT];
|
||||||
|
noms_shp[0] = shapefile;
|
||||||
|
noms_gdb[0] = ambitos;
|
||||||
|
noms_shp[1] = shapefile + NAME_AUX;
|
||||||
|
noms_gdb[1] = ambitos + NAME_SECT;
|
||||||
|
}
|
||||||
|
else if (modo == 1) //planifica
|
||||||
|
{
|
||||||
|
if (reco_o_limp_con_instala)
|
||||||
|
NIMPORT = 6;
|
||||||
|
else
|
||||||
|
NIMPORT = 5;
|
||||||
|
if (reco_tramos)
|
||||||
|
NIMPORT++;
|
||||||
|
noms_shp = new string[NIMPORT];
|
||||||
|
noms_gdb = new string[NIMPORT];
|
||||||
|
noms_shp[0] = shapefile;
|
||||||
|
noms_gdb[0] = ambitos;
|
||||||
|
noms_shp[1] = shapefile + NAME_AUX;
|
||||||
|
noms_gdb[1] = ambitos + NAME_SECT;
|
||||||
|
noms_shp[2] = shapefile + NAME_CONTROL;
|
||||||
|
noms_gdb[2] = ambitos + NAME_CONTROL_OUT;
|
||||||
|
noms_shp[3] = shapefile + NAME_RUTA;
|
||||||
|
noms_gdb[3] = ambitos + NAME_RUTA_OUT;
|
||||||
|
noms_shp[4] = shapefile + NAME_RUTA_AUX;
|
||||||
|
noms_gdb[4] = ambitos + NAME_RUTA_OUT + NAME_AUX;
|
||||||
|
ii = 5;
|
||||||
|
if (reco_o_limp_con_instala)
|
||||||
|
{
|
||||||
|
noms_shp[5] = shapefile + NAME_INSTAL;
|
||||||
|
noms_gdb[5] = ambitos + NAME_INSTAL_OUT;
|
||||||
|
ii++;
|
||||||
|
}
|
||||||
|
if (reco_tramos)
|
||||||
|
{
|
||||||
|
noms_shp[ii] = shapefile + NAME_RUTA2;
|
||||||
|
noms_gdb[ii] = ambitos + NAME_RUTA2_OUT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (noms_gdb == null || noms_shp==null)
|
||||||
|
{
|
||||||
|
res.Error.Add("Errores al crear los nombres de las Feature Class");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
Respuesta<bool> resp2;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/////////////////////////////////////////
|
||||||
|
//se embucla para hacer todas las importaciones necesarias
|
||||||
|
for (i = 0; i < NIMPORT; i++)
|
||||||
|
{
|
||||||
|
//mira a ver si hay que borrar para reemplazar
|
||||||
|
if (replace)
|
||||||
|
{
|
||||||
|
resp2 = HelperGdb.DeleteFeatureClass(GdbFileName, noms_gdb[i]);
|
||||||
|
if (!resp2.Value)
|
||||||
|
{
|
||||||
|
err_st = "Error al sobreescribir la capa " + noms_gdb[i];
|
||||||
|
if (resp2.HasError)
|
||||||
|
err_st += " " + resp2.Error.First();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
resp2 = HelperGdb.ImportShp(noms_shp[i], GdbFileName + "\\" + dataset, noms_gdb[i]);
|
||||||
|
if (!resp2.Value)
|
||||||
|
{
|
||||||
|
err_st = "Error al importar la capa " + noms_gdb[i];
|
||||||
|
if (resp2.HasError)
|
||||||
|
err_st += " " + resp2.Error.First();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (i < NIMPORT)
|
||||||
|
{
|
||||||
|
res.Error.Add("Errores en la importación: "+err_st);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
res.Error.Add("Errores en la importación");
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
res.Value = path_import;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Realiza las funciones de importación de la planificación
|
* Realiza las funciones de importación de la planificación
|
||||||
*/
|
*/
|
||||||
public Respuesta<bool> ImportPlanif(string GdbFileName)
|
public Respuesta<string> ImportPlanif(string GdbFileName)
|
||||||
{
|
{
|
||||||
var res = new Respuesta<bool> { Value = false };
|
var res = new Respuesta<string> { Value = string.Empty };
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,7 @@ namespace OliviaAddInPro.Services
|
||||||
{
|
{
|
||||||
//REVISAR CUANDO ACABA, SE CAMBIE EL MARCHANDO PARA QUE SE LE DE A FINALIZAR Y TERMINA OK
|
//REVISAR CUANDO ACABA, SE CAMBIE EL MARCHANDO PARA QUE SE LE DE A FINALIZAR Y TERMINA OK
|
||||||
|
|
||||||
String msg=string.Empty;
|
/*String msg=string.Empty;
|
||||||
//gestiona los flags, el estado de finok o finnok va en res.Vale
|
//gestiona los flags, el estado de finok o finnok va en res.Vale
|
||||||
if (res.HasError)
|
if (res.HasError)
|
||||||
{
|
{
|
||||||
|
|
@ -60,14 +60,82 @@ namespace OliviaAddInPro.Services
|
||||||
//borra los archivos que le toca borrar
|
//borra los archivos que le toca borrar
|
||||||
BorraFiles();
|
BorraFiles();
|
||||||
HelperGlobal.ponMsg(msg);
|
HelperGlobal.ponMsg(msg);
|
||||||
Application.Current.Dispatcher.Invoke(new Action(() => { finEjecuta2(); }));
|
//Application.Current.Dispatcher.Invoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>(((p, v)) => { finEjecuta2(p, v); }));*/
|
||||||
|
Application.Current.Dispatcher.Invoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst);
|
||||||
|
|
||||||
|
//borra los archivos que le toca borrar
|
||||||
|
BorraFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void finEjecuta2()
|
public void finEjecuta2(Respuesta<TiposEjecucion> res, TratamientoComun inst)
|
||||||
{
|
{
|
||||||
|
String msg = string.Empty;
|
||||||
|
String msg_err = "Errores en el proceso de importación de resultados";
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
//gestiona los flags, el estado de finok o finnok va en res.Vale
|
||||||
|
if (res.HasError)
|
||||||
|
{
|
||||||
|
msg = res.Error.First();
|
||||||
|
//actualiza los flags
|
||||||
|
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecNOk);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//actualiza los flags
|
||||||
|
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.FinEjecOk);
|
||||||
|
//importa resultados
|
||||||
|
var resp = IniImport();
|
||||||
|
if (resp.HasError)
|
||||||
|
msg = resp.Error.First();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
string GdbFileName = resp.Value;
|
||||||
|
var resp2 = new Respuesta<string> { Value = string.Empty };
|
||||||
|
if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecSecto)) //Ha terminado bien la sectorización
|
||||||
|
{
|
||||||
|
//actualiza los flags
|
||||||
|
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.EjecSecto);
|
||||||
|
//acciones de importación
|
||||||
|
resp2 = inst.ServCom.ImportSecto(GdbFileName);
|
||||||
|
}
|
||||||
|
else if (OliviaGlob.HasFlagTipEjec(TiposEjecucion.EjecPlanif)) //Ha terminado bien la planificación
|
||||||
|
{
|
||||||
|
//actualiza los flags
|
||||||
|
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.EjecPlanif);
|
||||||
|
//guarda csv
|
||||||
|
GuardaCsv(inst);
|
||||||
|
//acciones de importación
|
||||||
|
resp2 = inst.ServCom.ImportPlanif(GdbFileName);
|
||||||
|
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(resp2.Value))
|
||||||
|
{
|
||||||
|
if (resp2.HasError)
|
||||||
|
msg = resp2.Error.First();
|
||||||
|
else
|
||||||
|
msg = msg_err;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
msg = Resource1.String_exito;
|
||||||
|
//pone modo config2
|
||||||
|
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(Exception ex)
|
||||||
|
{
|
||||||
|
msg = msg_err + ": "+msg+": "+ex.Message;
|
||||||
|
}
|
||||||
|
|
||||||
|
HelperGlobal.ponMsg(msg);
|
||||||
OliviaGlob.progrDialog.Hide();
|
OliviaGlob.progrDialog.Hide();
|
||||||
//muestra la ventana
|
//muestra la ventana
|
||||||
OliviaGlob.ShowHidePane(true);
|
OliviaGlob.ShowHidePane(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -113,8 +181,6 @@ namespace OliviaAddInPro.Services
|
||||||
MessageBox.Show(ex.Message);
|
MessageBox.Show(ex.Message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static string NAME_CSV = "_L";
|
|
||||||
public static string EXT_CSV = ".csv";
|
|
||||||
/*
|
/*
|
||||||
* Permite guardar el archivo CSV que contiene la secuencia que se ha llevado a cabo en las rutas en la planificación.
|
* Permite guardar el archivo CSV que contiene la secuencia que se ha llevado a cabo en las rutas en la planificación.
|
||||||
*/
|
*/
|
||||||
|
|
@ -124,7 +190,7 @@ namespace OliviaAddInPro.Services
|
||||||
string[] nameDokL;
|
string[] nameDokL;
|
||||||
string DirData = System.IO.Path.GetDirectoryName(OliviaGlob.Paths.PathData);
|
string DirData = System.IO.Path.GetDirectoryName(OliviaGlob.Paths.PathData);
|
||||||
nameDokL = Directory.GetFiles(DirData,
|
nameDokL = Directory.GetFiles(DirData,
|
||||||
System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + NAME_CSV + ".*");
|
System.IO.Path.GetFileNameWithoutExtension(OliviaGlob.Paths.PathData) + inst.ServCom.NAME_CSV + ".*");
|
||||||
|
|
||||||
string Title = "Guardar Secuencia de la Planificación";
|
string Title = "Guardar Secuencia de la Planificación";
|
||||||
string Filter = "Secuencia en formato CSV (*.csv)|*.csv";
|
string Filter = "Secuencia en formato CSV (*.csv)|*.csv";
|
||||||
|
|
@ -133,7 +199,7 @@ namespace OliviaAddInPro.Services
|
||||||
string InitialDirectory = System.IO.Path.Combine(DirData, nombre);
|
string InitialDirectory = System.IO.Path.Combine(DirData, nombre);
|
||||||
|
|
||||||
|
|
||||||
string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, EXT_CSV, Filter);
|
string FileName = HelperGdb.SaveFileDlg(Title, InitialDirectory, inst.ServCom.EXT_CSV, Filter);
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(FileName) || FileName.Length == 0)
|
if (string.IsNullOrEmpty(FileName) || FileName.Length == 0)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,8 @@ namespace OliviaAddInPro.Services
|
||||||
{
|
{
|
||||||
cancela_permu = false;
|
cancela_permu = false;
|
||||||
}
|
}
|
||||||
res.Error.Add("Proceso Cancelado por el usuario");
|
if(!fin) //si no ha finalizado normal, el usuario lo ha cancelado
|
||||||
|
res.Error.Add("Proceso Cancelado por el usuario");
|
||||||
}
|
}
|
||||||
else if (!first_send_cfg && ((Math.Abs(Environment.TickCount) - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea
|
else if (!first_send_cfg && ((Math.Abs(Environment.TickCount) - lastprog) >= m_tm_progr) && !fin) //en caso normal, todo va bien, pide el progreso y la tarea
|
||||||
{
|
{
|
||||||
|
|
@ -503,10 +504,22 @@ namespace OliviaAddInPro.Services
|
||||||
else if(actu == TiposActu.ActuFinOk)
|
else if(actu == TiposActu.ActuFinOk)
|
||||||
cps.SetProceso("Proceso Finalizado.");
|
cps.SetProceso("Proceso Finalizado.");
|
||||||
|
|
||||||
if (actu > TiposActu.ActuFinOk)
|
//FALTA CAMBIAR EL NOMBRE DEL BOTÓN DE CANCELAR
|
||||||
|
/*if (actu > TiposActu.ActuFinOk)
|
||||||
cps.SetEstado("Calculando...");
|
cps.SetEstado("Calculando...");
|
||||||
if ((actu == TiposActu.ActuPermu) && !cancela)
|
if ((actu == TiposActu.ActuPermu) && !cancela)
|
||||||
cps.SetEstado("Calculando Permutaciones...");
|
cps.SetEstado("Calculando Permutaciones...");
|
||||||
|
|
||||||
|
if ((actu == TiposActu.ActuMal) || (actu == TiposActu.ActuFinNOk))
|
||||||
|
col = 2;
|
||||||
|
else
|
||||||
|
col = 1;
|
||||||
|
|
||||||
|
|
||||||
|
if (actu > TiposActu.ActuFinOk)
|
||||||
|
button_canc.Text = "Finalizar";
|
||||||
|
if ((actu == TiposActu.ActuPermu) && !cancela)
|
||||||
|
button_canc.Text = "Parar permu.";*/
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
* Para poder actualizar la barra de progreso hay que llamar a invoke
|
* Para poder actualizar la barra de progreso hay que llamar a invoke
|
||||||
|
|
|
||||||
|
|
@ -177,20 +177,19 @@ namespace OliviaAddInPro
|
||||||
public void Ejecuta(OliviaAddInPro.Services.ModosEjec modo)
|
public void Ejecuta(OliviaAddInPro.Services.ModosEjec modo)
|
||||||
{
|
{
|
||||||
string err = "";
|
string err = "";
|
||||||
//marchando
|
|
||||||
|
|
||||||
|
|
||||||
OliviaGlob.Limp.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel());
|
|
||||||
OliviaGlob.progrDialog.Show();
|
|
||||||
|
|
||||||
//oculta la ventana
|
|
||||||
OliviaGlob.ShowHidePane(false);
|
|
||||||
|
|
||||||
if (!Lee(out err))
|
if (!Lee(out err))
|
||||||
{
|
{
|
||||||
HelperGlobal.ponMsg(err);
|
HelperGlobal.ponMsg(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//marchando
|
||||||
|
OliviaGlob.Limp.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel());
|
||||||
|
|
||||||
|
//oculta la ventana
|
||||||
|
OliviaGlob.ShowHidePane(false);
|
||||||
|
|
||||||
OliviaGlob.limp.ComienzaEjec(modo);
|
OliviaGlob.limp.ComienzaEjec(modo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -230,6 +230,12 @@ namespace OliviaAddInPro
|
||||||
HelperGlobal.ponMsg(err);
|
HelperGlobal.ponMsg(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//marchando
|
||||||
|
OliviaGlob.Reco.ProgrSrc = new MyCancelableProgressorSource(OliviaGlob.progrDialog.GetViewModel());
|
||||||
|
|
||||||
|
//oculta la ventana
|
||||||
|
OliviaGlob.ShowHidePane(false);
|
||||||
|
|
||||||
OliviaGlob.Reco.ComienzaEjec(modo);
|
OliviaGlob.Reco.ComienzaEjec(modo);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue