Example #1
0
        private UserControl switchView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            UserControl view = getView(scenario, modelType, interval, unitType);

            splitContainer1.Panel2.Controls.Clear();
            splitContainer1.Panel2.Controls.Add(view);

            if (view is SubbasinView)
            {
                Map = (view as SubbasinView).Map;
            }
            else
            {
                Map = null;
            }

            _scenario  = scenario;
            _modelType = modelType;
            _unitType  = unitType;

            //change status
            updateStatus(view);

            return(view);
        }
Example #2
0
        /// <summary>
        /// Update the observed status when the data is loaded or deleted.
        /// </summary>
        /// <param name="unitType"></param>
        /// <param name="id"></param>
        public void updateObservedStatus(ArcSWAT.SWATUnitType unitType, int id)
        {
            FeatureType feaType = FeatureType.Line;

            if (unitType == ArcSWAT.SWATUnitType.RES)
            {
                feaType = FeatureType.Point;
            }

            foreach (IFeatureLayer layer in Layers)
            {
                if (layer.DataSet.FeatureType == feaType)
                {
                    DataRow[] rows = layer.DataSet.DataTable.Select(string.Format("{0}={1}", ID_COLUMN_NAME, id));
                    if (rows == null || rows.Length == 0)
                    {
                        continue;
                    }

                    DataRow r = rows[0];
                    if (_project.Observation(Interval).getObservedData(unitType, id).Count > 0)
                    {
                        r[OBSERVED_COLUMN] = 1;
                    }
                    else
                    {
                        r[OBSERVED_COLUMN] = 0;
                    }

                    //re-draw all feature using defined categories
                    layer.ApplyScheme(layer.Symbology);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Retrieve difference data table between two scenarios
        /// </summary>
        /// <param name="type"></param>
        /// <param name="resultType"></param>
        /// <param name="col"></param>
        /// <param name="compareScenario"></param>
        /// <returns></returns>
        public DataTable getDifference(ArcSWAT.SWATUnitType type, string resultType, string col,
                                       ArcSWAT.ScenarioResult compareScenario, System.ComponentModel.BackgroundWorker worker = null)
        {
            string tableId = string.Format("{0}_{1}_{2}_{3}_{4}", type, resultType, col,
                                           compareScenario.ModelType, compareScenario.Scenario.Name);

            if (!_differenceDataset.Tables.Contains(tableId))
            {
                List <int> ids = getSWATUnitIDs(type);

                DataTable dt = new System.Data.DataTable(tableId);
                dt.Columns.Add("ID", typeof(int));
                dt.Columns.Add("R2", typeof(double));
                foreach (int id in ids)
                {
                    if (worker != null)
                    {
                        worker.ReportProgress(0, string.Format("{0}:{1}", type, id));
                    }

                    ArcSWAT.SWATUnit unit = getSWATUnit(type, id);
                    if (unit == null)
                    {
                        continue;
                    }

                    ArcSWAT.SWATUnitResult unitResult = unit.getResult(resultType);
                    if (unitResult == null)
                    {
                        continue;
                    }

                    ArcSWAT.SWATUnitColumnYearResult oneUnitResult = unitResult.getResult(col, -1);
                    if (oneUnitResult == null)
                    {
                        continue;
                    }

                    try
                    {
                        DataRow r = dt.NewRow();
                        r[0] = id;
                        r[1] = oneUnitResult.Compare(compareScenario).Statistics.Statistic("", StatisticCompareType.R2);
                        dt.Rows.Add(r);
                    }
                    catch (System.Exception e)
                    {
                        System.Diagnostics.Debug.WriteLine(e.Message);
                    }
                }
                _differenceDataset.Tables.Add(dt);
            }
            return(_differenceDataset.Tables[tableId]);
        }
Example #4
0
        private void ProjectView_Load(object sender, EventArgs e)
        {
            this.Resize += (ss, ee) => { this.splitContainer1.SplitterDistance = this.Width - 200; };

            cmbObservedColumns.SelectedIndexChanged += (ss, ee) =>
            {
                if (cmbObservedColumns.SelectedIndex == -1)
                {
                    _col = null;
                }
                else
                {
                    _col = ArcSWAT.ObservationData.getObservationSWATColumn(cmbObservedColumns.SelectedItem.ToString());
                }
                updateTableAndChart();
            };

            subbasinMap1.onLayerSelectionChanged += (unitType, id) =>
            {
                cmbObservedColumns.DataSource = null;
                updateTableAndChart();

                if (id <= 0)
                {
                    return;
                }

                _id       = id;
                _unitType = unitType;
                cmbObservedColumns.DataSource =
                    ArcSWAT.ObservationData.getObservationDataColumns(_unitType);
                cmbObservedColumns.SelectedIndex = 0;
                if (onMapSelectionChanged != null)
                {
                    onMapSelectionChanged(this, new EventArgs());
                }
            };

            yearCtrl1.onYearChanged += (ss, ee) => { _year = yearCtrl1.Year; updateTableAndChart(); };

            intervalCtrl1.onIntervalChanged += (ss, ee) =>
            {
                _interval                     = intervalCtrl1.Interval;
                subbasinMap1.Interval         = _interval;
                cmbObservedColumns.DataSource = null;
                updateTableAndChart();
            };
        }
Example #5
0
        /// <summary>
        /// For result display view
        /// </summary>
        /// <param name="project"></param>
        /// <param name="scenario"></param>
        /// <param name="type"></param>
        public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            if (type != ArcSWAT.SWATUnitType.SUB && type != ArcSWAT.SWATUnitType.RCH &&
                type != ArcSWAT.SWATUnitType.HRU && type != ArcSWAT.SWATUnitType.RES)
            {
                return;
            }

            _project  = project;
            _scenario = scenario;
            _type     = type;

            this.MapFrame.ProjectionModeDefine    = DotSpatial.Controls.ActionMode.Always;
            this.MapFrame.ProjectionModeReproject = DotSpatial.Controls.ActionMode.Never;
            this.Resized += (ss, ee) => { this.ZoomToMaxExtent(); };

            this.Layers.Clear();

            if (type == ArcSWAT.SWATUnitType.SUB)
            {
                _workingLayer = addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, true);
                addLayer(project.Spatial.ReachShapefile, "Reach", false, false);
            }
            else if (type == ArcSWAT.SWATUnitType.RCH)
            {
                addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, false);
                _workingLayer = addLayer(project.Spatial.ReachShapefile, "Reach", false, true);
            }
            else if (type == ArcSWAT.SWATUnitType.HRU)
            {
                _workingLayer = addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, true);
                addLayer(project.Spatial.ReachShapefile, "Reach", false, false);
            }
            else if (type == ArcSWAT.SWATUnitType.RES)
            {
                addLayer(project.Spatial.SubbasinShapefile, "Subbasin", false, false);
                addLayer(project.Spatial.ReachShapefile, "Reach", false, false);
                _workingLayer = addLayer(project.Spatial.MonitoringShapefile, "Reservoir", false, true);
            }
            this.FunctionMode = DotSpatial.Controls.FunctionMode.Select;
        }
