No demasiados avances en importación

Elena/develop
Elena 2022-05-26 11:12:21 +02:00
parent 9e8f4e6d25
commit e2ec0d2dc6
5 changed files with 100 additions and 45 deletions

View File

@ -122,7 +122,7 @@ namespace OliviaAddInPro.Helper
return null;
ArcGIS.Core.Geometry.SpatialReference spatref = null;
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
{
try
{
spatref = fc.GetDefinition().GetSpatialReference();
@ -146,7 +146,7 @@ namespace OliviaAddInPro.Helper
Geodatabase gdb = null;
FeatureClassDefinition fcdef = null;
try
{
{
gdb = GetGdb(gdbName).Result;
if (gdb == null)
return null;
@ -160,7 +160,7 @@ namespace OliviaAddInPro.Helper
}
catch
{
}
});
task.Wait();
@ -1526,7 +1526,7 @@ namespace OliviaAddInPro.Helper
/**
* Saca diálogo para guardar un archivo
*/
public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_, BrowseProjectFilter brwsFilt=null)
public static string SaveFileDlg(string title_, string initloc_, string ext_, string filt_, BrowseProjectFilter brwsFilt = null)
{
//Display the filter in an Open Item dialog
SaveItemDialog dlg = new SaveItemDialog
@ -1556,9 +1556,9 @@ namespace OliviaAddInPro.Helper
/**
* Comprueva si una GDB contiene un Dataset
*/
public static Task<bool> CheckDataset(Geodatabase gdb, string datasetName)
public static Task<bool> CheckDataset(Geodatabase gdb, string datasetName)
{
return ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<bool>)(() =>
{
try
@ -1571,14 +1571,14 @@ namespace OliviaAddInPro.Helper
{
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)
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;
@ -1587,14 +1587,14 @@ namespace OliviaAddInPro.Helper
try
{
gdb = GetGdb(gdbPath).Result;
if(gdb==null)
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).Result)
if (CheckDataset(gdb, datasetName).Result)
{
//comprueba si tiene la misma referencia espacial
featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName);
@ -1620,7 +1620,7 @@ namespace OliviaAddInPro.Helper
schemaBuilder = new SchemaBuilder(gdb);
// Create a FeatureDataset
FeatureDatasetDescription featureDatasetDescription = new FeatureDatasetDescription(datasetName, spatref);
schemaBuilder.Create(featureDatasetDescription);
schemaBuilder.Create(featureDatasetDescription);
// Build status
res2.Value = schemaBuilder.Build();
if (!res2.Value && schemaBuilder.ErrorMessages.Count > 0)
@ -1637,7 +1637,7 @@ namespace OliviaAddInPro.Helper
}
}));
task.Wait();
if(task.Result.Value)//ha ido bien
if (task.Result.Value)//ha ido bien
{
if (string.IsNullOrEmpty(datasetNameOut))
res.Value = 0;
@ -1645,7 +1645,7 @@ namespace OliviaAddInPro.Helper
res.Value = 2;//avisa
//actualiza la gdb
Refresh(gdbPath);
}
}
else// Build errors
{
res.Value = 1;
@ -1656,7 +1656,7 @@ namespace OliviaAddInPro.Helper
catch (Exception ex)
{
res.Value = 1;
res.Error.Add("Errores al crear el Dataset "+datasetName + " " +ex.Message);
res.Error.Add("Errores al crear el Dataset " + datasetName + " " + ex.Message);
return res;
}
finally
@ -1669,22 +1669,21 @@ namespace OliviaAddInPro.Helper
/**
* 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)
*/
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};
string[] args = { nom_shp, Gdb_dataset, namefc };
// execute the tool
FeatureClass fc = GetFtClassFromShp(nom_shp).Result;
if (fc == null)
return res;
try
try
{
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: spatref);
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args,
environments, null, null).Result;
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, environments).Result;
if (gpResult.IsCanceled)
{
return res;
@ -1718,7 +1717,7 @@ namespace OliviaAddInPro.Helper
/**
* Borrar una feature class de un dataset
*/
public static Respuesta<bool> DeleteFeatureClass(string gdbPath, string featureClassPath)
public static Respuesta<bool> DeleteFeatureClass(string gdbPath, string featureClassPath)
{
var res = new Respuesta<bool> { Value = false };
FeatureClass ftclss = GetFtClass(featureClassPath);
@ -1742,7 +1741,7 @@ namespace OliviaAddInPro.Helper
schemaBuilder.Delete(featureClassDescription);
// Execute the DDL
resp.Value = schemaBuilder.Build();
if(!resp.Value && schemaBuilder.ErrorMessages.Count>0)
if (!resp.Value && schemaBuilder.ErrorMessages.Count > 0)
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
return resp;
}
@ -1756,7 +1755,7 @@ namespace OliviaAddInPro.Helper
res.Value = true;
else
{
res.Error.Add(task.Result.Error.FirstOrDefault());
res.Error.Add(task.Result.Error.FirstOrDefault());
}
Free(gdb);
Free(ftclss);
@ -1766,12 +1765,12 @@ namespace OliviaAddInPro.Helper
/**
* Refresca la gdb después de añadir dataset y featureclass
*/
public static void Refresh(string gdbPath)
public static void Refresh(string gdbPath)
{
Item gdb=null;
Item gdb = null;
try
{
gdb = ItemFactory.Instance.Create(gdbPath);
gdb = ItemFactory.Instance.Create(gdbPath);
if (gdb == null)
return;
var contentItem = gdb;
@ -1796,8 +1795,30 @@ namespace OliviaAddInPro.Helper
}
catch
{
}
}
/**
* Abre en el mapa la capa seleccionada, con los parámetros seleccionados
*/
public static bool OpenLayer(string ftclasspath, string campValUniq, bool visible)
{
var mapView = MapView.Active;
int indexNumber = mapView.Map.Layers.Count;
string ftclassname = System.IO.Path.GetFileNameWithoutExtension(ftclasspath);
if (mapView != null)//Check if there is a map
{
System.Uri ftclass_uri = new System.Uri(ftclasspath); //creating uri for the ftclass
QueuedTask.Run(() =>
{
Layer layer = LayerFactory.Instance.CreateLayer(ftclass_uri, mapView.Map, indexNumber, ftclassname);
var selectedLayer = mapView.GetSelectedLayers()[0] as FeatureLayer;
//Do something with selected layer
selectedLayer.SetVisibility(visible);
});
}
return true;
}
}
}

