Пример #1
0
        public Reservoir(DataRow resInfoRow, ScenarioResult scenario)
            : base(resInfoRow, scenario)
        {
            RowItem item = new RowItem(resInfoRow);

            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RES);
        }
Пример #2
0
        public Subbasin(DataRow subInfoRow, ScenarioResult scenario)
            : base(subInfoRow, scenario)
        {
            RowItem item = new RowItem(subInfoRow);

            _id           = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);
            _area         = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_wshd = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);
        }
Пример #3
0
        public HRU(DataRow hruInfoRow, ScenarioResult scenario)
            : base(hruInfoRow,scenario)
        {
            RowItem item = new RowItem(hruInfoRow);
            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU);
            _seqIdInSubbasin = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU_SEQ);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_sub = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_SUB);
            _area_fr_wshd = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);

            //connect hru and subbasin
            int subid = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);
            if (scenario.Subbasins.ContainsKey(subid))
            {
                _sub = scenario.Subbasins[subid] as Subbasin;
                if (_sub != null) _sub.addHRU(this);
            }
        }
Пример #4
0
        private void checkStatus()
        {
            if (DatabasePath == null || !File.Exists(DatabasePath))
            {
                _status = ScenarioResultStatus.NO_EXIST; return;
            }

            DataTable dt = Query.GetDataTable("select * from " + ScenarioResultStructure.TABLE_NAME_WATERSHED_AVERAGE_ANNUAL, DatabasePath);

            if (dt.Rows.Count == 0)
            {
                _status = ScenarioResultStatus.UNSUCCESS; return;
            }

            foreach (DataRow r in dt.Rows)
            {
                RowItem item = new RowItem(r);
                string  name = item.getColumnValue_String("NAME");
                if (name.Equals(ScenarioResultStructure.NAME_STATUS_START_YEAR))
                {
                    _startYear = item.getColumnValue_Int("VALUE");
                }
                else if (name.Equals("END_YEAR"))
                {
                    _endYear = item.getColumnValue_Int("VALUE");
                }
                else if (name.Equals("OUTPUT_INTERVAL"))
                {
                    _interval = (SWATResultIntervalType)(item.getColumnValue_Int("VALUE"));
                }
                else if (name.Equals("SUCCESS"))
                {
                    _status = ScenarioResultStatus.NORMAL;
                }
            }

            //some version don't have this output, need to upgrade
            if (_startYear == ScenarioResultStructure.UNKONWN_ID)
            {
                throw new Exception("Missing output starting year. Please upgrade your SWAT executable.");
            }

            _generationTime = (new System.IO.FileInfo(DatabasePath)).LastWriteTime;
        }
Пример #5
0
        public Reach(DataRow rchInfoRow, ScenarioResult scenario)
            : base(rchInfoRow, scenario)
        {
            RowItem item = new RowItem(rchInfoRow);
            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RCH);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);

            if (scenario.Subbasins.ContainsKey(_id))
                _sub = scenario.Subbasins[_id] as Subbasin;
        }
Пример #6
0
        private void calculateDate(DataRow r)
        {
            DateTime d     = DateTime.Now;
            RowItem  item  = new RowItem(r);
            int      year  = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_YEAR);
            int      month = 1;
            int      day   = 1;

            if (_result.Interval == SWATResultIntervalType.MONTHLY || _result.Interval == SWATResultIntervalType.DAILY)
            {
                month = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_MONTH);
            }
            if (_result.Interval == SWATResultIntervalType.DAILY)
            {
                day = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_DAY);
            }

            r[SWATUnitResult.COLUMN_NAME_DATE] = new DateTime(year, month, day);
        }
Пример #7
0
        private void loadData(SWATUnitType type, int id, string col)
        {
            if (!_exist)
            {
                return;
            }

            string    tableName = getTableName(type, id, col);
            DataTable dt        = GetDataTable(
                string.Format("select name from sqlite_master where type = 'table' and name = '{0}'", tableName));

            if (dt.Rows.Count > 0)
            {
                //see if there are some data
                //don't consider empty tables
                dt = GetDataTable(
                    string.Format("select count(*) from [{0}]", tableName));
                if (dt.Rows.Count == 0)
                {
                    return;
                }
                RowItem item = new RowItem(dt.Rows[0]);
                if (item.getColumnValue_Int(0) == 0)
                {
                    return;
                }

                //read data
                string dataUniqueId = getUniqueId(type, id, col);

                //remove previous one
                _allData.Remove(dataUniqueId);
                _allData_display.Remove(dataUniqueId);

                //add new one
                SWATUnitObservationData data =
                    new SWATUnitObservationData(
                        id, type, col,
                        -1, -1,
                        this);

                //add to all data
                _allData.Add(dataUniqueId, data);

                //add to display data
                string display_id = string.Format("{0}_{1}", type, id);
                if (!_allData_display.ContainsKey(display_id))
                {
                    _allData_display.Add(display_id, new List <SWATUnitObservationData>());
                }
                _allData_display[display_id].Add(data);
            }
        }