Example #6
0
        public void setScenarioAndUnit(ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            this.Nodes.Clear();

            if (scenario == null)
            {
                return;
            }
            if (type == ArcSWAT.SWATUnitType.UNKNOWN)
            {
                return;
            }

            StringCollection tbls = scenario.Structure.getResultTablesWithData(type);

            if (tbls.Count == 0)
            {
                return;
            }

            foreach (string tbl in tbls)
            {
                TreeNode tblNode = Nodes.Add(tbl);

                StringCollection cols = scenario.Structure.getDataColumns(tbl);
                foreach (string col in cols)
                {
                    tblNode.Nodes.Add(col);
                }

                tblNode.ExpandAll();
            }
            //if (Nodes.Count > 0 && Nodes[0].Nodes.Count > 0)
            //    OnNodeMouseClick(new TreeNodeMouseClickEventArgs(
            //        Nodes[0].Nodes[0], System.Windows.Forms.MouseButtons.Left, -1, -1, -1));
        }
Example #7
0
        public ProjectTree()
        {
            NodeMouseClick += (s, e) =>
            {
                if (onResultLevelChanged == null)
                {
                    return;
                }
                _scenarioResult = null;

                if (e.Node == null)
                {
                    return;
                }

                ArcSWAT.SWATUnitType type = ArcSWAT.SWATUnitType.UNKNOWN;
                if (e.Node.Text.Equals("Watershed"))
                {
                    type = ArcSWAT.SWATUnitType.WSHD;
                }
                else if (e.Node.Text.Equals("HRU"))
                {
                    type = ArcSWAT.SWATUnitType.HRU;
                }
                else if (e.Node.Text.Equals("Subbasin"))
                {
                    type = ArcSWAT.SWATUnitType.SUB;
                }
                else if (e.Node.Text.Equals("Reach"))
                {
                    type = ArcSWAT.SWATUnitType.RCH;
                }
                else if (e.Node.Text.Equals("Reservoir"))
                {
                    type = ArcSWAT.SWATUnitType.RES;
                }

                if (type != ArcSWAT.SWATUnitType.UNKNOWN)
                {
                    onResultLevelChanged(e.Node.Tag as ArcSWAT.ScenarioResult, (ArcSWAT.SWATModelType)e.Node.Parent.Tag, type);
                }

                //click on scenario node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.Scenario && onScenarioSelectionChanged != null)
                {
                    onScenarioSelectionChanged(e.Node.Tag as ArcSWAT.Scenario);
                }

                //click on model node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.SWATModelType && e.Node.Nodes.Count > 0 && e.Node.Nodes[0].Tag != null && e.Node.Nodes[0].Tag is ArcSWAT.ScenarioResult)
                {
                    onResultLevelChanged(e.Node.Nodes[0].Tag as ArcSWAT.ScenarioResult, (ArcSWAT.SWATModelType)e.Node.Tag, ArcSWAT.SWATUnitType.WSHD);
                }

                //click on project node
                if (e.Node.Tag != null && e.Node.Tag is ArcSWAT.Project && onProjectNodeSelected != null)
                {
                    onProjectNodeSelected(this, new EventArgs());
                }

                //click on difference node
                if (e.Node.Text.Equals("Difference") && e.Node.Tag != null && e.Node.Tag is ArcSWAT.ScenarioResult && onDifferenceNodeSelected != null)
                {
                    _scenarioResult = e.Node.Tag as ArcSWAT.ScenarioResult;
                    onDifferenceNodeSelected(this, new EventArgs());
                }

                //click on difference node
                if (e.Node.Text.Equals("Performance") && e.Node.Tag != null && e.Node.Tag is ArcSWAT.ScenarioResult && onPerformanceNodeSelected != null)
                {
                    _scenarioResult = e.Node.Tag as ArcSWAT.ScenarioResult;
                    onPerformanceNodeSelected(this, new EventArgs());
                }
            };
        }
        public PerformanceView()
        {
            InitializeComponent();

            this.Resize += (s, e) =>
            {
                this.splitContainer1.SplitterDistance = this.Height - 250;
            }; //always set the height of chart as 250

            cmbSplitYear.SelectedIndexChanged += (s, e) => {
                updatePerformanceTable();
            };

            this.dataGridView1.ReadOnly  = true;
            this.dataGridView1.RowEnter += (s, e) =>
            {
                if (e.RowIndex < 0)
                {
                    return;
                }

                try
                {
                    //get selected unit type and id
                    string unitType = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    if (unitType == ArcSWAT.SWATUnitType.RCH.ToString())
                    {
                        _unitType = ArcSWAT.SWATUnitType.RCH;
                    }
                    else if (unitType == ArcSWAT.SWATUnitType.RES.ToString())
                    {
                        _unitType = ArcSWAT.SWATUnitType.RES;
                    }
                    else
                    {
                        return;
                    }

                    //get the id
                    _id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());

                    //get column
                    _col = ArcSWAT.ObservationData.getObservationSWATColumn(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());

                    //get current result
                    _currentResult = getResult(_result);

                    //get statistic info for each hydrological year
                    _statisticTable = _currentResult.UnitResult.getYearlyPerformanceTable(_col, _statisticType);
                    this.dataGridView2.DataSource = _statisticTable;

                    //----
                    //show scatter plot
                    this.outputDisplayChart_Scatter1.draw(_currentResult, ArcSWAT.SeasonType.WholeYear);
                }
                catch { }
            };

            this.dataGridView2.ReadOnly  = true;
            this.dataGridView2.RowEnter += (s, e) =>
            {
                if (e.RowIndex < 0)
                {
                    return;
                }
                if (_currentResult == null)
                {
                    return;
                }

                try
                {
                    //get year
                    _year = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString());

                    //show the compared data chart
                    this.outputDisplayChart1.Result = _currentResult.UnitResult.getResult(_col, _year);
                }
                catch { }
            };

            //change the season type of chart when choose different column
            this.dataGridView2.ColumnHeaderMouseClick += (s, e) =>
            {
                if (e.ColumnIndex <= 0)
                {
                    return;
                }
                this.outputDisplayChart1.Season = (ArcSWAT.SeasonType)(e.ColumnIndex);
                if (this.outputDisplayChart1.DataSource != null)
                {
                    this.outputDisplayChart1.Result = _currentResult.UnitResult.getResult(_col, _year);
                }
            };

            compareCtrl1.onCompareResultChanged += (s, e) =>
            {
                if (compareCtrl1.CompareResult == null)
                {
                    return;
                }

                ArcSWAT.SWATUnitColumnYearResult r = getResult(compareCtrl1.CompareResult);
                if (r == null)
                {
                    return;
                }

                _comparedStatisticTable = r.UnitResult.getYearlyPerformanceTable(_col, _statisticType);

                updateComparedTable();
            };
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { updateComparedTable(); };

            dataGridView3.RowEnter += (s, e) =>
            {
                try
                {
                    //get year
                    int year = Convert.ToInt32(dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString());

                    //show the compared data chart
                    this.outputDisplayChart1.CompareResult = _currentResult.UnitResult.getResult(_col, year).Compare(compareCtrl1.CompareResult);
                }
                catch { }
            };

            this.cmbStatisticTypes.SelectedIndexChanged += (s, e) =>
            {
                if (cmbStatisticTypes.SelectedIndex == -1)
                {
                    return;
                }
                ArcSWAT.StatisticCompareType type = (ArcSWAT.StatisticCompareType)(cmbStatisticTypes.SelectedIndex);
                if (type == _statisticType)
                {
                    return;
                }
                _statisticType = type;

                updatePerformanceTable();
            };
        }
