250 lines
8.5 KiB
C#
250 lines
8.5 KiB
C#
using ArcGIS.Core.Data;
|
|
using ArcGIS.Core.Geometry;
|
|
using ArcGIS.Core.Internal.CIM;
|
|
using ArcGIS.Desktop.Framework.Threading.Tasks;
|
|
using OliviaAddInPro.Helper;
|
|
using OliviaAddInPro.Model;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using static OliviaAddInPro.Model.ComunDef;
|
|
|
|
namespace OliviaAddInPro.Services
|
|
{
|
|
public class LimpiezaServ : EjecServ
|
|
{
|
|
private Limpieza limp;
|
|
|
|
public LimpiezaServ(Limpieza _limp)
|
|
{
|
|
limp = _limp;
|
|
}
|
|
/**
|
|
* Acciones para comenzar ejecución
|
|
* Modo 0, sectorizar
|
|
* Modo 1, planificar
|
|
*/
|
|
public TareaRes Sectoriza(CancelableProgressorSource cps)
|
|
{
|
|
var res = new TareaRes()
|
|
{
|
|
Errores = false,
|
|
data = null,
|
|
msg = ""
|
|
};
|
|
|
|
com = (TratamientoComun)limp;
|
|
string nombFileAmbs = string.Empty;
|
|
cps.Status = "Preparando filtro para la exportacion";
|
|
//Prepara consulta
|
|
ErrStr = string.Empty;
|
|
if (!PreparaConsulta(out nombFileAmbs))
|
|
{
|
|
res.msg= "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs;
|
|
res.Errores = true;
|
|
return res;
|
|
}
|
|
cps.Value = 10;
|
|
|
|
//Prepara nombre
|
|
string fechaHora = string.Empty;
|
|
//se consigue el tiempo en este instante para añadirlo a los nombres de los archivos de salida (shapefiles)
|
|
fechaHora = DateTime.Now.ToString("yyyyMMdd_Hmmss");
|
|
//Pone nombre al shape en función de los ámbitos, el tratamiento, y los polígonos + timestamp
|
|
limp.NombreShpExport = prefNameExport + "T" + limp.TipoTto.ToString("00") + nombFileAmbs + DameStrPoligs() + "_" + fechaHora + extShp;
|
|
|
|
string msg = "";
|
|
//comienza ejecucion
|
|
if(!ComienzaEjec(ModosEjec.Sectoriza, cps, out msg))
|
|
{
|
|
res.Errores = true;
|
|
res.msg = msg;
|
|
return res;
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
public bool PreparaConsulta(out string nombFileAmbs)
|
|
{
|
|
nombFileAmbs = string.Empty;
|
|
limp.ConsultaAmbs = DameAmbsConsulta(out nombFileAmbs);
|
|
if (string.IsNullOrEmpty(limp.ConsultaAmbs))
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public TareaRes Planifica(CancelableProgressorSource cps)
|
|
{
|
|
TareaRes res = new TareaRes()
|
|
{
|
|
Errores = false,
|
|
msg = "",
|
|
data = null
|
|
};
|
|
//se asegura que tiene todo para planif
|
|
//ErrStr = string.Empty;
|
|
if (!CompruebaPlanif())
|
|
{
|
|
res.msg = "En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, necesarias para planificar";
|
|
res.Errores = true;
|
|
return res;
|
|
}
|
|
//Prepara consulta
|
|
string nombFileAmbs = string.Empty;
|
|
//Prepara consulta
|
|
if (!PreparaConsulta(out nombFileAmbs))
|
|
{
|
|
res.msg = "No se ha seleccionado una consulta válida" + limp.ConsultaAmbs;
|
|
res.Errores = true;
|
|
return res;
|
|
}
|
|
|
|
return res;
|
|
}
|
|
|
|
public string DameAmbsConsulta(out string ambs_file)
|
|
{
|
|
string consulta, orstr;
|
|
|
|
consulta = string.Empty;
|
|
ambs_file = "";
|
|
orstr = null;
|
|
var n = limp.AmbitosSel.Length;
|
|
|
|
for (int i = 0; i < n; i++)
|
|
{
|
|
if (limp.AmbitosSel[i])
|
|
{
|
|
consulta = consulta + orstr + "(" + LimpiezaDef.filtro_str[i] + ")";
|
|
ambs_file = ambs_file + i.ToString("00");
|
|
if (orstr == null)
|
|
orstr = " OR ";
|
|
}
|
|
}
|
|
ambs_file = "_A" + ambs_file;
|
|
if (consulta == "()")
|
|
consulta = "";
|
|
|
|
return consulta;
|
|
}
|
|
|
|
/**
|
|
* Comprueba lo necesario para ver si hay campos para la planificación
|
|
*/
|
|
public bool CompruebaPlanif()
|
|
{
|
|
|
|
//si ha importado no hace falta que compruebe, seguro que las tiene
|
|
if (OliviaGlob.IsConfig2())
|
|
return true;
|
|
//no ha importado, comprueba capa
|
|
if (ComprCamposPlanif(limp.CapaElems))
|
|
return true;
|
|
|
|
return false;
|
|
/*
|
|
string path = null;
|
|
if (!HelperGlobal.ponMsg("En la capa de ámbitos seleccionada no se encuentran columnas de SECTOR y/o SECUENCIA, " +
|
|
"necesarias para planificar. ¿Desea utilizar la sectorización de otra capa?",MessageBoxImage.Question,"OLIVIA",
|
|
MessageBoxButton.YesNo))
|
|
return false;
|
|
|
|
//saca diálogo para elegir capa
|
|
path = HelperGdb.OpenFileDialog(HelperGdb.TiposOpenFileDlg.OpenFtrClassLine | HelperGdb.TiposOpenFileDlg.OpenFtrClassPoint);
|
|
if (string.IsNullOrEmpty(path))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//comprueba que en la nueva capa haya columnas de planif
|
|
if (!ComprCamposPlanif(path))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//almacena la info de secto auxiliar
|
|
limp.CapaAuxPlanif = path;
|
|
return true;*/
|
|
|
|
}
|
|
|
|
/*
|
|
* Lee la capa que se ha seleccionzdo de limpieza y se comprueba que contiene los campos necesarios
|
|
*/
|
|
public bool CompruebaCamposLimp(string pathCapa)
|
|
{
|
|
int NCAMPS = 5;
|
|
string[] camps;
|
|
camps = new string[NCAMPS];
|
|
camps[0] = LimpiezaDef.Campos.consulta_entidad;
|
|
camps[1] = LimpiezaDef.Campos.consulta_mecan;
|
|
camps[2] = LimpiezaDef.Campos.consulta_observ;
|
|
camps[3] = LimpiezaDef.Campos.consulta_anch_tip;
|
|
camps[4] = LimpiezaDef.Campos.consulta_tipolo;
|
|
return CompruebaCampos(pathCapa, camps)==0;
|
|
}
|
|
/**
|
|
* Lee la gdb y devuelve el array de ámbitos en función de si hay en la gdb o no
|
|
*/
|
|
public bool[] BuscAmbGdb(string pathCapa)
|
|
{
|
|
string consulta;
|
|
int numero_lin;
|
|
bool[] amb_gdb = new bool[(int)LimpiezaDef.AmbitsTra.AmbN];//se inician a false
|
|
string ftclass;
|
|
|
|
//mira a ver si hay ejes de calle
|
|
ftclass = LimpiezaDef.ftclass[(int)LimpiezaDef.AmbitsTra.AmbEjeCalle];
|
|
consulta = LimpiezaDef.filtro_str[(int)LimpiezaDef.AmbitsTra.AmbEjeCalle];
|
|
numero_lin = HelperGdb.GetNumElems(OliviaGlob.Paths.PathGdbNw, ftclass, consulta);
|
|
if (numero_lin > 0)
|
|
{
|
|
amb_gdb[(int)LimpiezaDef.AmbitsTra.AmbEjeCalle] = true;
|
|
}
|
|
//mira a ver si hay el resto de capas y tienen entidades
|
|
for (int i = (int)LimpiezaDef.AmbitsTra.AmbBordLibreMec; i < (int)LimpiezaDef.AmbitsTra.AmbN; i++)
|
|
{
|
|
consulta = LimpiezaDef.filtro_str[i];
|
|
numero_lin = HelperGdb.GetNumElems(pathCapa, consulta);
|
|
|
|
if (numero_lin > 0)
|
|
{
|
|
amb_gdb[i] = true;
|
|
}
|
|
}
|
|
|
|
return amb_gdb;
|
|
}
|
|
/**Devuelve el array de los ámbitos comunes y no comunes de las opciones de un tratamiento tto
|
|
* Es un array de longitud el número de ámbitos totales, con true en las posiciones en los que el ámbito sea común o
|
|
* no común en las opciones
|
|
*/
|
|
public bool[] DameAmbTto(int tto)
|
|
{
|
|
int i;
|
|
bool sig;
|
|
bool[] amb_com = new bool[(int)LimpiezaDef.AmbitsTra.AmbN];
|
|
|
|
for (int j = 0; j < (int)LimpiezaDef.AmbitsTra.AmbN; j++)
|
|
{
|
|
sig = false;
|
|
for (i = 0; i < LimpiezaDef.ambs_val[tto].n_ops && !sig; i++)
|
|
{
|
|
if (LimpiezaDef.ambs_val[tto].ambs_ops[i].ambs[j]) //con que encuentre uno true lo pone y pasa al siguiente
|
|
{
|
|
amb_com[j] = sig = true;
|
|
}
|
|
}
|
|
}
|
|
return amb_com;
|
|
}
|
|
}
|
|
}
|