View File

@ -125,10 +125,13 @@ namespace OliviaAddInPro.Model
auxi = auxi.Substring(0, indice);
}
auxl = indice - aux;
if (auxl <= 0)
return;
auxili = shapefile.Substring(aux, auxl);
ambitos = ambitos + auxili;
if (auxl > 0)
{
auxili = shapefile.Substring(aux, auxl);
ambitos = ambitos + auxili;
}
//concatena el timestamp
ambitos = ambitos + shapefile.Substring(aux);
}
}

View File

@ -146,11 +146,14 @@ namespace OliviaAddInPro.Model
auxi = auxi.Substring(0, indice);
}
auxl = indice - aux;
if (auxl <= 0)
return;
auxili = shapefile.Substring(aux, auxl);
carga = carga + auxili;
if (auxl > 0)
{
auxili = shapefile.Substring(aux, auxl);
carga = carga + auxili;
}
//concatena el timestamp
carga = carga + shapefile.Substring(aux);
}
}
}

View File

@ -377,9 +377,15 @@ namespace OliviaAddInPro.Services
*/
public Respuesta<string> ImportSecto(string GdbFileName)
{
/*var res = new Respuesta<string> { Value = string.Empty };
return res;*/
return Import(GdbFileName, 0);
var res = new Respuesta<string> { Value = string.Empty };
res = Import(GdbFileName, 0);
if (res.HasError)
return res;
//////////////////////////////////////////////////
//abre las capas, pintando los sectores
HelperGdb.CloseAllLayers();
return res;
}
/**
* Realiza las funciones de importación, modo 0 secto, modo 1 planif
@ -436,7 +442,10 @@ namespace OliviaAddInPro.Services
HelperGlobal.ponMsg(err_spatref +", se ha creado un nuevo dataset "+ datasetNameOut );
tratamiento = datasetNameOut;
}
string dataset = tratamiento;
//NO hace falta preguntar ni comprobar el ftclass porque pone el timestamp y el nombre es único
/*
/////////////////////////////////////////
//pregunta a ver si se quiere ese nombre u otro
bool replace = false;
@ -475,6 +484,8 @@ namespace OliviaAddInPro.Services
HelperGlobal.ponMsg(err_spatref);
}
}
*/
/////////////////////////////////////////
//todo ok, se pone a importar
string err_st=string.Empty;
@ -542,7 +553,7 @@ namespace OliviaAddInPro.Services
for (i = 0; i < NIMPORT; i++)
{
//mira a ver si hay que borrar para reemplazar
if (replace)
/*if (replace)
{
resp2 = HelperGdb.DeleteFeatureClass(GdbFileName, noms_gdb[i]);
if (!resp2.Value)
@ -552,7 +563,7 @@ namespace OliviaAddInPro.Services
err_st += " " + resp2.Error.First();
break;
}
}
}*/
resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]);
if (!resp2.Value)
{
@ -588,6 +599,23 @@ namespace OliviaAddInPro.Services
public Respuesta<string> ImportPlanif(string GdbFileName)
{
var res = new Respuesta<string> { Value = string.Empty };
res = Import(GdbFileName, 1);
if (res.HasError)
return res;
//abre las capas, pintando por sectores
/////////////////////////////////////////////////////
//la primera capa que se añade es la de ruta, se le quita la visualización porque lo que interesa
//de esa capa es poder acceder si fuera necesario a la tabla de atributos. shape + name_ruta_out
/////////////////////////////////////////////////////
//la siguiente es la de ruta2, se le quita la visualización porque lo que interesa
//de esa capa es poder acceder si fuera necesario a la tabla de atributos. shape + name_ruta2_out
/////////////////////////////////////////////////////
//se añade la capa de ruta_aux y se pinta por sectores - shape + name_ruta_out + name_aux
/////////////////////////////////////////////////////
//se añade la capa de ambitos original con la secto, y se pinta por sectores - shape
/////////////////////////////////////////////////////
//se añade la capa de la ruta a las instalaciones, comprueba si hay configurada coordenadas de la instalación - shape + name_inst_out
//se abre la capa de puntos de control y se pintan por el sector al que pertenecen - shape + name_control_out
return res;
}

View File

@ -152,14 +152,14 @@ namespace OliviaAddInPro.Services
OliviaGlob.progrDialog.Hide();
//muestra la ventana
OliviaGlob.ShowHidePane(true);
/*var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
var task = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(() =>
{
//borra los archivos que le toca borrar
BorraFiles();
});
task.Wait();*/
task.Wait();
//borra los archivos que le toca borrar
BorraFiles();
//BorraFiles();
}
/**