Пример #8
0
        public HRU(DataRow hruInfoRow, ScenarioResult scenario) : base(hruInfoRow, scenario)
        {
            RowItem item = new RowItem(hruInfoRow);

            _id = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU);
            _seqIdInSubbasin = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_HRU_SEQ);
            _area            = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);
            _area_fr_sub     = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_SUB);
            _area_fr_wshd    = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_FR_WSHD);

            //connect hru and subbasin
            int subid = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_SUB);

            if (scenario.Subbasins.ContainsKey(subid))
            {
                _sub = scenario.Subbasins[subid] as Subbasin;
                if (_sub != null)
                {
                    _sub.addHRU(this);
                }
            }
        }
Пример #9
0
        public Reach(DataRow rchInfoRow, ScenarioResult scenario)
            : base(rchInfoRow, scenario)

        {
            RowItem item = new RowItem(rchInfoRow);

            _id   = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_RCH);
            _area = item.getColumnValue_Double(ScenarioResultStructure.COLUMN_NAME_AREA_KM2);

            if (scenario.Subbasins.ContainsKey(_id))
            {
                _sub = scenario.Subbasins[_id] as Subbasin;
            }
        }
Пример #10
0
        public bool isTableHasData(string tableName)
        {
            tableName = tableName.Trim().ToLower();
            if (!_tableStatus.ContainsKey(tableName))
            {
                bool      hasData = false;
                DataTable dt      = _scenario.GetDataTable(
                    string.Format("select * from sqlite_master where type = 'table' and name ='{0}'", tableName));
                if (dt.Rows.Count > 0)
                {
                    dt = _scenario.GetDataTable(
                        string.Format("select count(*) from {0}", tableName));

                    RowItem item = new RowItem(dt.Rows[0]);
                    if (item.getColumnValue_Int(0) > 0)
                    {
                        hasData = true;
                    }
                }
                _tableStatus[tableName] = hasData;
            }
            return(_tableStatus[tableName]);
        }
        private void calculateDate(DataRow r)
        {
            DateTime d = DateTime.Now;
            RowItem item = new RowItem(r);
            int year = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_YEAR);
            int month = 1;
            int day = 1;
            if (_result.Interval == SWATResultIntervalType.MONTHLY || _result.Interval == SWATResultIntervalType.DAILY)
                month = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_MONTH);
            if (_result.Interval == SWATResultIntervalType.DAILY)
                day = item.getColumnValue_Int(ScenarioResultStructure.COLUMN_NAME_DAY);

            r[SWATUnitResult.COLUMN_NAME_DATE] = new DateTime(year, month, day);
        }
Пример #12
0
        private void loadData(SWATUnitType type)
        {
            if (!_exist) return;

            DataTable dt = GetDataTable("select name from sqlite_master where type = 'table'");
            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    //get table name
                    string tableName = r[0].ToString();
                    if(!tableName.Contains(type.ToString())) continue;

                    //see if there are some data
                    //don't consider empty tables
                    dt = GetDataTable(
                        string.Format("select count(*) from [{0}]", tableName));
                    RowItem item = new RowItem(dt.Rows[0]);
                    if (item.getColumnValue_Int(0) == 0) continue;

                    //extract the id from table name
                    string[] all_in_tableName = tableName.Split(OBSERVATION_TABLE_NAME_DELIMITER);
                    if (all_in_tableName.Length < 3) continue;

                    int id = -1;
                    if (int.TryParse(all_in_tableName[1], out id))
                    {
                        string col = all_in_tableName[2];

                        string dataUniqueId = getUniqueId(type, id, col);

                        if (!_allData.ContainsKey(dataUniqueId))
                        {
                            SWATUnitObservationData data =
                                new SWATUnitObservationData(
                                    id, type, col,
                                    -1, -1,
                                    this);

                            //add to all data
                            _allData.Add(dataUniqueId,data);

                            //add to display data
                            string display_id = string.Format("{0}_{1}",type,id);
                            if (!_allData_display.ContainsKey(display_id))
                                _allData_display.Add(display_id, new List<SWATUnitObservationData>());
                            _allData_display[display_id].Add(data);
                        }
                    }
                }
            }
        }
