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

@ -1526,7 +1526,7 @@ namespace OliviaAddInPro.Helper
/** /**
* 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_, 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 //Display the filter in an Open Item dialog
SaveItemDialog dlg = new SaveItemDialog SaveItemDialog dlg = new SaveItemDialog
@ -1587,14 +1587,14 @@ namespace OliviaAddInPro.Helper
try try
{ {
gdb = GetGdb(gdbPath).Result; gdb = GetGdb(gdbPath).Result;
if(gdb==null) if (gdb == null)
{ {
res.Value = 1; res.Value = 1;
res.Error.Add("Error al abrir la gdb " + gdbPath); res.Error.Add("Error al abrir la gdb " + gdbPath);
return res; return res;
} }
//comprueba si extiste ya el dataset //comprueba si extiste ya el dataset
if(CheckDataset(gdb,datasetName).Result) if (CheckDataset(gdb, datasetName).Result)
{ {
//comprueba si tiene la misma referencia espacial //comprueba si tiene la misma referencia espacial
featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName); featureDatasetDefinition = gdb.GetDefinition<FeatureDatasetDefinition>(datasetName);
@ -1637,7 +1637,7 @@ namespace OliviaAddInPro.Helper
} }
})); }));
task.Wait(); task.Wait();
if(task.Result.Value)//ha ido bien if (task.Result.Value)//ha ido bien
{ {
if (string.IsNullOrEmpty(datasetNameOut)) if (string.IsNullOrEmpty(datasetNameOut))
res.Value = 0; res.Value = 0;
@ -1656,7 +1656,7 @@ namespace OliviaAddInPro.Helper
catch (Exception ex) catch (Exception ex)
{ {
res.Value = 1; 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; return res;
} }
finally finally
@ -1673,7 +1673,7 @@ namespace OliviaAddInPro.Helper
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 }; var res = new Respuesta<bool> { Value = false };
string[] args = { nom_shp, Gdb_dataset, namefc}; string[] args = { nom_shp, Gdb_dataset, namefc };
// execute the tool // execute the tool
FeatureClass fc = GetFtClassFromShp(nom_shp).Result; FeatureClass fc = GetFtClassFromShp(nom_shp).Result;
if (fc == null) if (fc == null)
@ -1683,8 +1683,7 @@ namespace OliviaAddInPro.Helper
{ {
ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc); ArcGIS.Core.Geometry.SpatialReference spatref = GetSpatRef(fc);
var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: spatref); var environments = Geoprocessing.MakeEnvironmentArray(outputCoordinateSystem: spatref);
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass_conversion", args, environments).Result;
environments, null, null).Result;
if (gpResult.IsCanceled) if (gpResult.IsCanceled)
{ {
return res; return res;
@ -1742,7 +1741,7 @@ namespace OliviaAddInPro.Helper
schemaBuilder.Delete(featureClassDescription); schemaBuilder.Delete(featureClassDescription);
// Execute the DDL // Execute the DDL
resp.Value = schemaBuilder.Build(); resp.Value = schemaBuilder.Build();
if(!resp.Value && schemaBuilder.ErrorMessages.Count>0) if (!resp.Value && schemaBuilder.ErrorMessages.Count > 0)
resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault()); resp.Error.Add(schemaBuilder.ErrorMessages.FirstOrDefault());
return resp; return resp;
} }
@ -1768,7 +1767,7 @@ namespace OliviaAddInPro.Helper
*/ */
public static void Refresh(string gdbPath) public static void Refresh(string gdbPath)
{ {
Item gdb=null; Item gdb = null;
try try
{ {
gdb = ItemFactory.Instance.Create(gdbPath); gdb = ItemFactory.Instance.Create(gdbPath);
@ -1799,5 +1798,27 @@ namespace OliviaAddInPro.Helper
} }
} }
/**
* 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); auxi = auxi.Substring(0, indice);
} }
auxl = indice - aux; auxl = indice - aux;
if (auxl <= 0) if (auxl > 0)
return; {
auxili = shapefile.Substring(aux, auxl); auxili = shapefile.Substring(aux, auxl);
ambitos = ambitos + auxili; 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); auxi = auxi.Substring(0, indice);
} }
auxl = indice - aux; auxl = indice - aux;
if (auxl <= 0) if (auxl > 0)
return; {
auxili = shapefile.Substring(aux, auxl); auxili = shapefile.Substring(aux, auxl);
carga = carga + auxili; 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) public Respuesta<string> ImportSecto(string GdbFileName)
{ {
/*var res = new Respuesta<string> { Value = string.Empty }; var res = new Respuesta<string> { Value = string.Empty };
return res;*/ res = Import(GdbFileName, 0);
return 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 * 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 ); HelperGlobal.ponMsg(err_spatref +", se ha creado un nuevo dataset "+ datasetNameOut );
tratamiento = 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 //pregunta a ver si se quiere ese nombre u otro
bool replace = false; bool replace = false;
@ -475,6 +484,8 @@ namespace OliviaAddInPro.Services
HelperGlobal.ponMsg(err_spatref); HelperGlobal.ponMsg(err_spatref);
} }
} }
*/
///////////////////////////////////////// /////////////////////////////////////////
//todo ok, se pone a importar //todo ok, se pone a importar
string err_st=string.Empty; string err_st=string.Empty;
@ -542,7 +553,7 @@ namespace OliviaAddInPro.Services
for (i = 0; i < NIMPORT; i++) for (i = 0; i < NIMPORT; i++)
{ {
//mira a ver si hay que borrar para reemplazar //mira a ver si hay que borrar para reemplazar
if (replace) /*if (replace)
{ {
resp2 = HelperGdb.DeleteFeatureClass(GdbFileName, noms_gdb[i]); resp2 = HelperGdb.DeleteFeatureClass(GdbFileName, noms_gdb[i]);
if (!resp2.Value) if (!resp2.Value)
@ -552,7 +563,7 @@ namespace OliviaAddInPro.Services
err_st += " " + resp2.Error.First(); err_st += " " + resp2.Error.First();
break; break;
} }
} }*/
resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]); resp2 = HelperGdb.ImportShp(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]);
if (!resp2.Value) if (!resp2.Value)
{ {
@ -588,6 +599,23 @@ namespace OliviaAddInPro.Services
public Respuesta<string> ImportPlanif(string GdbFileName) public Respuesta<string> ImportPlanif(string GdbFileName)
{ {
var res = new Respuesta<string> { Value = string.Empty }; 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; return res;
} }

View File

@ -152,14 +152,14 @@ namespace OliviaAddInPro.Services
OliviaGlob.progrDialog.Hide(); OliviaGlob.progrDialog.Hide();
//muestra la ventana //muestra la ventana
OliviaGlob.ShowHidePane(true); 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 //borra los archivos que le toca borrar
BorraFiles(); BorraFiles();
}); });
task.Wait();*/ task.Wait();
//borra los archivos que le toca borrar //borra los archivos que le toca borrar
BorraFiles(); //BorraFiles();
} }
/** /**