Example #9
0
        private IFeatureLayer addLayer(string path, string name, bool isForObserved, bool isWorkingLayer)
        {
            Debug.WriteLine(DateTime.Now);
            Debug.WriteLine("Adding Layer..., " + name);

            if (!System.IO.File.Exists(path))
            {
                Debug.WriteLine(path + " doesn't exist!");
                return(null);
            }

            IFeatureLayer layer = this.Layers.Add(path) as IFeatureLayer;

            layer.SelectionEnabled = isWorkingLayer;
            layer.LegendText       = name;

            foreach (DataColumn col in layer.DataSet.DataTable.Columns)
            {
                col.ColumnName = col.ColumnName.ToLower();
            }

            //working layer and result display
            if (isWorkingLayer && !isForObserved)
            {
                //add result column
                DataTable dt = layer.DataSet.DataTable;
                dt.Columns.Add(RESULT_COLUMN, typeof(double));

                //create schema for result display
                layer.Symbology.EditorSettings.ClassificationType     = ClassificationType.Quantities;
                layer.Symbology.EditorSettings.FieldName              = RESULT_COLUMN;
                layer.Symbology.EditorSettings.IntervalMethod         = IntervalMethod.Quantile;
                layer.Symbology.EditorSettings.IntervalSnapMethod     = IntervalSnapMethod.SignificantFigures;
                layer.Symbology.EditorSettings.IntervalRoundingDigits = 3; //3 significant number
                layer.Symbology.EditorSettings.StartSize              = 5;
                layer.Symbology.EditorSettings.EndSize      = 25;
                layer.Symbology.EditorSettings.NumBreaks    = 5;
                layer.Symbology.EditorSettings.UseSizeRange = true;

                //start and end color
                layer.Symbology.EditorSettings.StartColor = Color.Green;
                layer.Symbology.EditorSettings.EndColor   = Color.Red;
            }

            //set normal symbol
            //for result display, this is just the initial symbol. The symbol would be updated based on result
            //after the result is retrieved.
            if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Polygon) //subbasin
            {
                layer.Symbolizer = new PolygonSymbolizer(System.Drawing.Color.LightGray, System.Drawing.Color.Black, 0.5);

                //show label for subbasin
                MapLabelLayer label = new MapLabelLayer();
                label.Symbology.Categories[0].Expression = "[" + ID_COLUMN_NAME + "]";
                layer.LabelLayer = label;
                layer.ShowLabels = true;
            }
            else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Line) //reach
            {
                layer.Symbolizer = new LineSymbolizer(System.Drawing.Color.Blue, 3.0);

                //set selection sysmbol for reach as wider red to make it more obvious
                layer.SelectionSymbolizer = new LineSymbolizer(System.Drawing.Color.Red, 3.0);
            }
            else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point) //reservoir
            {
                //set the symbol color,shape and size
                layer.Symbolizer          = new PointSymbolizer(Color.Green, DotSpatial.Symbology.PointShape.Hexagon, 20.0);
                layer.SelectionSymbolizer = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0);


                //also set to just show reservoir
                //first to see if there are some reservoir there Type = R
                if (layer.DataSet.DataTable.Rows.Count == 0)
                {
                    Layers.Remove(layer as IMapLayer); return(null);
                }

                int reservoirNum = int.Parse(layer.DataSet.DataTable.Compute("count(" + ID_COLUMN_NAME + ")", "type = 'R' or type = 'r'").ToString());
                if (reservoirNum <= 0)
                {
                    Layers.Remove(layer as IMapLayer); return(null);
                }

                //only show reservoir
                List <int> hiddenMoniterPoints = new List <int>();
                for (int i = 0; i < layer.DataSet.DataTable.Rows.Count; i++)
                {
                    ArcSWAT.RowItem item = new ArcSWAT.RowItem(layer.DataSet.DataTable.Rows[i]);
                    string          type = item.getColumnValue_String("type");

                    if (!type.Equals("R") && !type.Equals("r"))
                    {
                        hiddenMoniterPoints.Add(i);
                    }
                }
                layer.RemoveFeaturesAt(hiddenMoniterPoints);
            }

            //add a column to show if the feature has observed data
            if (isForObserved)
            {
                //add observed column
                DataTable dt = layer.DataSet.DataTable;
                dt.Columns.Add(OBSERVED_COLUMN, typeof(int));


                //create schema observed column to make feature with observed data more obvious
                if (layer.DataSet.FeatureType != DotSpatial.Topology.FeatureType.Polygon)
                {
                    layer.Symbology.ClearCategories();

                    //get the observed data status
                    ArcSWAT.SWATUnitType unitType = ArcSWAT.SWATUnitType.RCH;
                    if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point)
                    {
                        unitType = ArcSWAT.SWATUnitType.RES;
                    }

                    foreach (DataRow r in layer.DataSet.DataTable.Rows)
                    {
                        int id = getIDFromFeatureRow(r);
                        if (_project.Observation(Interval).getObservedData(unitType, id).Count > 0)
                        {
                            r[OBSERVED_COLUMN] = 1;
                        }
                        else
                        {
                            r[OBSERVED_COLUMN] = 0;
                        }
                    }

                    //set the category
                    IFeatureCategory cat_observed = layer.Symbology.CreateNewCategory(Color.Blue, 3.0) as IFeatureCategory;
                    cat_observed.FilterExpression = string.Format("[{0}]=0", OBSERVED_COLUMN.ToUpper());

                    IFeatureCategory cat_no_observed = layer.Symbology.CreateNewCategory(Color.Red, 3.0) as IFeatureCategory;
                    cat_no_observed.FilterExpression = string.Format("[{0}]=1", OBSERVED_COLUMN.ToUpper());

                    //for reservoir, change default size and shape
                    if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point)
                    {
                        cat_observed.SelectionSymbolizer    = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0);
                        cat_no_observed.SelectionSymbolizer = new PointSymbolizer(Color.Cyan, DotSpatial.Symbology.PointShape.Hexagon, 20.0);

                        ((cat_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).Size    = new Size2D(20.0, 20.0);
                        ((cat_no_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).Size = new Size2D(20.0, 20.0);

                        ((cat_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).PointShape    = DotSpatial.Symbology.PointShape.Hexagon;
                        ((cat_no_observed.Symbolizer as PointSymbolizer).Symbols[0] as SimpleSymbol).PointShape = DotSpatial.Symbology.PointShape.Hexagon;
                    }

                    layer.Symbology.AddCategory(cat_observed);
                    layer.Symbology.AddCategory(cat_no_observed);

                    layer.ApplyScheme(layer.Symbology);
                }
            }

            if (isWorkingLayer)
            {
                layer.SelectionEnabled = true;

                //for selection changed event
                layer.SelectionChanged += (ss, _e) =>
                {
                    if (onLayerSelectionChanged == null)
                    {
                        return;
                    }

                    ArcSWAT.SWATUnitType unitType = ArcSWAT.SWATUnitType.SUB;
                    if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Point)
                    {
                        unitType = ArcSWAT.SWATUnitType.RES;
                    }
                    else if (layer.DataSet.FeatureType == DotSpatial.Topology.FeatureType.Line)
                    {
                        unitType = ArcSWAT.SWATUnitType.RCH;
                    }

                    int id = -1;
                    if (layer.Selection.NumRows() > 0)
                    {
                        IFeature fea = layer.Selection.ToFeatureList()[0];
                        id = getIDFromFeatureRow(fea.DataRow);
                    }
                    onLayerSelectionChanged(unitType, id);
                    _id = id;
                };
            }

            return(layer);
        }
Example #10
0
        private UserControl getView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            string key = getViewName(scenario, modelType, interval, unitType);

            if (!_views.ContainsKey(key))
            {
                if (unitType == ArcSWAT.SWATUnitType.WSHD)
                {
                    WatershedView view = new WatershedView();
                    view.Dock = DockStyle.Fill;
                    view.setProjectScenario(_prj, scenario.getModelResult(modelType, interval));
                    view.onDataStatisticsChanged += (ss, ee) => { onDataStatisticsChanged(view); };

                    _views.Add(key, view);
                }
                else
                {
                    SubbasinView view = new SubbasinView();
                    view.Dock = DockStyle.Fill;

                    view.onMapTimeChanged        += (ss, ee) => { onMapTimeChanged(view); };
                    view.onMapSelectionChanged   += (ss, ee) => { onMapSelectionChanged(view); };
                    view.onDataStatisticsChanged += (ss, ee) => { onDataStatisticsChanged(view); };

                    view.setProjectScenario(_prj, scenario.getModelResult(modelType, interval), unitType);

                    if (unitType == ArcSWAT.SWATUnitType.SUB)
                    {
                        view.onSwitch2HRU += (hru) =>
                        {
                            SubbasinView hruview = switchView(_scenario, _modelType, interval, ArcSWAT.SWATUnitType.HRU) as SubbasinView;
                            hruview.HRU = hru;
                        }
                    }
                    ;
                    _views.Add(key, view);
                }
            }
            return(_views[key]);
        }
Example #11
0
 private string getViewName(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
 {
     return(string.Format("{0}_{1}_{2}_{3}",
                          scenario.Name, modelType, interval, unitType));
 }
Example #12
0
        private void removeView(ArcSWAT.Scenario scenario, ArcSWAT.SWATModelType modelType, ArcSWAT.SWATResultIntervalType interval, ArcSWAT.SWATUnitType unitType)
        {
            string key = getViewName(scenario, modelType, interval, unitType);

            if (_views.ContainsKey(key))
            {
                _views.Remove(key);
            }
        }
Example #13
0
        public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            _project  = project;
            _scenario = scenario;
            _type     = type;
            _date     = new DateTime(scenario.StartYear, 1, 1);
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }

            if (type == ArcSWAT.SWATUnitType.SUB)
            {
                _unitList = _scenario.Subbasins;
            }
            else if (type == ArcSWAT.SWATUnitType.RCH)
            {
                _unitList = _scenario.Reaches;
            }
            else if (type == ArcSWAT.SWATUnitType.HRU)
            {
                _unitList = _scenario.HRUs;
            }
            else if (type == ArcSWAT.SWATUnitType.RES)
            {
                _unitList = _scenario.Reservoirs;
            }

            this.Resize += (ss, ee) => { splitContainer3.SplitterDistance = 72; };

            //swat input files extension list
            swatFileList1.SWATUnitType = _type;
            swatFileList1.onSWATInputFileExtensionChanged += (s, e) =>
            {
                if (_unit == null)
                {
                    return;
                }
                string fileName = _unit.getInputFileName(swatFileList1.Extension);
                if (!System.IO.File.Exists(fileName))
                {
                    SWAT_SQLite.showInformationWindow(fileName + " doesn't exist!");
                    return;
                }

                string notePad = System.Environment.SystemDirectory + @"\notepad.exe";
                if (System.IO.File.Exists(notePad))
                {
                    System.Diagnostics.Process.Start(notePad, fileName);
                }
            };

            //id list
            if (type == ArcSWAT.SWATUnitType.HRU)
            {
                idList1.IDs = scenario.getSWATUnitIDs(ArcSWAT.SWATUnitType.SUB);
            }
            else
            {
                idList1.IDs = scenario.getSWATUnitIDs(type);
            }

            idList1.onIDChanged += (s, e) => { onIDChanged(idList1.ID); subbasinMap1.ID = idList1.ID; };

            //season control
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { tableView1.Season = seasonCtrl1.Season; outputDisplayChart1.Season = seasonCtrl1.Season; updateTableAndChart(); };

            //year control
            yearCtrl1.Scenario       = scenario;
            yearCtrl1.onYearChanged += (s, e) => { updateTableAndChart(); };

            //only for subbasin to show hru list
            hruList1.Visible            = (type == ArcSWAT.SWATUnitType.SUB || type == ArcSWAT.SWATUnitType.HRU);
            hruList1.IsChangeWhenSelect = (type == ArcSWAT.SWATUnitType.HRU);
            hruList1.onSwitch2HRU      += (hru) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    if (_unit != null && _unit.ID == hruList1.HRU.ID)
                    {
                        return;
                    }

                    _unit = hruList1.HRU;

                    //show basic information
                    if (onMapSelectionChanged != null)
                    {
                        onMapSelectionChanged(this, new EventArgs());
                    }

                    //update table and chart
                    updateTableAndChart();
                }
                if (_type == ArcSWAT.SWATUnitType.SUB)
                {
                    if (onSwitch2HRU != null)
                    {
                        onSwitch2HRU(hru);
                    }
                }
            };

            //columns
            resultColumnTree1.onResultTypeAndColumnChanged += (resultType, col) =>
            {
                _resultType = resultType;
                _col        = col;

                //only for daily and monthly
                this.yearCtrl1.Visible = _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.DAILY ||
                                         _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.MONTHLY;

                updateMap();
                updateTableAndChart();
            };
            resultColumnTree1.setScenarioAndUnit(scenario, type);

            //map
            subbasinMap1.onLayerSelectionChanged += (unitType, id) => { onIDChanged(id); idList1.ID = id; };
            subbasinMap1.setProjectScenario(project, scenario, type);

            //chart export
            outputDisplayChart1.onExport += (s, e) =>
            {
            };

            //table view
            tableView1.onDateChanged += (d) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    return;
                }
                _date = d;
                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
                updateMap();
            };

            //compare control
            compareCtrl1.ScenarioResult          = scenario;
            compareCtrl1.onCompareResultChanged += (ss, ee) =>
            {
                updateTableAndChart();
            };


            //update
            updateMap();
            updateTableAndChart();
        }
Example #14
0
        public void setProjectScenario(ArcSWAT.Project project, ArcSWAT.ScenarioResult scenario, ArcSWAT.SWATUnitType type)
        {
            _project  = project;
            _scenario = scenario;
            _type     = type;
            _date     = new DateTime(scenario.StartYear, 1, 1);
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }

            if (type == ArcSWAT.SWATUnitType.SUB)
            {
                _unitList = _scenario.Subbasins;
            }
            else if (type == ArcSWAT.SWATUnitType.RCH)
            {
                _unitList = _scenario.Reaches;
            }
            else if (type == ArcSWAT.SWATUnitType.HRU)
            {
                _unitList = _scenario.HRUs;
            }
            else if (type == ArcSWAT.SWATUnitType.RES)
            {
                _unitList = _scenario.Reservoirs;
            }

            this.Resize += (ss, ee) => { splitContainer3.SplitterDistance = 72; };

            //swat input files extension list
            swatFileList1.SWATUnitType = _type;
            swatFileList1.onSWATInputFileExtensionChanged += (s, e) =>
            {
                if (_unit == null)
                {
                    return;
                }
                string fileName = _unit.getInputFileName(swatFileList1.Extension);
                if (!System.IO.File.Exists(fileName))
                {
                    SWAT_SQLite.showInformationWindow(fileName + " doesn't exist!");
                    return;
                }

                string notePad = System.Environment.SystemDirectory + @"\notepad.exe";
                if (System.IO.File.Exists(notePad))
                {
                    System.Diagnostics.Process.Start(notePad, fileName);
                }
            };

            //id list
            if (type == ArcSWAT.SWATUnitType.HRU)
            {
                idList1.IDs = scenario.getSWATUnitIDs(ArcSWAT.SWATUnitType.SUB);
            }
            else
            {
                idList1.IDs = scenario.getSWATUnitIDs(type);
            }

            idList1.onIDChanged += (s, e) => { onIDChanged(idList1.ID); subbasinMap1.ID = idList1.ID; setMapTalbeIDSelection(idList1.ID); };

            //season control
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { tableView1.Season = seasonCtrl1.Season; outputDisplayChart1.Season = seasonCtrl1.Season; updateTableAndChart(); };

            //year control
            yearCtrl1.Scenario       = scenario;
            yearCtrl1.onYearChanged += (s, e) =>
            {
                //update the summary type control
                summaryTypeCtrl1.CurrentYear = yearCtrl1.Year;

                //update the time step map view and summary control
                if (yearCtrl1.Year != -1)
                {
                    _date = new DateTime(yearCtrl1.Year, 1, 1);
                    summaryTypeCtrl1.TimeForTimeStep = _date;

                    //update the status bar
                    if (onMapTimeChanged != null)
                    {
                        onMapTimeChanged(this, new EventArgs());
                    }
                }

                //update map
                if (_summaryType != ArcSWAT.ResultSummaryType.AVERAGE_ANNUAL) //only update map when it's not average annual
                {
                    this.updateMap();
                }

                updateTableAndChart();
            };

            //summary type control for map
            summaryTypeCtrl1.ScenarioResult        = scenario;
            summaryTypeCtrl1.onSummaryTypeChanged += (s, e) =>
            {
                _summaryType = summaryTypeCtrl1.SummaryType;
                this.updateMap();                     //update the status bar
                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
            };

            //only for subbasin to show hru list
            hruList1.Visible            = (type == ArcSWAT.SWATUnitType.SUB || type == ArcSWAT.SWATUnitType.HRU);
            hruList1.IsChangeWhenSelect = (type == ArcSWAT.SWATUnitType.HRU);
            hruList1.onSwitch2HRU      += (hru) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    if (_unit != null && _unit.ID == hruList1.HRU.ID)
                    {
                        return;
                    }

                    _unit = hruList1.HRU;

                    //show basic information
                    if (onMapSelectionChanged != null)
                    {
                        onMapSelectionChanged(this, new EventArgs());
                    }

                    //update table and chart
                    updateTableAndChart();
                }
                if (_type == ArcSWAT.SWATUnitType.SUB)
                {
                    if (onSwitch2HRU != null)
                    {
                        onSwitch2HRU(hru);
                    }
                }
            };

            //columns
            resultColumnTree1.onResultTypeAndColumnChanged += (resultType, col) =>
            {
                _resultType = resultType;
                _col        = col;

                //only for daily and monthly
                this.yearCtrl1.Visible = _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.DAILY ||
                                         _scenario.Structure.getInterval(_resultType) == ArcSWAT.SWATResultIntervalType.MONTHLY;

                updateMap();
                updateTableAndChart();
            };
            resultColumnTree1.setScenarioAndUnit(scenario, type);

            //the id selection changed
            tblMapData.RowHeadersVisible = false;
            tblMapData.ReadOnly          = true;
            tblMapData.Sorted           += (s, e) =>
            {
                //System.Diagnostics.Debug.WriteLine("--------");
                //foreach (DataGridViewRow r in tblMapData.Rows)
                //{
                //    if (r.Cells[0].Value == null) continue;
                //    System.Diagnostics.Debug.WriteLine(r.Cells[0].Value);
                //}
            };
            tblMapData.RowEnter += onMapTableIDChanged;

            //map
            subbasinMap1.onLayerSelectionChanged += (unitType, id) => { onIDChanged(id); idList1.ID = id; setMapTalbeIDSelection(id); };
            subbasinMap1.setProjectScenario(project, scenario, type);
            subbasinMap1.onMapUpdated += (s, e) =>
            {
                //get current selected id on map
                //if none is selected, will be -1
                //will keep the current the selection when the datasource of map data table view is changed
                int id = subbasinMap1.ID;
                if (id > 0)
                {
                    this.tblMapData.RowEnter -= onMapTableIDChanged;            //remove the handler, don't need to do this when none is selected
                }
                this.tblMapData.DataSource = subbasinMap1.DataTable;            //set data
                if (id > 0)
                {
                    setMapTalbeIDSelection(id);                                 //use current selected id, don't change to a new one
                    this.tblMapData.RowEnter += onMapTableIDChanged;            //resume the handler
                }

                tblMapData.Columns[SubbasinMap.ID_COLUMN_NAME].HeaderText             = _resultType.ToString().ToLower();
                tblMapData.Columns[SubbasinMap.RESULT_COLUMN].HeaderText              = _col;
                tblMapData.Columns[SubbasinMap.RESULT_COLUMN].DefaultCellStyle.Format = "F4";
            };

            //chart export
            outputDisplayChart1.onExport += (s, e) =>
            {
            };

            //table view
            tableView1.onDateChanged += (d) =>
            {
                if (_type == ArcSWAT.SWATUnitType.HRU)
                {
                    return;
                }
                _date = d;
                summaryTypeCtrl1.TimeForTimeStep = d;

                if (onMapTimeChanged != null)
                {
                    onMapTimeChanged(this, new EventArgs());
                }
                if (_summaryType == ArcSWAT.ResultSummaryType.TIMESTEP)
                {
                    updateMap();
                }
            };

            //compare control
            compareCtrl1.ScenarioResult          = scenario;
            compareCtrl1.onCompareResultChanged += (ss, ee) =>
            {
                updateTableAndChart();
            };


            //update
            updateMap();
            updateTableAndChart();

            //update the status bar
            if (onMapTimeChanged != null)
            {
                onMapTimeChanged(this, new EventArgs());
            }
        }
        public PerformanceView()
        {
            InitializeComponent();

            this.Resize += (s, e) =>
            {
                this.splitContainer1.SplitterDistance = this.Height - 250;
            }; //always set the height of chart as 250

            cmbSplitYear.SelectedIndexChanged += (s, e) => {
                updatePerformanceTable();
            };

            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowEnter += (s, e) =>
            {
                if (e.RowIndex < 0) return;

                try
                {
                    //get selected unit type and id
                    string unitType = dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
                    if (unitType == ArcSWAT.SWATUnitType.RCH.ToString())
                        _unitType = ArcSWAT.SWATUnitType.RCH;
                    else if (unitType == ArcSWAT.SWATUnitType.RES.ToString())
                        _unitType = ArcSWAT.SWATUnitType.RES;
                    else
                        return;

                    //get the id
                    _id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString());

                    //get column
                    _col = ArcSWAT.ObservationData.getObservationSWATColumn(dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString());

                    //get current result
                    _currentResult = getResult(_result);

                    //get statistic info for each hydrological year
                    _statisticTable = _currentResult.UnitResult.getYearlyPerformanceTable(_col,_statisticType);
                    this.dataGridView2.DataSource = _statisticTable;

                    //----
                    //show scatter plot
                    this.outputDisplayChart_Scatter1.draw(_currentResult, ArcSWAT.SeasonType.WholeYear);
                }
                catch { }

            };

            this.dataGridView2.ReadOnly = true;
            this.dataGridView2.RowEnter += (s, e) =>
                {
                    if (e.RowIndex < 0) return;
                    if (_currentResult == null) return;

                    try
                    {
                        //get year
                        _year = Convert.ToInt32(dataGridView2.Rows[e.RowIndex].Cells[0].Value.ToString());

                        //show the compared data chart
                        this.outputDisplayChart1.Result = _currentResult.UnitResult.getResult(_col, _year);
                    }
                    catch { }

                };

            //change the season type of chart when choose different column
            this.dataGridView2.ColumnHeaderMouseClick += (s, e) =>
                {
                    if (e.ColumnIndex <= 0) return;
                    this.outputDisplayChart1.Season = (ArcSWAT.SeasonType)(e.ColumnIndex);
                    if(this.outputDisplayChart1.DataSource != null)
                        this.outputDisplayChart1.Result = _currentResult.UnitResult.getResult(_col, _year);
                };

            compareCtrl1.onCompareResultChanged += (s, e) =>
                {
                    if (compareCtrl1.CompareResult == null) return;

                    ArcSWAT.SWATUnitColumnYearResult r = getResult(compareCtrl1.CompareResult);
                    if(r == null) return;

                    _comparedStatisticTable = r.UnitResult.getYearlyPerformanceTable(_col,_statisticType);

                    updateComparedTable();
                };
            seasonCtrl1.onSeasonTypeChanged += (s, e) => { updateComparedTable(); };

            dataGridView3.RowEnter += (s, e) =>
                {
                    try
                    {
                        //get year
                        int year = Convert.ToInt32(dataGridView3.Rows[e.RowIndex].Cells[0].Value.ToString());

                        //show the compared data chart
                        this.outputDisplayChart1.CompareResult = _currentResult.UnitResult.getResult(_col, year).Compare(compareCtrl1.CompareResult);
                    }
                    catch { }
                };

            this.cmbStatisticTypes.SelectedIndexChanged += (s, e) =>
                {
                    if (cmbStatisticTypes.SelectedIndex == -1) return;
                    ArcSWAT.StatisticCompareType type = (ArcSWAT.StatisticCompareType)(cmbStatisticTypes.SelectedIndex);
                    if (type == _statisticType) return;
                    _statisticType = type;

                    updatePerformanceTable();
                };
        }