Restaura nombre de los campos a más de 10 caracteres cuando importa
parent
828eff60c1
commit
8de6d7682e
|
|
@ -562,7 +562,7 @@ namespace OliviaAddInPro.Helper
|
|||
return ftclss;
|
||||
}
|
||||
//devuelve el campo dado el nombre
|
||||
private static ArcGIS.Core.Data.Field GetFieldByNameSinc(FeatureClass ftClss, string fieldName)
|
||||
private static ArcGIS.Core.Data.Field GetFieldByNameSync(FeatureClass ftClss, string fieldName)
|
||||
{
|
||||
FeatureClassDefinition ftcldef = ftClss.GetDefinition();
|
||||
ReiniciaOutStr();
|
||||
|
|
@ -2387,5 +2387,33 @@ namespace OliviaAddInPro.Helper
|
|||
Free(ftcl);
|
||||
return tipo;
|
||||
}
|
||||
|
||||
public static bool RenameField(string fcname, string oldFieldName, string newFieldName, string newFieldAlias)
|
||||
{
|
||||
bool res = false;
|
||||
string[] args = { fcname, oldFieldName, newFieldName,newFieldAlias };
|
||||
// execute the tool
|
||||
try
|
||||
{
|
||||
var gpres = Geoprocessing.ExecuteToolAsync("management.AlterField", args);
|
||||
if (gpres.Result.IsFailed)
|
||||
{
|
||||
var gpResult = gpres.Result;
|
||||
string msg;
|
||||
if (gpResult.ErrorMessages != null)
|
||||
msg = gpResult.ErrorMessages.First().Text;
|
||||
else
|
||||
msg = "Errores al renombrar campo "+newFieldName;
|
||||
}
|
||||
else
|
||||
res= true; //ha ido bien
|
||||
return res;
|
||||
}
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,5 +144,20 @@ namespace OliviaAddInPro.Model
|
|||
ambitos = ambitos + shapefile.Substring(aux);
|
||||
|
||||
}
|
||||
/**
|
||||
* Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp
|
||||
*/
|
||||
public override string[] GetCamposRestaura()
|
||||
{
|
||||
string[] camps = {
|
||||
LimpiezaDef.Campos.consulta_entidad,
|
||||
LimpiezaDef.Campos.consulta_mecan,
|
||||
LimpiezaDef.Campos.consulta_observ,
|
||||
LimpiezaDef.Campos.consulta_anch_tip,
|
||||
LimpiezaDef.Campos.consulta_tipolo,
|
||||
/*LimpiezaDef.Campos.consulta_sector,
|
||||
LimpiezaDef.Campos.consulta_secuen */};
|
||||
return camps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,5 +155,21 @@ namespace OliviaAddInPro.Model
|
|||
//concatena el timestamp
|
||||
carga = carga + shapefile.Substring(aux);
|
||||
}
|
||||
|
||||
/**
|
||||
* Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp
|
||||
*/
|
||||
public override string[] GetCamposRestaura()
|
||||
{
|
||||
string[] camps = {
|
||||
RecogidaDef.campos_def.cons_id,
|
||||
RecogidaDef.campos_def.cons_nomrec,
|
||||
RecogidaDef.campos_def.cons_lateral ,
|
||||
RecogidaDef.campos_def.cons_fracc,
|
||||
RecogidaDef.campos_def.cons_capac,
|
||||
RecogidaDef.campos_def.cons_uds,
|
||||
RecogidaDef.campos_def.cons_kgrec };
|
||||
return camps;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,9 @@ using OliviaAddInPro.Helper;
|
|||
using OliviaAddInPro.Model.contract;
|
||||
using OliviaAddInPro.Services;
|
||||
using static OliviaAddInPro.Model.ComunDef;
|
||||
using ArcGIS.Core.CIM;
|
||||
using ArcGIS.Core.Data;
|
||||
using System.Collections.ObjectModel;
|
||||
|
||||
namespace OliviaAddInPro.Model
|
||||
{
|
||||
|
|
@ -191,5 +194,62 @@ namespace OliviaAddInPro.Model
|
|||
tratamiento = string.Empty;
|
||||
ambitos = string.Empty;
|
||||
}
|
||||
/**
|
||||
* Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp
|
||||
*/
|
||||
public virtual string[] GetCamposRestaura()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restaura el nombre original del campo si se ha truncado a 10 car al exportar a shp
|
||||
*/
|
||||
public Respuesta<bool> RestauraNomCampos(string nombFtClass)
|
||||
{
|
||||
int LENGTHCAMPSHP = 10;
|
||||
Respuesta<bool> resp = new Respuesta<bool> { Value = false };
|
||||
FeatureClass fc = HelperGdb.GetFtClassSync(nombFtClass);
|
||||
if (fc == null)
|
||||
return resp;
|
||||
////////////////////////////////////////////////////////
|
||||
string[] camps = GetCamposRestaura();
|
||||
|
||||
ObservableCollection<string> fields = HelperGdb.GetFieldsSync(fc);
|
||||
HelperGdb.Free(fc);
|
||||
if (fields == null)
|
||||
return resp;
|
||||
try
|
||||
{
|
||||
int i = 0;
|
||||
int indx;
|
||||
string campTrunc = string.Empty;
|
||||
for (i = 0; i < camps.Length; i++)
|
||||
{
|
||||
if (camps[i].Length <= LENGTHCAMPSHP)
|
||||
continue;
|
||||
campTrunc = camps[i].Substring(0, LENGTHCAMPSHP);
|
||||
//si tiene más de 10 caracteres, lo ha truncado al exportar
|
||||
//busca el nombre actual del campo en la fc
|
||||
indx = fields.IndexOf(campTrunc);
|
||||
if (indx < 0)
|
||||
break;
|
||||
if (!HelperGdb.RenameField(nombFtClass, campTrunc, camps[i],camps[i]))
|
||||
break;
|
||||
}
|
||||
if (i < camps.Length)
|
||||
{
|
||||
resp.Error.Add("Error en el campo " + camps[i]);
|
||||
}
|
||||
else
|
||||
resp.Value = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
return resp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -491,15 +491,7 @@ namespace OliviaAddInPro.Services
|
|||
string tratamiento = string.Empty;
|
||||
string ambitos = string.Empty;
|
||||
com.decode_gdb(shapefile, out tratamiento, out ambitos); //supsuestamente distingue si es limpieza o recogida
|
||||
/*
|
||||
if (prefijo == "T")
|
||||
{
|
||||
com.decode_gdb(shapefile, out tratamiento, out ambitos);
|
||||
}
|
||||
else if (prefijo == "F")
|
||||
{
|
||||
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));
|
||||
|
|
@ -529,48 +521,6 @@ namespace OliviaAddInPro.Services
|
|||
}
|
||||
string dataset = tratamiento;
|
||||
|
||||
/*
|
||||
* //YA 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;
|
||||
string dataset = tratamiento;
|
||||
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.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))
|
||||
{
|
||||
//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;
|
||||
|
|
@ -637,18 +587,6 @@ namespace OliviaAddInPro.Services
|
|||
//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(dir_shp + "\\" + noms_shp[i] + HelperGdb.SHP_EXT, GdbFileName + "\\" + dataset, noms_gdb[i]);
|
||||
if (!resp2.Value)
|
||||
{
|
||||
|
|
@ -657,13 +595,23 @@ namespace OliviaAddInPro.Services
|
|||
err_st += " " + resp2.Error.First();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (i < NIMPORT)
|
||||
{
|
||||
res.Error.Add("Errores en la importación: "+err_st);
|
||||
return res;
|
||||
}
|
||||
//cambia el nombre de los campos que había truncado a 10 caracteres al exportar a shp
|
||||
//solo para la capa original
|
||||
resp2 = com.RestauraNomCampos(GdbFileName + "\\" + dataset + "\\" + noms_gdb[0]);
|
||||
if (!resp2.Value)
|
||||
{
|
||||
err_st = "Error al renombrar campos " + noms_gdb[i];
|
||||
if (resp2.HasError)
|
||||
err_st += " " + resp2.Error.First();
|
||||
res.Error.Add("Errores en la importación: " + err_st);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
@ -677,7 +625,6 @@ namespace OliviaAddInPro.Services
|
|||
res.Value = path_import;
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cierra del mapa las capas de trabajo después de la exportación
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -16,105 +16,8 @@ namespace OliviaAddInPro.Services
|
|||
{
|
||||
Application.Current.Dispatcher.BeginInvoke(new Action<Respuesta<TiposEjecucion>, TratamientoComun>((p, v) => finEjecuta2(p, v)),res,inst);
|
||||
|
||||
//borra los archivos que le toca borrar
|
||||
//BorraFiles();
|
||||
}
|
||||
public void finEjecuta2_old(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
|
||||
{
|
||||
|
||||
|
||||
//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();
|
||||
mal = true;
|
||||
}
|
||||
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;
|
||||
mal = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = Resource1.String_exito;
|
||||
//pone modo config2
|
||||
OliviaGlob.AddFlagTipEjec(TiposEjecucion.Config2);
|
||||
//actualiza la capa de la que tiene que leer ahora para planificar
|
||||
inst.CapaElems = resp.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
public void finEjecuta2(Respuesta<TiposEjecucion> res, TratamientoComun inst)
|
||||
{
|
||||
String msg = string.Empty;
|
||||
|
|
|
|||
Loading…
Reference in New Issue