Beispiel #1
0
 private void btnOK_Click(object sender, EventArgs e)
 {
     try
     {
         BenMAPLine inputBenMAPLine = new BenMAPLine();
         string     err             = "";
         inputBenMAPLine = DataSourceCommonClass.LoadAQGFile(txtAirQualitySurface.Text, ref err);
         if (inputBenMAPLine == null)
         {
             MessageBox.Show(err);
             return;
         }
         SaveFileDialog saveCSV = new SaveFileDialog();
         saveCSV.Filter           = "csv file(*.csv)|*.csv";
         saveCSV.FilterIndex      = 2;
         saveCSV.RestoreDirectory = true;
         saveCSV.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
         if (saveCSV.ShowDialog() == DialogResult.Cancel)
         {
             return;
         }
         string filePath = saveCSV.FileName.Substring(0, saveCSV.FileName.LastIndexOf(@"\") + 1);
         string fileName = saveCSV.FileName.Substring(saveCSV.FileName.LastIndexOf(@"\") + 1);
         DataSourceCommonClass.SaveModelDataLineToNewFormatCSV(inputBenMAPLine, saveCSV.FileName);
         this.DialogResult = DialogResult.OK;
     }
     catch (Exception ex)
     {
         Logger.LogError(ex.Message);
     }
 }
Beispiel #2
0
        public void ParaserAQG(string strPath)
        {
            try
            {
                string tip = "Reading and checking the data file.";
                _strPath = strPath;
                WaitShow(tip);
                string     err        = "";
                BenMAPLine benMapLine = DataSourceCommonClass.LoadAQGFile(txtExistingAQG.Text, ref err);
                System.Threading.Thread.Sleep(100);
                if (benMapLine == null)
                {
                    WaitClose();
                    MessageBox.Show(err);
                    return;
                }
                WaitClose();
                if (benMapLine.Pollutant.PollutantID != _bgc.Pollutant.PollutantID)
                {
                    MessageBox.Show("The AQG's pollutant does not match the selected pollutant. Please select another file.");
                    return;
                }
                else if (benMapLine.GridType.GridDefinitionID != _bgc.GridType.GridDefinitionID)
                {
                    MessageBox.Show("The AQG's grid definition does not match the selected grid definition. Please select another file.");
                    return;
                }
                if (benMapLine.ShapeFile != null && !benMapLine.ShapeFile.Contains(@"\"))
                {
                    string AppPath      = Application.StartupPath;
                    string _filePath    = txtExistingAQG.Text.Substring(0, txtExistingAQG.Text.LastIndexOf(@"\") + 1);
                    string strShapePath = string.Format("{0}\\Result\\Tmp\\{1}", CommonClass.DataFilePath, benMapLine.ShapeFile);
                    benMapLine.ShapeFile = _filePath + benMapLine.ShapeFile;
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(_bgc.GridType, _bgc.Pollutant, benMapLine, strShapePath);
                }
                else if (benMapLine.ShapeFile != null)
                {
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(_bgc.GridType, _bgc.Pollutant, benMapLine, benMapLine.ShapeFile);
                }
                switch (_currentStat)
                {
                case "baseline":
                    _bgc.Base = benMapLine;
                    break;

                case "control":
                    _bgc.Control = benMapLine; break;
                }
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }
Beispiel #3
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtAirQualitySurface.Text != "")
                {
                    string     err        = "";
                    BenMAPLine benMAPLine = DataSourceCommonClass.LoadAQGFile(txtAirQualitySurface.Text, ref err);
                    if (benMAPLine == null)
                    {
                        MessageBox.Show(err);
                        return;
                    }
                    if (benMAPLine is MonitorDataLine)
                    {
                        MonitorDataLine monitorDataLine = (benMAPLine as MonitorDataLine);
                        if (monitorDataLine.MonitorNeighbors != null && monitorDataLine.MonitorNeighbors.Count > 0)
                        {
                            SaveFileDialog sfd = new SaveFileDialog();
                            sfd.Filter           = "Neighbors files (*.csv)|*.csv";
                            sfd.FilterIndex      = 2;
                            sfd.RestoreDirectory = true;
                            sfd.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                            string _filePath = "";
                            _filePath = sfd.FileName.Substring(0, sfd.FileName.LastIndexOf(@"\") + 1);

                            if (sfd.ShowDialog() == DialogResult.OK)
                            {
                                DataTable dt = new DataTable();
                                dt.Columns.Add("Col");
                                dt.Columns.Add("Row");
                                dt.Columns.Add("MonitorName");
                                dt.Columns.Add("Weight");
                                dt.Columns.Add("Distance");
                                foreach (MonitorNeighborAttribute m in monitorDataLine.MonitorNeighbors)
                                {
                                    DataRow dr = dt.NewRow();
                                    dr["Col"]         = m.Col;
                                    dr["Row"]         = m.Row;
                                    dr["MonitorName"] = m.MonitorName;
                                    dr["Weight"]      = m.Weight;
                                    dr["Distance"]    = m.Distance;
                                    dt.Rows.Add(dr);
                                }
                                CommonClass.SaveCSV(dt, sfd.FileName);
                            }
                        }
                        else
                        {
                            MessageBox.Show("No neighbors in this air quality grid.");
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("This air quality grid is not a monitor direct grid.");
                        return;
                    }
                }
            }
            catch
            {
            }
        }
        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                List <ModelResultAttribute> lstResult = new List <ModelResultAttribute>();
                BenMAPLine inputBenMAPLine            = new BenMAPLine();
                List <ModelResultAttribute>        outModelResultAttributes = new List <ModelResultAttribute>();
                List <Dictionary <string, float> > lstBig   = new List <Dictionary <string, float> >();
                List <ModelResultAttribute>        lstSmall = new List <ModelResultAttribute>();
                string err = "";
                inputBenMAPLine = DataSourceCommonClass.LoadAQGFile(txtAirQualitySurface.Text, ref err);
                if (inputBenMAPLine == null)
                {
                    MessageBox.Show(err);
                    return;
                }
                DataRowView drOutput = (cboAggregationSurface.SelectedItem) as DataRowView;

                int outputGridDefinitionID = Convert.ToInt32(drOutput["GridDefinitionID"]);
                if (inputBenMAPLine.GridType.GridDefinitionID == outputGridDefinitionID)
                {
                    MessageBox.Show("The AQG file you want to aggregate is already at the spatial resolution of the selected aggregation surface.");
                    return;
                }

                SaveFileDialog saveOutAQG = new SaveFileDialog();
                saveOutAQG.Filter           = "aqgx file|*.aqgx";
                saveOutAQG.InitialDirectory = CommonClass.ResultFilePath + @"\Result\AQG";
                saveOutAQG.RestoreDirectory = true;
                if (saveOutAQG.ShowDialog() == DialogResult.Cancel)
                {
                    return;
                }
                WaitShow("Aggregating air quality surface...");
                string filePath = saveOutAQG.FileName.Substring(0, saveOutAQG.FileName.LastIndexOf(@"\") + 1);
                string fileName = saveOutAQG.FileName.Substring(saveOutAQG.FileName.LastIndexOf(@"\") + 1).Replace("aqgx", "shp");

                int GridFrom = inputBenMAPLine.GridType.GridDefinitionID;
                if (GridFrom == 28)
                {
                    GridFrom = 27;
                }
                int GridTo = outputGridDefinitionID;
                if (GridTo == 28)
                {
                    GridTo = 27;
                }
                if (GridFrom == GridTo)
                {
                    outModelResultAttributes = inputBenMAPLine.ModelResultAttributes;
                }
                else
                {
                    string str = string.Format("select sourcecolumn, sourcerow, targetcolumn, targetrow,Percentage from GridDefinitionPercentages a,GridDefinitionPercentageEntries b where a.PercentageID=b.PercentageID and a.SourceGridDefinitionID={0} and a.TargetGridDefinitionID={1} and normalizationstate in (0,1)", GridFrom, GridTo);
                    ESIL.DBUtility.FireBirdHelperBase fb = new ESIL.DBUtility.ESILFireBirdHelper();
                    DataSet ds; int iCount = Convert.ToInt32(fb.ExecuteScalar(CommonClass.Connection, CommandType.Text, "select count(*) from (" + str + " ) a"));
                    if (iCount == 0)
                    {
                        Configuration.ConfigurationCommonClass.creatPercentageToDatabase(GridTo, GridFrom);
                        iCount = 1;
                    }
                    if (iCount != 0)
                    {
                        Dictionary <string, Dictionary <string, double> > dicRelationShip = new Dictionary <string, Dictionary <string, double> >();

                        ds = fb.ExecuteDataset(CommonClass.Connection, CommandType.Text, str);

                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            if (dicRelationShip.ContainsKey(dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()))
                            {
                                if (!dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].ContainsKey(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString()))
                                {
                                    dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].Add(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString(), Convert.ToDouble(dr["Percentage"]));
                                }
                            }
                            else
                            {
                                dicRelationShip.Add(dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString(), new Dictionary <string, double>());
                                dicRelationShip[dr["targetcolumn"].ToString() + "," + dr["targetrow"].ToString()].Add(dr["sourcecolumn"].ToString() + "," + dr["sourcerow"].ToString(), Convert.ToDouble(dr["Percentage"]));
                            }
                        }

                        ds.Dispose();
                        Dictionary <string, ModelResultAttribute> dicModelFrom = new Dictionary <string, ModelResultAttribute>();
                        foreach (ModelResultAttribute mo in inputBenMAPLine.ModelResultAttributes)
                        {
                            dicModelFrom.Add(mo.Col + "," + mo.Row, mo);
                        }
                        foreach (KeyValuePair <string, Dictionary <string, double> > gra in dicRelationShip)
                        {
                            if (gra.Value == null || gra.Value.Count == 0)
                            {
                                continue;
                            }
                            ModelResultAttribute anew = new ModelResultAttribute();
                            anew.Col    = Convert.ToInt32(gra.Key.Split(new char[] { ',' }).ToArray()[0]);
                            anew.Row    = Convert.ToInt32(gra.Key.Split(new char[] { ',' }).ToArray()[1]);
                            anew.Values = new Dictionary <string, float>();
                            Dictionary <string, float> dicValue = new Dictionary <string, float>();


                            for (int i = 0; i < gra.Value.Count; i++)
                            {
                                if (dicModelFrom.ContainsKey(gra.Value.ToList()[i].Key))
                                {
                                    foreach (KeyValuePair <string, float> k in dicModelFrom[gra.Value.ToList()[i].Key].Values)
                                    {
                                        if (!anew.Values.ContainsKey(k.Key))
                                        {
                                            anew.Values.Add(k.Key, Convert.ToSingle(k.Value * gra.Value.ToList()[i].Value));
                                        }
                                        else
                                        {
                                            anew.Values[k.Key] += Convert.ToSingle(k.Value * gra.Value.ToList()[i].Value);
                                        }
                                    }
                                }
                            }

                            if (anew.Values != null && anew.Values.Count > 0)
                            {
                                List <string> lstKey = anew.Values.Keys.ToList();
                                foreach (string k in lstKey)
                                {
                                    anew.Values[k] = Convert.ToSingle(anew.Values[k] / gra.Value.Sum(p => p.Value));
                                }
                            }
                            outModelResultAttributes.Add(anew);
                        }
                    }
                }



                inputBenMAPLine.ModelResultAttributes = outModelResultAttributes;
                inputBenMAPLine.ModelAttributes       = null;
                inputBenMAPLine.GridType = Grid.GridCommon.getBenMAPGridFromID(outputGridDefinitionID);

                DataSourceCommonClass.CreateAQGFromBenMAPLine(inputBenMAPLine, saveOutAQG.FileName);
                WaitClose();
                MessageBox.Show("File saved.", "File saved");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                WaitClose();
                Logger.LogError(ex.Message);
            }
        }
Beispiel #5
0
        private void openAQG(string sourceFilePath, string currentState, BaseControlGroup bcg)
        {
            try
            {
                string     err        = "";
                BenMAPLine benMapLine = DataSourceCommonClass.LoadAQGFile(sourceFilePath, ref err);
                if (benMapLine == null)
                {
                    WaitClose();
                    MessageBox.Show(err);
                    return;
                }

                if (bcg.Pollutant != null && benMapLine.Pollutant.PollutantID != bcg.Pollutant.PollutantID)
                {
                    WaitClose();
                    MessageBox.Show("The AQG's pollutant does not match the selected pollutant. Please select another file.");
                    if (isGridTypeChanged)
                    {
                        CommonClass.GBenMAPGrid = benMAPGridOld;
                        isGridTypeChanged       = false;
                    }

                    return;
                }
                else if (benMapLine.GridType.GridDefinitionID != bcg.GridType.GridDefinitionID)
                {
                    WaitClose();
                    MessageBox.Show("The AQG's grid definition does not match the selected grid definition. Please select another file.");
                    if (isGridTypeChanged)
                    {
                        CommonClass.GBenMAPGrid = benMAPGridOld;
                        isGridTypeChanged       = false;
                    }

                    return;
                }
                if (bcg.Pollutant == null)
                {
                    bcg.Pollutant = benMapLine.Pollutant;
                }
                if (benMapLine.ShapeFile != null && !benMapLine.ShapeFile.Contains(@"\"))
                {
                    string AppPath      = Application.StartupPath;
                    string _filePath    = sourceFilePath.Substring(0, sourceFilePath.LastIndexOf(@"\") + 1);
                    string strShapePath = string.Format("{0}\\Tmp\\{1}", CommonClass.DataFilePath, benMapLine.ShapeFile);
                    benMapLine.ShapeFile = _filePath + benMapLine.ShapeFile;
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(bcg.GridType, bcg.Pollutant, benMapLine, strShapePath);
                }
                else if (benMapLine.ShapeFile != null && benMapLine.ShapeFile.Contains(@"\"))
                {
                    DataSourceCommonClass.SaveBenMAPLineShapeFile(bcg.GridType, bcg.Pollutant, benMapLine, benMapLine.ShapeFile);
                }
                switch (currentState)
                {
                case "baseline":
                    if (bcg.Pollutant == null || bcg.Pollutant.PollutantID == benMapLine.Pollutant.PollutantID)
                    {
                        bcg.Base = benMapLine; if (CommonClass.LstPollutant == null || CommonClass.LstPollutant.Count == 0)
                        {
                            CommonClass.LstPollutant = new List <BenMAPPollutant>();
                            CommonClass.LstPollutant.Add(benMapLine.Pollutant);
                            bcg.Pollutant = benMapLine.Pollutant;
                        }
                    }

                    break;

                case "control":
                    if (bcg.Pollutant == null || bcg.Pollutant.PollutantID == benMapLine.Pollutant.PollutantID)
                    {
                        bcg.Control = benMapLine;
                    }
                    if (CommonClass.LstPollutant == null || CommonClass.LstPollutant.Count == 0)
                    {
                        CommonClass.LstPollutant = new List <BenMAPPollutant>();
                        CommonClass.LstPollutant.Add(benMapLine.Pollutant);
                        bcg.Pollutant = benMapLine.Pollutant;
                    }
                    break;
                }
            }
            catch (Exception ex)
            {
                Logger.LogError(ex);
            }
        }