Exemple #1
0
        private void FrmSIGPIPrincipal_Load(object sender, EventArgs e)
        {
            lblTitulo.Text = "SISTEMA DE INFORMACION GEOGRAFICA \nPARA LA PREVENCION DE INCENDIOS SIGPI";

            string sPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            sPath = sPath + "\\" + "parameters";
            logger.Info("FrmSIGPIPrincipal  :: sPath :: {0}", sPath);
            //System.Console.WriteLine(sPath);
            //MessageBox.Show(sPath,"sPath");

            sPath = sPath.Replace("file:\\", "");
            //MessageBox.Show("parametros: " + sPath + "\\parametros.xml");
            try
            {
                XmlSerializer          serializer = new XmlSerializer(typeof(SIGPIParametros));
                System.IO.StreamReader r          = new System.IO.StreamReader(sPath + "\\parametros.xml");
                parametros = (SIGPIParametros)serializer.Deserialize(r);
                r.Close();
                serializer = null;
                r          = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SIGPI");
                return;
            }

            //string sCurrentDir = System.Reflection.Assembly.GetExecutingAssembly().Location;
            //string sPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

            //try
            //{
            //  parametros = new SIGPIParametros(sPath + "\\parametros.xml");
            //}
            //catch (Exception ex)
            //{

            //  MessageBox.Show(ex.Message, "SIGPI 2010");
            //  return;
            //}

            procesamiento = new SIGPIProcesamiento(parametros);
            sigpi         = new SIGPICls();
            sigpiDao      = new SIGPIDao();
            sigpiDao.ConnectLocalDB(parametros.RutaBD);
            sigpiDao.UltimaFechaIncorporacion(sigpi);
            sigpi.Parametros = parametros;
            // Revisar que coincida la fecha de procesamiento de datos con la fecha de procesamiento del modelo
            txtFechaUltimoModelo.Text = sigpi.FechaProcesamiento.ToLongDateString();

            //if (!LicenseInitializer.InitializeApplication("arcview"))
            //{
            //  if (!LicenseInitializer.InitializeApplication("arcinfo"))
            //  {
            //    MessageBox.Show("No posee licencia de arcview o arcinfo");
            //  }
            //}
        }
Exemple #2
0
        private void btnExportarAExcel_Click(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;

            string   sNombreCapa      = lvwModelos.SelectedItems[0].Text;
            DateTime fechaExportacion = new DateTime(Convert.ToInt16("20" + sNombreCapa.Substring(9, 2)),
                                                     Convert.ToInt16(sNombreCapa.Substring(1, 2)),
                                                     Convert.ToInt16(sNombreCapa.Substring(4, 2)));
            string             sFecha        = fechaExportacion.ToString("dd DE MMMM DE yyyy").ToUpper();
            SIGPIProcesamiento procesamiento = new SIGPIProcesamiento(_sigpi.Parametros);

            Microsoft.Office.Interop.Excel.Application _excelApp = new Microsoft.Office.Interop.Excel.Application();
            string sRuta = "";

            if (radioBtnProbabilidad.Checked)
            {
                sRuta = _sigpi.Parametros.RutaSIGPI + "\\" + _sigpi.Parametros.Resultado;
            }
            else if (radioBtnModelo.Checked)
            {
                sRuta = _sigpi.Parametros.RutaSIGPI + "\\" + _sigpi.Parametros.Raster;
            }

            string sTitulo = "PROBABILIDAD PARA EL " + sFecha;

            try
            {
                Worksheet sheet = procesamiento.ExportarAExcel(sNombreCapa, sRuta, _sigpi, _excelApp);
                sheet.SaveAs(_sigpi.Parametros.RutaSIGPI + "Tablas\\" + sTitulo + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            catch (Exception ex)
            {
                _excelApp.Quit();
                MessageBox.Show(ex.Message);
                this.Cursor = Cursors.Default;
            }

            this.Cursor       = Cursors.Default;
            _excelApp.Visible = true;
            //_excelApp.Quit();

            //MessageBox.Show("Archivo Exportado");
        }
        private void btnExportarAExcel_Click_1(object sender, EventArgs e)
        {
            this.Cursor = Cursors.WaitCursor;
            DateTime fechaExportacion = monthCalendar1.SelectionStart;
            string   sMonth           = fechaExportacion.ToString("MM");

            int    iYear          = fechaExportacion.Year;
            string sNombreFileGDB = iYear.ToString() + "-" + sMonth + "-Modelos.gdb";

            string sNombreCapa = "Amenaza_" + fechaExportacion.ToString("yyyy_MM_dd");

            Geoprocessor gp = new Geoprocessor();

            string sOutFC = sNombreCapa + ".shp";
            int    i      = 1;

            while (System.IO.File.Exists(System.IO.Path.GetTempPath() + sOutFC))
            {
                sOutFC = sNombreCapa + "_" + i.ToString() + ".shp";
                i++;
            }

            String sOutFC2;

            try
            {
                sOutFC2 = RasterAPuntos(Sigpi.Parametros.RutaSIGPI + "\\" + Sigpi.Parametros.Resultado + "\\" + sNombreFileGDB + "\\" + sNombreCapa,
                                        System.IO.Path.GetTempPath() + sOutFC, gp);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SIGPI", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                this.Cursor = Cursors.Default;
                return;
            }


            IWorkspaceFactory pWF         = new ShapefileWorkspaceFactoryClass();
            IFeatureWorkspace pFWorkspace = (IFeatureWorkspace)pWF.OpenFromFile(System.IO.Path.GetTempPath(), 0);
            string            sFC         = sOutFC2.Substring(sOutFC2.LastIndexOf("\\"), sOutFC2.Length - sOutFC2.LastIndexOf("\\")); // sOutFC2.Replace(System.IO.Path.GetTempPath(), "");
            IFeatureClass     pFC         = pFWorkspace.OpenFeatureClass(sFC);

            string sFecha = fechaExportacion.ToString("dd DE MMMM DE yyyy").ToUpper();

            SIGPIProcesamiento procesamiento = new SIGPIProcesamiento(_sigpi.Parametros);

            Microsoft.Office.Interop.Excel.Application _excelApp = new Microsoft.Office.Interop.Excel.Application();

            string sRuta   = _sigpi.Parametros.RutaSIGPI + "\\" + "plantillas" + "\\" + "plantilla presentacion datos probabilidad.xls";
            string sTitulo = "PROBABILIDAD PARA EL " + sFecha;

            try
            {
                Workbook workBook = _excelApp.Workbooks.Open(sRuta, Type.Missing, Type.Missing, Type.Missing,
                                                             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                Worksheet sheet = (Worksheet)workBook.Sheets["DATOS_PROBABILIDAD"];
                object    objVal;
                Microsoft.Office.Interop.Excel.Range range;
                object[,] objValues = new object[1, 6];
                int k               = 2;
                int lFieldCelda     = pFC.FindField("GRID_CODE");
                int lFieldMpio      = pFC.FindField("MUNICIPIO");
                int lFieldCabecera  = pFC.FindField("CABECERA");
                int lFieldDepto     = pFC.FindField("DEPARTAMEN");
                int lFieldCobertura = pFC.FindField("COBERTURA");
                int lFieldParque    = pFC.FindField("NOMBRE_PAR");

                IFeatureCursor pFCursor1;
                IFeature       pFeature1 = null;


                pFCursor1            = pFC.Search(null, false);
                pFeature1            = pFCursor1.NextFeature();
                progressBar1.Minimum = 1;
                progressBar1.Maximum = 65537;
                progressBar1.Step    = 100;
                progressBar1.Visible = true;
                System.Windows.Forms.Application.DoEvents();
                String currentValue = "";
                while (pFeature1 != null)
                {
                    range           = sheet.get_Range("A" + k.ToString(), "E" + k.ToString());
                    objValues[0, 0] = pFeature1.get_Value(lFieldCelda);
                    objValues[0, 1] = pFeature1.get_Value(lFieldMpio);
                    objValues[0, 2] = pFeature1.get_Value(lFieldCabecera);
                    objValues[0, 3] = pFeature1.get_Value(lFieldDepto);
                    objValues[0, 4] = pFeature1.get_Value(lFieldCobertura);
                    objValues[0, 5] = pFeature1.get_Value(lFieldParque);
                    if (!currentValue.Equals(objValues[0, 0] + "-" + objValues[0, 1] + "-" + objValues[0, 2] + "-" + objValues[0, 3] + "-" + objValues[0, 4] + "-" + objValues[0, 5]))
                    {
                        range.set_Value(Type.Missing, objValues);
                        k++;
                    }
                    currentValue = objValues[0, 0] + "-" + objValues[0, 1] + "-" + objValues[0, 2] + "-" + objValues[0, 3] + "-" + objValues[0, 4] + "-" + objValues[0, 5];


                    if (k == 65537)
                    {
                        break;
                    }
                    if (k % 100 == 0)
                    {
                        progressBar1.PerformStep();
                    }

                    //Console.WriteLine(k.ToString());
                    pFeature1 = pFCursor1.NextFeature();
                }
                progressBar1.Visible = false;
                System.Windows.Forms.Application.DoEvents();
                sheet.SaveAs(_sigpi.Parametros.RutaSIGPI + "Tablas\\" + sTitulo + ".xls", Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                             Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            }
            catch (Exception ex)
            {
                _excelApp.Quit();
                MessageBox.Show(ex.Message);
                this.Cursor = Cursors.Default;
            }

            this.Cursor       = Cursors.Default;
            _excelApp.Visible = true;
            //_excelApp.Quit();

            //MessageBox.Show("Archivo Exportado");

            ////this.Cursor = Cursors.WaitCursor;
            ////DateTime fechaExportacion = monthCalendar1.SelectionStart;
            ////int iMonth = fechaExportacion.Month;
            ////string sMonth = (iMonth.ToString().Length == 1 ? "0" + iMonth.ToString() : iMonth.ToString() );

            ////int iYear = fechaExportacion.Year;
            ////string sNombreFileGDB = iYear.ToString() + "-" + sMonth + "-Modelos.gdb";
            ////IWorkspaceFactory pWF = new FileGDBWorkspaceFactoryClass();
            ////string sRutaFileGDB = Sigpi.Parametros.RutaSIGPI + "\\" + Sigpi.Parametros.Resultado + "\\" + sNombreFileGDB;
            ////IRasterWorkspaceEx pRWorkspace = (IRasterWorkspaceEx)pWF.OpenFromFile(sRutaFileGDB, 0);
            ////string sNombreCapa = "Amenaza_" + fechaExportacion.ToString("yyyy_MM_dd");

            ////IRasterDataset pRDataset = pRWorkspace.OpenRasterDataset(sNombreCapa);
            ////string sFecha = fechaExportacion.ToString("dd DE MMMM DE yyyy").ToUpper();

            ////SIGPIProcesamiento procesamiento = new SIGPIProcesamiento(_sigpi.Parametros);
            ////Microsoft.Office.Interop.Excel.Application _excelApp = new Microsoft.Office.Interop.Excel.Application();


            ////string sTitulo = "PROBABILIDAD PARA EL " + sFecha;
            ////try
            ////{
            ////  Worksheet sheet = procesamiento.ExportarAExcel2(pRDataset.CreateDefaultRaster(), _sigpi, _excelApp);
            ////  string sNombreArchivo = _sigpi.Parametros.RutaSIGPI + "Tablas\\" + sTitulo + ".xls";
            ////  MessageBox.Show("Archivo Generado: " + sNombreArchivo);
            ////  sheet.SaveAs(sNombreArchivo, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
            ////                  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
            ////}
            ////catch (Exception ex)
            ////{
            ////  _excelApp.Quit();
            ////  MessageBox.Show(ex.Message);
            ////  this.Cursor = Cursors.Default;
            ////}

            ////this.Cursor = Cursors.Default;
            ////_excelApp.Visible = true;
            //////_excelApp.Quit();

            //////MessageBox.Show("Archivo Exportado");
        }
Exemple #4
0
        /// <summary>
        /// Ejecuta el modelo de amenazas de incendios
        /// </summary>
        /// <param name="sTablaPrecipPromedio">Tabla Precipitacion Promedio</param>
        /// <param name="sConsultaTablaPrecipPromedio">SQL para la table precipitacion promedio</param>
        /// <param name="sPrefijo">Prefijo para los nombres de las capas</param>
        /// <param name="sTablaTempPromedio">Nombre de la tabla temporal de promedios</param>
        /// <param name="sConsultaTablaTempPromedio">SQL para la tabla temporal de promedios</param>
        /// <param name="bUsarSatelite">Indica si se han de utilizar las imagenes de satelita</param>
        /// <param name="bMostrarIntermedios">Indica si se mostraran los resultados intermedios en el mapa activo</param>
        private void GenerarModelo(string sTablaPrecipPromedio, string sConsultaTablaPrecipPromedio, string sPrefijo,
                                   string sTablaTempPromedio, string sConsultaTablaTempPromedio, bool bUsarSatelite,
                                   bool bMostrarIntermedios, String[] sRastersPrecipitacion)
        {
            String sPath   = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
            String tempDir = "";

            sPath = sPath.Replace("file:\\", "");
            SIGPIParametros parametros = new SIGPIParametros();

            try
            {
                XmlSerializer          serializer = new XmlSerializer(typeof(SIGPIParametros));
                System.IO.StreamReader r          = new System.IO.StreamReader(sPath + "\\parameters\\parametros.xml");
                parametros = (SIGPIParametros)serializer.Deserialize(r);
                r.Close();
                serializer = null;
                r          = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "SIGPI 2013");
                return;
            }

            SIGPIProcesamiento procesamiento = new SIGPIProcesamiento(parametros);
            SIGPICls           sigpi         = new SIGPICls();
            SIGPIDao           sigpiDao      = new SIGPIDao();

            sigpiDao.ConnectLocalDB(parametros.RutaBD);
            sigpiDao.UltimaFechaIncorporacion(sigpi);
            sigpi.Parametros = parametros;

            OleDbCommand   command = sigpiDao.LocalDBConnection.CreateCommand();
            OleDbParameter param   = command.CreateParameter();
            OleDbParameter param1  = command.CreateParameter();

            param.ParameterName = "fecProce";
            param.Value         = sigpi.FechaProcesamiento;

            command.CommandText = "UPDATE FECHAS_PROCESO SET FEC_PROCE = @fecProce";
            command.Parameters.Add(param);

            string sSQL = ""; // "UPDATE FECHAS_PROCESO SET FEC_PROCE = #" + sigpi.FechaProcesamiento.ToString("MM/dd/yyyy") + "#";

            try
            {
                sigpiDao.EjecutarSentenciaSinQuery(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show("No se pudo actualizar la fecha de incorporacion.\n" + ex.Message);
            }

            IProgressDialogFactory pProDiaFac = new ProgressDialogFactoryClass();
            IStepProgressor        pStepPro   = pProDiaFac.Create(null, 0);

            pStepPro.MinRange  = 1;
            pStepPro.MaxRange  = 5;
            pStepPro.StepValue = 1;
            IProgressDialog2 pProDia = (IProgressDialog2)pStepPro;

            pProDia.Animation = esriProgressAnimationTypes.esriProgressGlobe;

            pProDia.Title = "Generar Modelo Amenazas";
            pProDia.ShowDialog();
            pStepPro.Step();
            pStepPro.Message = "Generando Grids Meteorologicos...";

            IFeatureClass     pFeatureClass;
            IWorkspaceFactory pShpWorkspaceFactory     = new ShapefileWorkspaceFactoryClass();
            IWorkspaceFactory pFileGDBWorkspaceFactory = new FileGDBWorkspaceFactoryClass();

            string sFormatTmp = "gdb_" + sigpi.FechaProcesamiento.ToString("yyyyMMdd") + "_" +
                                DateTime.Now.ToString("HHmmss");

            tempDir = sigpi.Parametros.TempDir;

            if (tempDir == null || tempDir.Trim().Equals(""))
            {
                tempDir = System.IO.Path.GetTempPath();
            }
            string sRutaFileGDB = System.IO.Path.GetTempPath() + sFormatTmp + ".gdb";

            if (System.IO.Directory.Exists(sRutaFileGDB))
            {
                try
                {
                    System.IO.Directory.Delete(sRutaFileGDB);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se pudo borrar la File Geodatabase Temporal: " +
                                    sRutaFileGDB +
                                    " Intente Borrarla Manualmente. " + ex.Message);
                    return;
                }
            }

            Geoprocessor   gp = new Geoprocessor();
            IWorkspaceName pWSName;
            string         sCapaResultado = "Amenaza_" + sigpi.FechaProcesamiento.ToString("yyyy_MM_dd");

            string sRutaGdbResultados = parametros.RutaSIGPI + parametros.Resultado + "\\" +
                                        sigpi.FechaProcesamiento.Year.ToString() + "-" +
                                        sigpi.FechaProcesamiento.ToString("MM") + "-Modelos.gdb";

            if (System.IO.Directory.Exists(sRutaGdbResultados))
            {
                GPUtilitiesClass gpUtilClass = new GPUtilitiesClass();
                try
                {
                    Delete del = new Delete();
                    del.in_data = sRutaGdbResultados + "\\" + sCapaResultado;
                    gp.Execute(del, null);
                }
                catch (Exception)
                {
                }
            }
            else
            {
                try
                {
                    pWSName = pFileGDBWorkspaceFactory.Create(parametros.RutaSIGPI + parametros.Resultado + "\\",
                                                              sigpi.FechaProcesamiento.Year.ToString() + "-" +
                                                              sigpi.FechaProcesamiento.ToString("MM") + "-Modelos.gdb", null, 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("No se pudo crear la Geodatabase de resultados: \n" + sRutaGdbResultados);
                    pStepPro.Hide();
                }
            }

            pWSName = pFileGDBWorkspaceFactory.Create(System.IO.Path.GetTempPath(), sFormatTmp, null, 0);
            ESRI.ArcGIS.esriSystem.IName name = (ESRI.ArcGIS.esriSystem.IName)pWSName;

            IFeatureWorkspace pWorkspaceTemp;

            try
            {
                pWorkspaceTemp = (IFeatureWorkspace)name.Open();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }

            IWorkspaceFactory pWF     = new AccessWorkspaceFactoryClass();
            IFeatureWorkspace pWSMask = (IFeatureWorkspace)pWF.OpenFromFile(parametros.RutaGBD, 0);
            IGeoDataset       pFCMask = (IGeoDataset)pWSMask.OpenFeatureClass(parametros.Mascara);
            ISpatialReference pSpaRef = pFCMask.SpatialReference;
            IEnvelope         pEnv    = pFCMask.Extent;

            string sNombreTabla = "TMPPR_";

            DateTime fechaProcesamiento = sigpi.FechaProcesamiento;

            fechaProcesamiento = fechaProcesamiento.Date;


            for (int i = 0; i < 10; i++)
            {
                try
                {
                    sigpiDao.EjecutarSentenciaSinQuery("DROP TABLE " + sNombreTabla + i.ToString());
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                }
                // "IIf([LECTUS_PRECI]![LECTURA]<=2,5,IIf([LECTUS_PRECI]![LECTURA]<=8 And [LECTUS_PRECI]![LECTURA]>2,4,IIf([LECTUS_PRECI]![LECTURA]<=14 And [LECTUS_PRECI]![LECTURA]>8,3,IIf([LECTUS_PRECI]![LECTURA]<=24 And [LECTUS_PRECI]![LECTURA]>14,2,IIf([LECTUS_PRECI]![LECTURA]>24,1,0))))) AS LECTURAS " +
                //sSQL = "SELECT CODIGO, FECHA, X, Y, LECTURA AS RASTERVALU " +
                //              "INTO " + sNombreTabla + i.ToString() + " " +
                //              "FROM LECTUS_PRECI " +
                //              "WHERE (((FECHA)=#" + sigpi.FechaProcesamiento.AddDays(-i).ToString("MM/dd/yyyy") + "#))";
                command             = sigpiDao.LocalDBConnection.CreateCommand();
                command.CommandText = "SELECT CODIGO, FECHA, X, Y, LECTURA AS RASTERVALU " +
                                      "INTO " + sNombreTabla + i.ToString() + " " +
                                      "FROM LECTUS_PRECI " +
                                      "WHERE (((FECHA) >=@fecha) and ((FECHA) <@fecha1))";
                param = command.CreateParameter();
                param.ParameterName = "fecha";
                param.Value         = sigpi.FechaProcesamiento.AddDays(-i);
                command.Parameters.Add(param);
                param1 = command.CreateParameter();
                param1.ParameterName = "fecha1";
                param1.Value         = sigpi.FechaProcesamiento.AddDays(-i + 1);
                command.Parameters.Add(param1);

                try
                {
                    sigpiDao.EjecutarSentenciaSinQuery(command);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Error generando las tablas temporales de precipitaciones. Descripcion: \n" + ex.Message);
                    //pProDia.HideDialog();
                    return;
                }
            }

            try
            {
                sigpiDao.EjecutarSentenciaSinQuery("DROP TABLE TEMPERATURA_PROMEDIO");
            }
            catch (Exception ex)
            {
            }

            //"IIf(Avg(LECTUS_TEMPE.LECTURA)<=6,1,IIf(Avg(LECTUS_TEMPE.LECTURA) <=12 And Avg(LECTUS_TEMPE.LECTURA)>6,2," +
            //"IIf(Avg(LECTUS_TEMPE.LECTURA)<=18 And Avg(LECTUS_TEMPE.LECTURA)>12,3,IIf(Avg(LECTUS_TEMPE.LECTURA)<=24 And " +
            //"Avg(LECTUS_TEMPE.LECTURA)>12,4,IIf(Avg(LECTUS_TEMPE.LECTURA)>24,5,0))))) AS LECTURAS, " +

            //sSQL = "SELECT CODIGO, Max(LECTUS_TEMPE.FECHA) AS FECHA, 10 AS Num_Dias, X, Y, AVG(LECTURA) AS RASTERVALU " +
            //        "INTO TEMPERATURA_PROMEDIO " +
            //        "FROM LECTUS_TEMPE " +
            //        "WHERE (((FECHA)>=#" + sigpi.FechaProcesamiento.AddDays(-10).ToString("MM/dd/yyyy") + "# " +
            //        "And (FECHA)<=#" + sigpi.FechaProcesamiento.ToString("MM/dd/yyyy") + "#)) " +
            //        "GROUP BY CODIGO, X, Y";
            command             = sigpiDao.LocalDBConnection.CreateCommand();
            command.CommandText = "SELECT CODIGO, Max(LECTUS_TEMPE.FECHA) AS FECHA, 10 AS Num_Dias, X, Y, AVG(LECTURA) AS RASTERVALU " +
                                  "INTO TEMPERATURA_PROMEDIO " +
                                  "FROM LECTUS_TEMPE " +
                                  "WHERE (((FECHA)>= @fecha1 " +
                                  "And (FECHA)<= @fecha)) " +
                                  "GROUP BY CODIGO, X, Y";
            param = command.CreateParameter();
            param.ParameterName = "fecha";
            param.Value         = sigpi.FechaProcesamiento;
            param1 = command.CreateParameter();
            param1.ParameterName = "fecha1";
            param1.Value         = sigpi.FechaProcesamiento.AddDays(-10);
            command.Parameters.Add(param1);
            command.Parameters.Add(param);

            try
            {
                sigpiDao.EjecutarSentenciaSinQuery(command);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Generando Tabla: TEMPERATURA_PROMEDIO " + ex.Message);
                pProDia.HideDialog();
                return;
            }

            string sExpression = "";
            string sOutGrid;
            double dPeso = 0;
            string sAmenazaXPrecipitacion    = sRutaFileGDB + "\\amenaza_x_precipitacion";
            string sTablaTemperaturaPromedio = "TEMPERATURA_PROMEDIO";
            string sFCTempPromedio           = "TEMP_PROMEDIO";
            string sPrefijoIDW                     = "idw";
            string sAmenazaXTemperatura            = sRutaFileGDB + "\\" + "amenaza_x_temperatura";
            string sAmenazasParciales              = parametros.RutaGBD + "\\" + "amenazas_parciales_2";
            string sAmenazaBruta                   = sRutaFileGDB + "\\amenaza_incendio_bruta";
            string sAmenazaFinal                   = sRutaFileGDB + "\\amenaza_incendio_final";
            string sTablaReclassIncendios          = parametros.TablaReclasificacionIncendios;     //"tbl_reclass_amenaza_incendios";
            string sTablaReclassTemp               = parametros.TablaReclasificacionTemperatura;   //"tbl_reclass_temperatura";
            string sTablaReclassPrecip             = parametros.TablaReclasificacionPrecipitacion; //"tbl_reclass_precipitacion";
            string sAmenazaXTemperaturaCombinada   = sRutaFileGDB + "\\" + "amenaza_x_temperatura_combinada";
            string sEstVirtualesPrecipitacion      = sRutaFileGDB + "\\" + "estaciones_virtuales_precipitacion";
            string sAmenazaXPrecipitacionCombinada = sRutaFileGDB + "\\" + "amenaza_x_precipitacion_combinada";
            string sAmenazaFinalBrutaNVI           = sRutaFileGDB + "\\" + "amenaza_incend_raw_nvi";
            string sNVITempReclass                 = sRutaFileGDB + "\\" + "nvi_reclass_temp";
            string sFromField             = "FROM_";
            string sToField               = "TO_";
            string sOutField              = "OUT";
            string sNoData                = "NODATA";
            string sFieldLecturas         = "RASTERVALU";               //LECTURAS";
            string sTipoEstadistico       = parametros.TipoEstadistico; //"MAXIMUM";
            string sAmenazaXPrecipReclass = sAmenazaXPrecipitacion + "_reclass";
            string sAmenazaXTempReclass   = sAmenazaXTemperatura + "_reclass";
            string nvi = parametros.RutaSIGPI + "NVI" + "\\" + "tmpMosaic.500m_16_days_NDVI_GEO.tif";

            double dPesoPrecipitacion     = parametros.PesoPrecipitacion;     //0.29;
            double dPesoTemperatura       = parametros.PesoTemperatura;       //0.24;
            double dPesoAmenazasParciales = parametros.PesoAmenazasParciales; //0.47;

            IDataset         pDS;
            IDatasetName     pDSName;
            IDatasetName     pDSName2  = new FeatureClassNameClass();
            IExportOperation pExportOp = new ExportOperationClass();

            string sEstacionesVirtuales           = sRutaFileGDB + "\\" + "EstacionesVirtuales.shp";
            ExtractValuesToPoints extractValPoint = new ExtractValuesToPoints();

            extractValPoint.in_point_features  = sEstacionesVirtuales;
            extractValPoint.interpolate_values = "NONE";
            extractValPoint.add_attributes     = "VALUE_ONLY";


            //'0.037037037;
            // 1" = 1/3600
            double dCellSize = parametros.TamanoCelda / (3600 * 30);

            double[] iPesos      = parametros.Pesos; //{ 30, 20, 10, 9, 8, 7, 6, 5, 4, 3 };
            double   iTotalPesos = 0;                //102;

            foreach (double dP in iPesos)
            {
                iTotalPesos += dP;
            }

            gp.AddOutputsToMap = bMostrarIntermedios;
            gp.SetEnvironmentValue("Mask", parametros.RutaGBD + "\\" + parametros.Mascara);
            gp.SetEnvironmentValue("Extent", pEnv.XMin.ToString() + " " + pEnv.YMin.ToString() + " " +
                                   pEnv.XMax.ToString() + " " + pEnv.YMax.ToString());

            ESRI.ArcGIS.SpatialAnalystTools.Idw idw = new Idw();
            idw.z_field   = sFieldLecturas;
            idw.cell_size = dCellSize;

            for (int i = 0; i < 10; i++)
            {
                pFeatureClass          = procesamiento.FCPrecipitacion(sNombreTabla + i.ToString(), pSpaRef);
                pDS                    = (IDataset)pFeatureClass;
                pDSName                = (IDatasetName)pDS.FullName;
                pDSName2.Name          = sNombreTabla + i.ToString();
                pDSName2.WorkspaceName = pWSName;
                try
                {
                    pExportOp.ExportFeatureClass(pDSName, null, null, null, (IFeatureClassName)pDSName2, 0);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                    pProDia.HideDialog();
                    return;
                }

                if (bUsarSatelite)
                {
                    //Geoprocessor gp1 = new Geoprocessor();
                    //extractValPoint.in_raster = sRastersPrecipitacion[i];  // txtRutaPrecipitacion.Text;
                    //extractValPoint.out_point_features = sEstVirtualesPrecipitacion + i.ToString();

                    //try
                    //{
                    //  gp1.Execute(extractValPoint, null);
                    //}
                    //catch (Exception ex)
                    //{
                    //  MessageBox.Show(ex.Message);
                    //}

                    //Merge merge = new Merge();
                    //string sInputMerge = sRutaFileGDB + "\\" + sNombreTabla + i.ToString() + ";" + sEstVirtualesPrecipitacion + i.ToString();
                    //merge.inputs = sInputMerge;
                    ////"[" + sRutaFileGDB + "\\" + sNombreTabla + i.ToString() + ";" + sEstVirtualesPrecipitacion + i.ToString() + "]" ;
                    //merge.output = sRutaFileGDB + "\\" + "est_precip_temporal" + i.ToString();
                    //try
                    //{
                    //  gp.Execute(merge, null);
                    //}
                    //catch (Exception ex)
                    //{
                    //  MessageBox.Show(ex.Message);
                    //}

                    //idw.in_point_features = sRutaFileGDB + "\\" + "est_precip_temporal" + i.ToString();

                    idw.in_point_features = sRutaFileGDB + "\\" + sNombreTabla + i.ToString();
                }
                else
                {
                    idw.in_point_features = sRutaFileGDB + "\\" + sNombreTabla + i.ToString();
                }

                sOutGrid       = sRutaFileGDB + "\\" + sPrefijoIDW + "_" + sNombreTabla + i.ToString();
                idw.out_raster = sOutGrid;
                try
                {
                    gp.Execute(idw, null);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }

                dPeso        = iPesos[i] / iTotalPesos;
                sExpression += "( Raster(r'" + sOutGrid + "') * " + dPeso.ToString().Replace(",", ".") + ")";
                if (i < 9)
                {
                    sExpression += " + ";
                }
            }


            pStepPro.Step();

            ////for (int i = 0; i < 10; i++)
            ////{
            ////  //pStepPro.Message = "Generando Modelo Precipitacion: " + i.ToString();
            ////  sOutGrid = sRutaFileGDB + "\\" + sPrefijoIDW + "_" + sNombreTabla + i.ToString();
            ////  idw.in_point_features = sRutaFileGDB + "\\" + sNombreTabla + i.ToString();
            ////  idw.out_raster = sOutGrid;
            ////  gp.Execute(idw, null);
            ////  dPeso = iPesos[i] / iTotalPesos;
            ////  sExpression += "(" + sOutGrid + " * " + dPeso.ToString() + ")";
            ////  if (i < 9)
            ////    sExpression += " + ";
            ////}
            //gp.AddMessage("Expresion: " + sExpression);
            //SingleOutputMapAlgebra mapAlgebra = new SingleOutputMapAlgebra();

            ESRI.ArcGIS.SpatialAnalystTools.RasterCalculator mapAlgebra = new RasterCalculator();
            //mapAlgebra.expression_string = sExpression;
            // mapAlgebra.out_raster = sAmenazaXPrecipitacion;

            mapAlgebra.expression = sExpression;

            mapAlgebra.output_raster = sAmenazaXPrecipitacion;
            pStepPro.Message         = "Generando Amenaza Precipitacion...";
            try
            {
                gp.Execute(mapAlgebra, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Generando Amenaza x Precipitacion. " + ex.Message);
                pProDia.HideDialog();
                return;
            }

            //if (bUsarSatelite)  // Para la combinacion de la precipitacion x estaciones y satelite
            //{

            //  //CellStatistics cellStatisticsP = new CellStatistics();
            //  //cellStatisticsP.in_rasters_or_constants = sAmenazaXPrecipitacion + ";" + txtRutaPrecipitacion.Text;
            //  //cellStatisticsP.out_raster = sAmenazaXPrecipitacionCombinada;
            //  //cellStatisticsP.statistics_type = sTipoEstadistico;
            //  try
            //  {
            //    gp.Execute(extractValPoint, null);
            //    //sAmenazaXPrecipitacion = sAmenazaXPrecipitacionCombinada;
            //  }
            //  catch (Exception ex)
            //  {
            //    MessageBox.Show("Error generando estaciones virtuales con precipitacion." + ex.Message);
            //    return;
            //  }

            //  Merge merge = new Merge();
            //  merge.inputs =

            //}

            DateTime date   = sigpi.FechaProcesamiento;
            string   sMonth = date.ToString("MM");

            pStepPro.Step();
            pStepPro.Message = "Generando Amenaza x Temperatura";
            pFeatureClass    = procesamiento.FCPrecipitacion(sTablaTemperaturaPromedio, pSpaRef);
            pDS                    = (IDataset)pFeatureClass;
            pDSName                = (IDatasetName)pDS.FullName;
            pDSName2.Name          = sFCTempPromedio;
            pDSName2.WorkspaceName = pWSName;
            try
            {
                pExportOp.ExportFeatureClass(pDSName, null, null, null, (IFeatureClassName)pDSName2, 0);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }

            idw.in_point_features = sRutaFileGDB + "\\" + sFCTempPromedio;
            idw.out_raster        = sAmenazaXTemperatura;
            try
            {
                gp.Execute(idw, null);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }


            //if (bUsarSatelite)
            //{
            //  Geoprocessor gp1 = new Geoprocessor();
            //  Con pContmp = new Con();
            //  pContmp.in_conditional_raster = txtRutaTemperatura.Text;
            //  pContmp.in_true_raster_or_constant = txtRutaTemperatura.Text;
            //  pContmp.in_false_raster_or_constant = -99;
            //  string sRasterTTemp = sAmenazaXTemperaturaCombinada + "_ajs";
            //  pContmp.out_raster = sRasterTTemp;
            //  pContmp.where_clause = "VALUE < 55";

            //  try
            //  {
            //    gp1.Execute(pContmp, null);
            //  }
            //  catch (Exception)
            //  {
            //    sRasterTTemp = txtRutaTemperatura.Text; ;
            //  }
            //  gp1 = null;

            //  CellStatistics cellStatistics = new CellStatistics();
            //  cellStatistics.in_rasters_or_constants = sAmenazaXTemperatura + ";" + sRasterTTemp;
            //  cellStatistics.out_raster = sAmenazaXTemperaturaCombinada;
            //  cellStatistics.statistics_type = sTipoEstadistico;
            //  try
            //  {
            //    gp.Execute(cellStatistics, null);
            //    sAmenazaXTemperatura = sAmenazaXTemperaturaCombinada;
            //  }
            //  catch (Exception)
            //  {
            //  }
            //}

            ReclassByTable rbt = new ReclassByTable();

            rbt.in_raster          = sAmenazaXPrecipitacion;
            rbt.in_remap_table     = sTablaReclassPrecip; // parametros.RutaGBD + "\\" + sTablaReclassPrecip;
            rbt.from_value_field   = sFromField;
            rbt.to_value_field     = sToField;
            rbt.output_value_field = sOutField;
            rbt.missing_values     = sNoData;
            rbt.out_raster         = sAmenazaXPrecipReclass;
            //pStepPro.Message = "Generando Amenaza X Precipitacion Reclasificada";
            try
            {
                gp.Execute(rbt, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                pProDia.HideDialog();
                return;
            }

            rbt.in_raster      = sAmenazaXTemperatura;
            rbt.in_remap_table = sTablaReclassTemp; // parametros.RutaGBD + "\\" + sTablaReclassTemp;
            rbt.out_raster     = sAmenazaXTempReclass;
            //pStepPro.Message = "Generando Amenaza X Temperatura Reclasificada";
            try
            {
                gp.Execute(rbt, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                pProDia.HideDialog();
                return;
            }

            sExpression = "( Raster(r'" + sAmenazaXPrecipReclass + "') * " + dPesoPrecipitacion.ToString().Replace(",", ".") + ") + " +
                          "( Raster(r'" + sAmenazaXTempReclass + "') * " + dPesoTemperatura.ToString().Replace(",", ".") + ") + " +
                          "( Raster(r'" + sAmenazasParciales + "') * " + dPesoAmenazasParciales.ToString().Replace(",", ".") + ")";

            //mapAlgebra.expression_string = sExpression;
            //mapAlgebra.out_raster = sAmenazaBruta;

            sExpression              = sExpression.Replace("\\\\", "/").Replace("\\", "/");
            mapAlgebra.expression    = sExpression;
            mapAlgebra.output_raster = sAmenazaBruta;

            pStepPro.Message = "Generando Amenaza Final Bruta";
            try
            {
                gp.Execute(mapAlgebra, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //if (txtRutaNVI.Text.Trim() != "")
            //{
            Geoprocessor gp2 = new Geoprocessor();

            mapAlgebra               = new RasterCalculator();
            sExpression              = "Con (Raster(r'" + nvi + "') < 0.75, Raster(r'" + sAmenazaBruta + "'), Raster(r'" + sAmenazaBruta + "') -1)";
            sExpression              = sExpression.Replace("\\\\", "/").Replace("\\", "/");
            mapAlgebra.expression    = sExpression;
            mapAlgebra.output_raster = sAmenazaFinalBrutaNVI;

            try
            {
                gp2.Execute(mapAlgebra, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            //}


            rbt.in_raster          = sAmenazaFinalBrutaNVI;  // sAmenazaBruta;
            rbt.in_remap_table     = sTablaReclassIncendios; // parametros.RutaGBD + "\\" + sTablaReclassIncendios;
            rbt.from_value_field   = sFromField;
            rbt.to_value_field     = sToField;
            rbt.output_value_field = sOutField;
            rbt.missing_values     = sNoData;
            rbt.out_raster         = sAmenazaFinal;
            pStepPro.Message       = "Generando Amenaza Final Reclasificada";
            gp.AddOutputsToMap     = true;
            try
            {
                gp.Execute(rbt, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            Copy copy = new Copy();

            copy.in_data = sAmenazaFinal;

            copy.out_data = sRutaGdbResultados + "\\" + sCapaResultado;
            try
            {
                gp.Execute(copy, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error Copiando el resultado. \n " + ex.Message);
            }



            MessageBox.Show("Algoritmo completo ejecutado: " + sRutaGdbResultados + "\\" + sCapaResultado);

            if (m_pApp != null)
            {
                IRasterLayer pRLayer = new RasterLayerClass();
                try
                {
                    IWorkspaceFactory  pWF2      = new FileGDBWorkspaceFactoryClass();
                    IRasterWorkspaceEx pRW       = (IRasterWorkspaceEx)pWF2.OpenFromFile(sRutaGdbResultados, 0);
                    IRasterDataset     pRDataset = pRW.OpenRasterDataset(sCapaResultado);
                    pRLayer.CreateFromDataset(pRDataset);
                    pRLayer.Name = sCapaResultado;
                    IMxDocument pMxDoc = m_pApp.Document as IMxDocument;
                    IMap        pMap   = pMxDoc.FocusMap;
                    AsignarSimbologiaProbabilidad(pRLayer);
                    pMap.AddLayer(pRLayer);
                    if (pMap.LayerCount > 0)
                    {
                        pMap.MoveLayer(pRLayer, pMap.LayerCount - 1);
                    }

                    pMxDoc.UpdateContents();
                    pMxDoc.ActiveView.Refresh();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error cargando Capa!!!");
                }
            }

            pProDia.HideDialog();
        }