Пример #13
0
        private void loadData(SWATUnitType type, int id, string col)
        {
            if (!_exist) return;

            string tableName = getTableName(type, id, col);
            DataTable dt = GetDataTable(
                string.Format("select name from sqlite_master where type = 'table' and name = '{0}'", tableName));
            if (dt.Rows.Count > 0)
            {
                //see if there are some data
                //don't consider empty tables
                dt = GetDataTable(
                    string.Format("select count(*) from [{0}]", tableName));
                if (dt.Rows.Count == 0) return;
                RowItem item = new RowItem(dt.Rows[0]);
                if (item.getColumnValue_Int(0) == 0) return;

                //read data
                string dataUniqueId = getUniqueId(type, id, col);

                //remove previous one
                _allData.Remove(dataUniqueId);
                _allData_display.Remove(dataUniqueId);

                //add new one
                SWATUnitObservationData data =
                    new SWATUnitObservationData(
                        id, type, col,
                        -1, -1,
                        this);

                //add to all data
                _allData.Add(dataUniqueId, data);

                //add to display data
                string display_id = string.Format("{0}_{1}", type, id);
                if (!_allData_display.ContainsKey(display_id))
                    _allData_display.Add(display_id, new List<SWATUnitObservationData>());
                _allData_display[display_id].Add(data);
            }
        }
Пример #14
0
 private int getIDFromFeatureRow(DataRow r)
 {
     ArcSWAT.RowItem item = new ArcSWAT.RowItem(r);
     return(item.getColumnValue_Int(ID_COLUMN_NAME));
 }
Пример #15
0
        private void loadData(SWATUnitType type)
        {
            if (!_exist)
            {
                return;
            }

            DataTable dt = GetDataTable("select name from sqlite_master where type = 'table'");

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow r in dt.Rows)
                {
                    //get table name
                    string tableName = r[0].ToString();
                    if (!tableName.Contains(type.ToString()))
                    {
                        continue;
                    }

                    //see if there are some data
                    //don't consider empty tables
                    dt = GetDataTable(
                        string.Format("select count(*) from [{0}]", tableName));
                    RowItem item = new RowItem(dt.Rows[0]);
                    if (item.getColumnValue_Int(0) == 0)
                    {
                        continue;
                    }

                    //extract the id from table name
                    string[] all_in_tableName = tableName.Split(OBSERVATION_TABLE_NAME_DELIMITER);
                    if (all_in_tableName.Length < 3)
                    {
                        continue;
                    }

                    int id = -1;
                    if (int.TryParse(all_in_tableName[1], out id))
                    {
                        string col = all_in_tableName[2];

                        string dataUniqueId = getUniqueId(type, id, col);

                        if (!_allData.ContainsKey(dataUniqueId))
                        {
                            SWATUnitObservationData data =
                                new SWATUnitObservationData(
                                    id, type, col,
                                    -1, -1,
                                    this);

                            //add to all data
                            _allData.Add(dataUniqueId, data);

                            //add to display data
                            string display_id = string.Format("{0}_{1}", type, id);
                            if (!_allData_display.ContainsKey(display_id))
                            {
                                _allData_display.Add(display_id, new List <SWATUnitObservationData>());
                            }
                            _allData_display[display_id].Add(data);
                        }
                    }
                }
            }
        }
Пример #16
0
        private void checkStatus()
        {
            if (DatabasePath == null || !File.Exists(DatabasePath)) { _status = ScenarioResultStatus.NO_EXIST; return; }

            DataTable dt = Query.GetDataTable("select * from " + ScenarioResultStructure.TABLE_NAME_WATERSHED_AVERAGE_ANNUAL, DatabasePath);
            if (dt.Rows.Count == 0) { _status = ScenarioResultStatus.UNSUCCESS; return; }

            foreach (DataRow r in dt.Rows)
            {
                RowItem item = new RowItem(r);
                string name = item.getColumnValue_String("NAME");
                if (name.Equals(ScenarioResultStructure.NAME_STATUS_START_YEAR))
                    _startYear = item.getColumnValue_Int("VALUE");
                else if (name.Equals("END_YEAR"))
                    _endYear = item.getColumnValue_Int("VALUE");
                else if (name.Equals("OUTPUT_INTERVAL"))
                    _interval = (SWATResultIntervalType)(item.getColumnValue_Int("VALUE"));
                else if (name.Equals("SUCCESS"))
                    _status = ScenarioResultStatus.NORMAL;
            }

            //some version don't have this output, need to upgrade
            if (_startYear == ScenarioResultStructure.UNKONWN_ID)
                throw new Exception("Missing output starting year. Please upgrade your SWAT executable.");

            _generationTime = (new System.IO.FileInfo(DatabasePath)).LastWriteTime;
        }