Avanzo como puedo en la importación
parent
d267229f9e
commit
9e8f4e6d25
|
|
@ -120,7 +120,19 @@ namespace OliviaAddInPro.Helper
|
|||
{
|
||||
if (fc == null)
|
||||
return null;
|
||||
ArcGIS.Core.Geometry.SpatialReference spatref = fc.GetDefinition().GetSpatialReference();
|
||||
ArcGIS.Core.Geometry.SpatialReference spatref = null;
|
||||
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
spatref = fc.GetDefinition().GetSpatialReference();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
task.Wait();
|
||||
return spatref;
|
||||
}
|
||||
|
||||
|
|
@ -131,21 +143,38 @@ namespace OliviaAddInPro.Helper
|
|||
{
|
||||
if (gdbName == null || string.IsNullOrEmpty(dataset))
|
||||
return null;
|
||||
Geodatabase gdb = null;
|
||||
FeatureClassDefinition fcdef = null;
|
||||
try
|
||||
{
|
||||
Geodatabase gdb = GetGdb(gdbName).Result;
|
||||
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);
|
||||
ArcGIS.Core.Geometry.SpatialReference spatref = null;
|
||||
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
fcdef = gdb.GetDefinition<FeatureClassDefinition>(dataset);
|
||||
spatref = fcdef.GetSpatialReference();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
task.Wait();
|
||||
return spatref;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Free(gdb);
|
||||
Free(fcdef);
|
||||
}
|
||||
}
|
||||
|
||||
//Dado el tipo de FtClass y una posición inicial abre un diálogo de búsqueda de ftclass
|
||||
|
|
@ -316,11 +345,11 @@ namespace OliviaAddInPro.Helper
|
|||
}
|
||||
|
||||
//Abre una feature class cuando es un shapefile
|
||||
public static async Task<FeatureClass> GetFtClassFromShp(string pathShp)
|
||||
public static Task<FeatureClass> GetFtClassFromShp(string pathShp)
|
||||
{
|
||||
FeatureClass ftclss = null;
|
||||
ReiniciaOutStr();
|
||||
return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<FeatureClass>)(() =>
|
||||
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<FeatureClass>)(() =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(pathShp) && pathShp.Contains(SHP_EXT))
|
||||
{
|
||||
|
|
@ -1272,7 +1301,7 @@ namespace OliviaAddInPro.Helper
|
|||
string message = String.Empty;
|
||||
bool deletionResult = false;
|
||||
|
||||
ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
|
||||
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
|
||||
{
|
||||
|
||||
EditOperation editOperation = new EditOperation();
|
||||
|
|
@ -1309,6 +1338,7 @@ namespace OliviaAddInPro.Helper
|
|||
}
|
||||
|
||||
});
|
||||
task.Wait();
|
||||
|
||||
if (!string.IsNullOrEmpty(message))
|
||||
{
|
||||
|
|
@ -1506,6 +1536,8 @@ namespace OliviaAddInPro.Helper
|
|||
};
|
||||
if (!string.IsNullOrEmpty(initloc_))
|
||||
dlg.InitialLocation = initloc_;
|
||||
else
|
||||
dlg.AlwaysUseInitialLocation = false;
|
||||
if (!string.IsNullOrEmpty(filt_))
|
||||
dlg.Filter = filt_;
|
||||
if (!string.IsNullOrEmpty(ext_))
|
||||
|
|
@ -1524,18 +1556,22 @@ namespace OliviaAddInPro.Helper
|
|||
/**
|
||||
* Comprueva si una GDB contiene un Dataset
|
||||
*/
|
||||
public static bool CheckDataset(Geodatabase gdb, string datasetName)
|
||||
public static Task<bool> CheckDataset(Geodatabase gdb, string datasetName)
|
||||
{
|
||||
try
|
||||
|
||||
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<bool>)(() =>
|
||||
{
|
||||
FeatureClass ftclss = gdb.OpenDataset<FeatureClass>(datasetName);
|
||||
ftclss.Dispose();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
try
|
||||
{
|
||||
FeatureClass ftclss = gdb.OpenDataset<FeatureClass>(datasetName);
|
||||
ftclss.Dispose();
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -1558,7 +1594,7 @@ namespace OliviaAddInPro.Helper
|
|||
return res;
|
||||
}
|
||||
//comprueba si extiste ya el dataset
|
||||
if(CheckDataset(gdb,datasetName))
|
||||
if(CheckDataset(gdb,datasetName).Result)
|
||||
{
|
||||
//comprueba si tiene la misma referencia espacial
|
||||
featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName);
|
||||
|
|
@ -1575,24 +1611,45 @@ namespace OliviaAddInPro.Helper
|
|||
}
|
||||
}
|
||||
//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
|
||||
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<Respuesta<bool>>)(() =>
|
||||
{
|
||||
Respuesta<bool> res2 = new Respuesta<bool> { Value = false };
|
||||
SchemaBuilder schemaBuilder = null;
|
||||
try
|
||||
{
|
||||
schemaBuilder = new SchemaBuilder(gdb);
|
||||
// Create a FeatureDataset
|
||||
FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref);
|
||||
schemaBuilder.Create(featureDatasetDescription);
|
||||
// Build status
|
||||
res2.Value = schemaBuilder.Build();
|
||||
if (!res2.Value && schemaBuilder.ErrorMessages.Count > 0)
|
||||
res2.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
return res2;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (schemaBuilder != null && schemaBuilder.ErrorMessages.Count > 0)
|
||||
res2.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
else
|
||||
res2.Error.Add("Error 1 al crear Dataset.");
|
||||
return res2;
|
||||
}
|
||||
}));
|
||||
task.Wait();
|
||||
if(task.Result.Value)//ha ido bien
|
||||
{
|
||||
if (string.IsNullOrEmpty(datasetNameOut))
|
||||
res.Value = 0;
|
||||
else
|
||||
res.Value = 2;//avisa
|
||||
//actualiza la gdb
|
||||
Refresh(gdbPath);
|
||||
}
|
||||
else// Build errors
|
||||
{
|
||||
res.Value = 1;
|
||||
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
res.Error.Add(task.Result.Error.FirstOrDefault());
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -1621,6 +1678,7 @@ namespace OliviaAddInPro.Helper
|
|||
FeatureClass fc = GetFtClassFromShp(nom_shp).Result;
|
||||
if (fc == null)
|
||||
return res;
|
||||
|
||||
try
|
||||
{
|
||||
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
|
||||
|
|
@ -1642,6 +1700,8 @@ namespace OliviaAddInPro.Helper
|
|||
return res;
|
||||
}
|
||||
res.Value = true;
|
||||
//actualiza la gdb
|
||||
Refresh(System.IO.Path.GetDirectoryName(Gdb_dataset));
|
||||
return res;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -1667,23 +1727,77 @@ namespace OliviaAddInPro.Helper
|
|||
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)
|
||||
|
||||
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<Respuesta<bool>>)(() =>
|
||||
{
|
||||
Respuesta<bool> resp = new Respuesta<bool> { Value = false };
|
||||
SchemaBuilder schemaBuilder = null;
|
||||
try
|
||||
{
|
||||
// Create a FeatureClassDescription object
|
||||
FeatureClassDescription featureClassDescription = new FeatureClassDescription(ftclss.GetDefinition());
|
||||
// Create a SchemaBuilder object
|
||||
schemaBuilder = new SchemaBuilder(gdb);
|
||||
// Add the deletion fo the feature class to our list of DDL tasks
|
||||
schemaBuilder.Delete(featureClassDescription);
|
||||
// Execute the DDL
|
||||
resp.Value = schemaBuilder.Build();
|
||||
if(!resp.Value && schemaBuilder.ErrorMessages.Count>0)
|
||||
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
return resp;
|
||||
}
|
||||
catch
|
||||
{
|
||||
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
return resp;
|
||||
}
|
||||
}));
|
||||
if (task.Result.Value)
|
||||
res.Value = true;
|
||||
else
|
||||
{
|
||||
res.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
|
||||
res.Error.Add(task.Result.Error.FirstOrDefault());
|
||||
}
|
||||
Free(gdb);
|
||||
Free(ftclss);
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Refresca la gdb después de añadir dataset y featureclass
|
||||
*/
|
||||
public static void Refresh(string gdbPath)
|
||||
{
|
||||
Item gdb=null;
|
||||
try
|
||||
{
|
||||
gdb = ItemFactory.Instance.Create(gdbPath);
|
||||
if (gdb == null)
|
||||
return;
|
||||
var contentItem = gdb;
|
||||
//Check if the MCT is required for Refresh()
|
||||
if (contentItem.IsMainThreadRequired)
|
||||
{
|
||||
//QueuedTask.Run must be used if item.IsMainThreadRequired
|
||||
//returns true
|
||||
QueuedTask.Run(() => contentItem.Refresh());
|
||||
}
|
||||
else
|
||||
{
|
||||
//if item.IsMainThreadRequired returns false, any
|
||||
//thread can be used to invoke Refresh(), though
|
||||
//BackgroundTask is preferred.
|
||||
contentItem.Refresh();
|
||||
|
||||
//Or, via BackgroundTask
|
||||
ArcGIS.Core.Threading.Tasks.BackgroundTask.Run(() =>
|
||||
contentItem.Refresh(), ArcGIS.Core.Threading.Tasks.BackgroundProgressor.None);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ namespace OliviaAddInPro.Model
|
|||
//comienza ejecución
|
||||
Action<Respuesta<TiposEjecucion>, TratamientoComun> ac = FinProceSrv.finEjecuta;
|
||||
//pone los flags
|
||||
OliviaGlob.RemoveFlagTipEjec(TiposEjecucion.Config);
|
||||
if (modo == ModosEjec.Sectoriza)
|
||||
OliviaGlob.AddFlagTipEjec(TiposEjecucion.EjecSecto);
|
||||
else if (modo == ModosEjec.Planifica || modo == ModosEjec.SoloPlanifica)
|
||||
|
|
|
|||
|
|
@ -441,15 +441,28 @@ namespace OliviaAddInPro.Services
|
|||
//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());
|
||||
bool sal = true;
|
||||
string ambitos_aux;
|
||||
//repite por si se ha equivocado hasta que elige el nombre de clase
|
||||
do
|
||||
{
|
||||
sal = true;
|
||||
ambitos_aux = HelperGdb.SaveFileDlg("Guardar Feature Class como...", GdbFileName + "\\" + tratamiento, null, null,
|
||||
ArcGIS.Desktop.Core.BrowseProjectFilter.GetFilter("esri_browseDialogFilters_featureClasses_all"));
|
||||
if (string.IsNullOrEmpty(ambitos_aux))
|
||||
sal = HelperGlobal.ponMsg("¿Desea cancelar el proceso de imporación?",
|
||||
MessageBoxImage.Question, "OLIVIA", MessageBoxButton.YesNo);
|
||||
} while (!sal);
|
||||
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) ;
|
||||
dataset = System.IO.Path.GetFileNameWithoutExtension(System.IO.Path.GetDirectoryName(ambitos_aux)) ;
|
||||
}
|
||||
else {
|
||||
res.Error.Add("Se ha cancelado la importación de resultados. Se cancela la elección de nombre de la Feature Class.");
|
||||
return res;
|
||||
}
|
||||
//comprueba si la proyección es la misma la del dataset que la que llega
|
||||
if (!dataset.Equals(tratamiento))
|
||||
|
|
@ -540,7 +553,7 @@ namespace OliviaAddInPro.Services
|
|||
break;
|
||||
}
|
||||
}
|
||||
resp2 = HelperGdb.ImportShp(noms_shp[i], GdbFileName + "\\" + dataset, noms_gdb[i]);
|
||||
resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]);
|
||||
if (!resp2.Value)
|
||||
{
|
||||
err_st = "Error al importar la capa " + noms_gdb[i];
|
||||
|
|
|
|||
|
|
@ -61,16 +61,17 @@ namespace OliviaAddInPro.Services
|
|||
BorraFiles();
|
||||
HelperGlobal.ponMsg(msg);
|
||||
//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);
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst);
|
||||
|
||||
//borra los archivos que le toca borrar
|
||||
BorraFiles();
|
||||
//BorraFiles();
|
||||
}
|
||||
|
||||
public void finEjecuta2(Respuesta<TiposEjecucion> res, TratamientoComun inst)
|
||||
{
|
||||
String msg = string.Empty;
|
||||
String msg_err = "Errores en el proceso de importación de resultados";
|
||||
bool mal = false;
|
||||
try
|
||||
{
|
||||
|
||||
|
|
@ -89,7 +90,10 @@ namespace OliviaAddInPro.Services
|
|||
//importa resultados
|
||||
var resp = IniImport();
|
||||
if (resp.HasError)
|
||||
{
|
||||
msg = resp.Error.First();
|
||||
mal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string GdbFileName = resp.Value;
|
||||
|
|
@ -114,9 +118,12 @@ namespace OliviaAddInPro.Services
|
|||
if (string.IsNullOrEmpty(resp2.Value))
|
||||
{
|
||||
if (resp2.HasError)
|
||||
{
|
||||
msg = resp2.Error.First();
|
||||
}
|
||||
else
|
||||
msg = msg_err;
|
||||
mal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -130,12 +137,29 @@ namespace OliviaAddInPro.Services
|
|||
catch(Exception ex)
|
||||
{
|
||||
msg = msg_err + ": "+msg+": "+ex.Message;
|
||||
mal = true;
|
||||
}
|
||||
if (mal)
|
||||
{
|
||||
//reinicia flags
|
||||
if(OliviaGlob.IsLimp())
|
||||
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Limp);
|
||||
else if(OliviaGlob.IsReco())
|
||||
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Reco);
|
||||
|
||||
}
|
||||
HelperGlobal.ponMsg(msg);
|
||||
OliviaGlob.progrDialog.Hide();
|
||||
//muestra la ventana
|
||||
OliviaGlob.ShowHidePane(true);
|
||||
/*var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
|
||||
{
|
||||
//borra los archivos que le toca borrar
|
||||
BorraFiles();
|
||||
});
|
||||
task.Wait();*/
|
||||
//borra los archivos que le toca borrar
|
||||
BorraFiles();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -237,7 +261,7 @@ namespace OliviaAddInPro.Services
|
|||
|
||||
if (string.IsNullOrEmpty(GdbFileName) || !Directory.Exists(GdbFileName))
|
||||
{
|
||||
res.Error.Add("Se ha cancelado la importación de resultados.");
|
||||
res.Error.Add("Se ha cancelado la importación de resultados. Se cancela la elección de GDB.");
|
||||
return res;
|
||||
}
|
||||
res.Value = GdbFileName;
|
||||
|
|
|
|||
|
|
@ -28,8 +28,6 @@ namespace OliviaAddInPro.Services.LanzaSrv
|
|||
return res;
|
||||
}
|
||||
|
||||
OliviaGlob.TipoEjec = TiposEjecucion.Limp;//OliviaDef.GeneralDef.TiposOliv.OlivLimp;
|
||||
|
||||
//configura el string de opciones
|
||||
if (!configura_ops_geo(limp, modo))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ namespace OliviaAddInPro.Services.LanzaSrv
|
|||
return res;
|
||||
}
|
||||
|
||||
//OliviaGlob.tip_oliv = OliviaDef.GeneralDef.TiposOliv.OlivResi;
|
||||
OliviaGlob.TipoEjec = TiposEjecucion.Reco;//OliviaDef.GeneralDef.TiposOliv.OlivResi;
|
||||
/*if (!OliviaGlob.gdb_reco.exporta(reco, modo == (int)Ejecuta.ModosEjec.Planif))
|
||||
{
|
||||
err_str = OliviaGlob.gdb_reco.err_st;
|
||||
|
|
|
|||
|
|
@ -63,11 +63,11 @@ namespace OliviaAddInPro
|
|||
//The parameter passed to this method will be true if the Dockpane is being opened and it is false when you close the dockpane
|
||||
protected override void OnShow(bool isVisible)
|
||||
{
|
||||
if (isVisible == false && !firstTimeShow && !hideTemp)
|
||||
/*if (isVisible == false && !firstTimeShow && !hideTemp)
|
||||
{
|
||||
//avisa de cerrar la ventana
|
||||
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno);
|
||||
}
|
||||
}*/
|
||||
if (firstTimeShow)
|
||||
firstTimeShow = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -210,6 +210,7 @@ namespace OliviaAddInPro
|
|||
CapaElems = string.Empty;
|
||||
OpsAmbs.Clear();
|
||||
Ambitos.Clear();
|
||||
TipoTto = -1;
|
||||
VisTextAnchoVia = System.Windows.Visibility.Hidden;
|
||||
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config); //lo reinicia, por si estaba después de planificar
|
||||
if (string.IsNullOrEmpty(capa))
|
||||
|
|
|
|||
|
|
@ -61,11 +61,11 @@ namespace OliviaAddInPro
|
|||
//also false the first time
|
||||
protected override void OnShow(bool isVisible)
|
||||
{
|
||||
if (isVisible == false && !firstTimeShow && !hideTemp)
|
||||
/* if (isVisible == false && !firstTimeShow && !hideTemp)
|
||||
{
|
||||
//avisa de cerrar la ventana
|
||||
OliviaGlob.SetFlagTipEjec(TiposEjecucion.Ninguno);
|
||||
}
|
||||
}*/
|
||||
if (firstTimeShow)
|
||||
firstTimeShow = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue