Importacion estable
parent
3885fa83b7
commit
b0e389aada
|
|
@ -18,6 +18,8 @@ using ArcGIS.Desktop.Core.Geoprocessing;
|
||||||
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
||||||
using ArcGIS.Desktop.Editing;
|
using ArcGIS.Desktop.Editing;
|
||||||
using OliviaAddInPro.Model;
|
using OliviaAddInPro.Model;
|
||||||
|
using System.IO;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace OliviaAddInPro.Helper
|
namespace OliviaAddInPro.Helper
|
||||||
{
|
{
|
||||||
|
|
@ -599,91 +601,102 @@ namespace OliviaAddInPro.Helper
|
||||||
Free(fc);
|
Free(fc);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
static public bool RenameSHP(string dir, string path, string nameNew)
|
||||||
|
{
|
||||||
|
var extensions = new[] { "cpg", "dbf", "prj", "sbn", "sbx", "shp", "shp.xml", "shx" };
|
||||||
|
string old_ext = System.IO.Path.GetExtension(path);
|
||||||
|
|
||||||
public static async Task<bool> ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, ProgressDialog progrDialog = null)
|
string name = System.IO.Path.GetFileName(path);
|
||||||
|
if (!string.IsNullOrEmpty(old_ext))
|
||||||
|
name.Replace(old_ext,"");
|
||||||
|
string _ex =System.IO.Path.GetExtension(nameNew);
|
||||||
|
string nn = nameNew;
|
||||||
|
if (!string.IsNullOrEmpty(_ex))
|
||||||
|
nn.Replace(_ex, "");
|
||||||
|
var res = true;
|
||||||
|
foreach(var ex in extensions)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var po = string.Format("{0}{1}.{2}", dir, name, ex);
|
||||||
|
var pn = string.Format("{0}{1}.{2}", dir, nn, ex);
|
||||||
|
|
||||||
|
if (!File.Exists(po))
|
||||||
|
res = false;//no existe
|
||||||
|
if (!File.Exists(pn))
|
||||||
|
File.Delete(pn);
|
||||||
|
File.Move(po,pn );
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
res = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<bool> ExportShp(string pathLayerIn, SpatialQueryFilter filter, string nameShp, string outpath, ProgressorSource progrDialog = null)
|
||||||
{
|
{
|
||||||
if (!System.IO.Directory.Exists(outpath))
|
if (!System.IO.Directory.Exists(outpath))
|
||||||
System.IO.Directory.CreateDirectory(outpath);
|
System.IO.Directory.CreateDirectory(outpath);
|
||||||
ReiniciaOutStr();
|
ReiniciaOutStr();
|
||||||
string dirPath;
|
System.Threading.CancellationTokenSource _cts= new System.Threading.CancellationTokenSource();
|
||||||
string fclassName = System.IO.Path.GetFileName(pathLayerIn);
|
var fin = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<string>)(() =>
|
||||||
IReadOnlyList<string> parameters = null;
|
|
||||||
IReadOnlyList<string> parameters2 = null;
|
|
||||||
|
|
||||||
FeatureClass featureClass = null;
|
|
||||||
var fin = ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run((Func<bool>)(() =>
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(fclassName))
|
var progSrc = new CancelableProgressorSource();
|
||||||
return false;
|
string[] args = { pathLayerIn, outpath };
|
||||||
|
// execute the tool
|
||||||
|
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", args,
|
||||||
|
null, _cts.Token,
|
||||||
|
|
||||||
try
|
(event_name, o) => // implement delegate and handle events
|
||||||
{
|
{
|
||||||
if (System.IO.Path.GetExtension(pathLayerIn).Equals(".shp"))
|
switch (event_name)
|
||||||
{
|
{
|
||||||
dirPath = System.IO.Path.GetDirectoryName(pathLayerIn);
|
case "OnValidate": // stop execute if any warnings
|
||||||
//es un shape de entrada
|
//if ((o as IGPMessage[]).Any(it => it.Type == GPMessageType.Warning))
|
||||||
FileSystemConnectionPath fileConnection = new FileSystemConnectionPath(new Uri(dirPath), FileSystemDatastoreType.Shapefile);
|
//_cts.Cancel();
|
||||||
using (FileSystemDatastore shapefile = new FileSystemDatastore(fileConnection))
|
break;
|
||||||
{
|
|
||||||
featureClass = shapefile.OpenDataset<FeatureClass>(fclassName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
dirPath = GetPathGdb(pathLayerIn);
|
|
||||||
//es una feature class de una gdb
|
|
||||||
using (Geodatabase fileGeodatabase = new Geodatabase(new FileGeodatabaseConnectionPath(new Uri(dirPath))))
|
|
||||||
{
|
|
||||||
featureClass = fileGeodatabase.OpenDataset<FeatureClass>(fclassName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (featureClass == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
//Selection selFeatures = featureClass.Select(filter, SelectionType.ObjectID, SelectionOption.Normal);
|
case "OnProgressMessage":
|
||||||
// make a value array of strings to be passed to ExecuteToolAsync
|
{
|
||||||
parameters = Geoprocessing.MakeValueArray(pathLayerIn, outpath);//, nameShp);
|
string msg = string.Format("{0}: {1}", new object[] { event_name, (string)o });
|
||||||
var aux = pathLayerIn.Split('\\');
|
progrDialog.Message = (string)o;
|
||||||
parameters2 = Geoprocessing.MakeValueArray(outpath + aux[aux.Length - 1]+".shp", outpath, nameShp);
|
Debug.WriteLine(msg);
|
||||||
|
//System.Windows.MessageBox.Show(msg);
|
||||||
|
//_cts.Cancel();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
case "OnProgressPos":
|
||||||
catch
|
{
|
||||||
{
|
string msg2 = string.Format("{0}: {1} %", new object[] { event_name, (int)o });
|
||||||
OutStr = "Ha ocurrido un error al convertir a shape";
|
Debug.WriteLine(msg2);
|
||||||
return false;
|
// if ((int)o < 0)
|
||||||
}
|
//System.Windows.MessageBox.Show(msg2);
|
||||||
return true;
|
//_cts.Cancel();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).Result;
|
||||||
|
|
||||||
|
//renombrado de ficheros:
|
||||||
|
if (!RenameSHP(outpath, pathLayerIn, nameShp))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return gpResult.ReturnValue;
|
||||||
}));
|
}));
|
||||||
|
|
||||||
fin.Wait();
|
fin.Wait();
|
||||||
if(!fin.Result)// || parameters==null)
|
if (string.IsNullOrEmpty(fin.Result))
|
||||||
{
|
{
|
||||||
OutStr = "Ha ocurrido un error al convertir a shape";
|
OutStr = "Ha ocurrido un error en la herramienta de GeoProcesamiento";
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
var progSrc = new CancelableProgressorSource(progrDialog);
|
|
||||||
|
|
||||||
|
|
||||||
// execute the tool
|
|
||||||
IGPResult gpResult = Geoprocessing.ExecuteToolAsync("FeatureClassToShapefile_conversion", parameters,
|
|
||||||
null, progSrc.Progressor, GPExecuteToolFlags.GPThread).Result;
|
|
||||||
|
|
||||||
//renombrar shp
|
|
||||||
//param2.Add(nameShp);
|
|
||||||
IGPResult gpResult2 = Geoprocessing.ExecuteToolAsync("FeatureClassToFeatureClass", parameters2,
|
|
||||||
null, progSrc.Progressor, GPExecuteToolFlags.GPThread).Result;
|
|
||||||
|
|
||||||
|
|
||||||
Free(featureClass);
|
|
||||||
if (string.IsNullOrEmpty(gpResult.ReturnValue))
|
|
||||||
{
|
|
||||||
OutStr = "Ha ocurrido un error en la herramienta de GeoProcesamiento: " + gpResult.ErrorMessages;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OutStr = "Ok: " + gpResult.ReturnValue;
|
OutStr = "Ok: " + fin.Result;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
using ArcGIS.Desktop.Internal.Framework.Controls;
|
using ArcGIS.Desktop.Internal.Framework.Controls;
|
||||||
using ArcGIS.Desktop.Framework.Dialogs;
|
using ArcGIS.Desktop.Framework.Dialogs;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace OliviaAddInPro.Helper
|
namespace OliviaAddInPro.Helper
|
||||||
{
|
{
|
||||||
|
|
@ -50,5 +51,33 @@ namespace OliviaAddInPro.Helper
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void create_folder(string dir)
|
||||||
|
{
|
||||||
|
string[] pathParts = dir.Split('\\');
|
||||||
|
string path = "";
|
||||||
|
foreach (var d in pathParts)
|
||||||
|
{
|
||||||
|
if(string.IsNullOrEmpty(path))
|
||||||
|
path = d;
|
||||||
|
|
||||||
|
else
|
||||||
|
path = path + '\\'+d;
|
||||||
|
|
||||||
|
if (!Directory.Exists(path))
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(path);
|
||||||
|
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ using System.Threading.Tasks;
|
||||||
using OliviaAddInPro.Services;
|
using OliviaAddInPro.Services;
|
||||||
using ArcGIS.Core.Geometry;
|
using ArcGIS.Core.Geometry;
|
||||||
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
||||||
|
using OliviaAddInPro.Helper;
|
||||||
|
|
||||||
namespace OliviaAddInPro.Model
|
namespace OliviaAddInPro.Model
|
||||||
{
|
{
|
||||||
|
|
@ -132,6 +133,9 @@ namespace OliviaAddInPro.Model
|
||||||
Paths.PathTemp = c.path_temp;
|
Paths.PathTemp = c.path_temp;
|
||||||
c.PathCartela = c.PathCartela;
|
c.PathCartela = c.PathCartela;
|
||||||
|
|
||||||
|
HelperGlobal.create_folder(Paths.DirData);
|
||||||
|
HelperGlobal.create_folder(Paths.PathTemp);
|
||||||
|
|
||||||
Paths.PathGdbGen = c.PathGdbGen;
|
Paths.PathGdbGen = c.PathGdbGen;
|
||||||
Paths.PathGdbNw = c.red_carreteras;
|
Paths.PathGdbNw = c.red_carreteras;
|
||||||
Paths.PathSimbVSM = c.PathSimbVSM;
|
Paths.PathSimbVSM = c.PathSimbVSM;
|
||||||
|
|
|
||||||
|
|
@ -37,60 +37,71 @@ namespace OliviaAddInPro.Services
|
||||||
*/
|
*/
|
||||||
public bool ComienzaEjec(ModosEjec modo)
|
public bool ComienzaEjec(ModosEjec modo)
|
||||||
{
|
{
|
||||||
bool fue_mal = false;
|
using (OliviaGlob.progrDialog = new ProgressDialog("Exportando Datos", "Cancelar", 100, true))
|
||||||
|
|
||||||
//esconde el pane
|
|
||||||
OliviaGlob.ShowHidePane(false);
|
|
||||||
ErrStr = string.Empty;
|
|
||||||
|
|
||||||
//Cuenta las filas que cumplen la consulta
|
|
||||||
int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs);
|
|
||||||
if(nelems<=0)
|
|
||||||
{
|
{
|
||||||
ErrStr = "No existen ámbitos que cumplan las condiciones introducidas para la exportación " + com.ConsultaAmbs;
|
var status = new ProgressorSource(OliviaGlob.progrDialog);
|
||||||
fue_mal = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Obtiene la geometría que envuelve a los ámbitos
|
OliviaGlob.progrDialog.Show();
|
||||||
Geometry geom_export = null;
|
bool fue_mal = false;
|
||||||
if (!fue_mal)
|
status.Message = "Exportando Datos";
|
||||||
{
|
status.Value = 0;
|
||||||
geom_export = GetGeomAmbitsExport();
|
status.Status = "Exportando Datos";
|
||||||
if (geom_export == null || geom_export.IsEmpty)
|
status.Max = 100;
|
||||||
|
//esconde el pane
|
||||||
|
OliviaGlob.ShowHidePane(false);
|
||||||
|
ErrStr = string.Empty;
|
||||||
|
|
||||||
|
//Cuenta las filas que cumplen la consulta
|
||||||
|
int nelems = HelperGdb.GetNumElems(com.CapaElems, com.ConsultaAmbs);
|
||||||
|
if (nelems <= 0)
|
||||||
{
|
{
|
||||||
ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + ErrStr;
|
ErrStr = "No existen ámbitos que cumplan las condiciones introducidas para la exportación " + com.ConsultaAmbs;
|
||||||
fue_mal = true;
|
fue_mal = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (geom_export == null || geom_export.IsEmpty)
|
//Obtiene la geometría que envuelve a los ámbitos
|
||||||
|
Geometry geom_export = null;
|
||||||
|
if (!fue_mal)
|
||||||
{
|
{
|
||||||
fue_mal = true;
|
geom_export = GetGeomAmbitsExport();
|
||||||
}
|
if (geom_export == null || geom_export.IsEmpty)
|
||||||
}
|
{
|
||||||
|
ErrStr = "No se ha podido generar geometría de los ámbitos" + com.ConsultaAmbs + ErrStr;
|
||||||
|
fue_mal = true;
|
||||||
|
}
|
||||||
|
|
||||||
//crea el filtro de exportación
|
if (geom_export == null || geom_export.IsEmpty)
|
||||||
if (!fue_mal)
|
{
|
||||||
{
|
fue_mal = true;
|
||||||
//mira spatialreference de los datos de entrada
|
}
|
||||||
spatRef = geom_export.SpatialReference;
|
}
|
||||||
filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export);
|
|
||||||
if (filtroEspacial == null)
|
//crea el filtro de exportación
|
||||||
|
if (!fue_mal)
|
||||||
{
|
{
|
||||||
fue_mal = true;
|
//mira spatialreference de los datos de entrada
|
||||||
|
spatRef = geom_export.SpatialReference;
|
||||||
|
filtroEspacial = CreaFiltro(com.ConsultaAmbs, geom_export);
|
||||||
|
if (filtroEspacial == null)
|
||||||
|
{
|
||||||
|
fue_mal = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fue_mal)
|
||||||
|
{
|
||||||
|
Ejecuta(modo, status);
|
||||||
|
OliviaGlob.progrDialog.Hide();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
OliviaGlob.progrDialog.Hide();
|
||||||
|
//fue mal
|
||||||
|
//muestra pane
|
||||||
|
OliviaGlob.ShowHidePane(true);
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!fue_mal)
|
|
||||||
{
|
|
||||||
Ejecuta(modo);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//fue mal
|
|
||||||
//muestra pane
|
|
||||||
OliviaGlob.ShowHidePane(true);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -192,14 +203,13 @@ namespace OliviaAddInPro.Services
|
||||||
/**
|
/**
|
||||||
* Exporta y lanza proceso y ventana de proceso
|
* Exporta y lanza proceso y ventana de proceso
|
||||||
*/
|
*/
|
||||||
public void Ejecuta(ModosEjec modo)
|
public void Ejecuta(ModosEjec modo, ProgressorSource dlgProcess)
|
||||||
{
|
{
|
||||||
//lanza ventana de progreso
|
//lanza ventana de progreso
|
||||||
OliviaGlob.progrDialog = new ProgressDialog("Exportando Datos", "Cancelar", 100);
|
|
||||||
OliviaGlob.progrDialog.Show();
|
|
||||||
|
|
||||||
//exporta los datos de entrada
|
//exporta los datos de entrada
|
||||||
bool res=HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, OliviaGlob.progrDialog).Result;
|
bool res=HelperGdb.ExportShp(com.CapaElems, filtroEspacial, com.NombreShpExport, OliviaGlob.Paths.DirData, dlgProcess).Result;
|
||||||
if(!res)
|
if(!res)
|
||||||
{
|
{
|
||||||
string msg = HelperGdb.OutStr;
|
string msg = HelperGdb.OutStr;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue