//TODO

        private void Export2Shp_Clicked(object sender, EventArgs e)
        {
            var dc = DataContext as IDendritiRecord <ObservationSeries>;

            if (dc != null)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter   = "csv file|*.csv";
                dlg.FileName = dc.Name + ".csv";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    if (dc.Tag is Heiflow.Core.Data.ODM.Variable)
                    {
                        CSVFileStream csv     = new CSVFileStream(dlg.FileName);
                        string        content = "SiteName,SiteID,Longitude,Latitude,Max,Min,Average,NoDataValue,StandardDeviation,Count\n";
                        foreach (var record in dc.Children)
                        {
                            var site     = record.Value.Site;
                            var statinfo = ODMSource.GetValueStatistics(record.Value);
                            content += string.Format("{0},{1},{2},{3},{4}\n", site.Name, site.ID, site.Longitude, site.Latitude, statinfo.ToString());
                        }
                        content.Trim(TypeConverterEx.Enter);
                        csv.Save(content);
                    }
                }
            }
        }
Esempio n. 2
0
 public override void CustomExport(DataTable source)
 {
     if (source != null)
     {
         var sites   = GetSites(source);
         var setting = _ExportSetting as SiteExportSetting;
         foreach (var site  in sites)
         {
             var series = new ObservationSeries()
             {
                 SiteID     = site.ID,
                 VariableID = setting.VariableID
             };
             var ts = ODM.GetTimeSereis(series);
             if (ts != null)
             {
                 var filename = Path.Combine(setting.Directory, site.Name + ".csv");
                 var var_odm  = ODM.GetVariable(setting.VariableID);
                 ts.Name = var_odm.Name;
                 CSVFileStream csv = new CSVFileStream(filename);
                 csv.Save(ts);
             }
         }
     }
 }
        //TODO

        private void Export2Excel_Clicked(object sender, EventArgs e)
        {
            var dc = DataContext as IDendritiRecord <ObservationSeries>;

            if (dc != null && dc.Children.Count == 0)
            {
                SaveFileDialog dlg = new SaveFileDialog();
                dlg.Filter   = "csv file|*.csv";
                dlg.FileName = dc.Name + ".csv";
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var qc = new QueryCriteria()
                    {
                        SiteID     = dc.Value.SiteID,
                        VariableID = dc.Value.VariableID,
                        AllTime    = true
                    };
                    var ts = ODMSource.GetTimeSeries(qc);
                    if (ts != null)
                    {
                        CSVFileStream csvf = new CSVFileStream(dlg.FileName);
                        csvf.Save(ts);
                    }
                }
            }
        }
Esempio n. 4
0
 public virtual void Export(string filename, System.Data.DataTable source)
 {
     if (source != null)
     {
         CSVFileStream csv = new CSVFileStream(filename);
         csv.Save(source);
     }
 }
        private void btnImport_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Filter = "csv file|*.csv";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                CSVFileStream csv   = new CSVFileStream(dlg.FileName);
                var           array = csv.LoadArray();
                arrayGrid.DataSource = array;
            }
        }
Esempio n. 6
0
        private void btnSave2Excel_Click(object sender, EventArgs e)
        {
            var dt = this.bindingSource1.DataSource as DataTable;

            if (dt != null)
            {
                SaveFileDialog sd = new SaveFileDialog();
                sd.Filter   = "csv file|*.csv";
                sd.FileName = "table.csv";
                if (sd.ShowDialog() == DialogResult.OK)
                {
                    CSVFileStream csv = new CSVFileStream(sd.FileName);
                    csv.Save(dt);
                }
            }
        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (_SelectedDataCubeMeta == null)
            {
                return;
            }

            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Filter   = "csv file|*.csv";
            dlg.FileName = _SelectedDataCubeMeta.Mat.Name + ".csv";
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                CSVFileStream csv = new CSVFileStream(dlg.FileName);
                csv.Save(arrayGrid.DataSource, _SelectedDataCubeMeta.Mat.Variables);
            }
        }
Esempio n. 8
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            var dt = bindingSource1.DataSource as DataTable;

            if (dt != null)
            {
                OpenFileDialog sd = new OpenFileDialog();
                sd.Filter = "csv file|*.csv";
                if (sd.ShowDialog() == DialogResult.OK)
                {
                    CSVFileStream csv = new CSVFileStream(sd.FileName);
                    csv.LoadTo(dt);
                    this.bindingSource1.DataSource = dt;
                    this.dataGridView1.DataSource  = bindingSource1;
                }
            }
        }
Esempio n. 9
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            var dt = dataGridEx1.DataTable;

            if (dt == null)
            {
                return;
            }

            SaveFileDialog sd = new SaveFileDialog();

            sd.Filter   = "csv file|*.csv";
            sd.FileName = "table.csv";
            if (sd.ShowDialog() == DialogResult.OK)
            {
                CSVFileStream csv = new CSVFileStream(sd.FileName);
                csv.Save(dt);
            }
        }
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            DataCubeStreamReader ds = new DataCubeStreamReader(CloudCoverFileName);

            ds.LoadDataCube();
            var           cloudcover  = ds.DataCube;
            CSVFileStream locationcsv = new CSVFileStream(LocationFileName);
            var           locations   = locationcsv.Load <double>();
            StreamReader  sr_dates    = new StreamReader(DateTimeFileName);
            int           ndays       = cloudcover.Size[1];
            int           nlocation   = cloudcover.Size[2];
            var           dates       = new DateTime[ndays];
            int           progress    = 0;
            int           np          = 1;
            var           swmat       = new DataCube <float>(cloudcover.Size[0], cloudcover.Size[1], cloudcover.Size[2]);

            swmat.Name = OutputName;
            for (int i = 0; i < ndays; i++)
            {
                var line = sr_dates.ReadLine();
                dates[i] = DateTime.Parse(line);
            }
            sr_dates.Close();
            for (int i = 0; i < ndays; i++)
            {
                for (int j = 0; j < nlocation; j++)
                {
                    swmat[0, i, j] = (float)_ShortWaveRadiation.DailyIncomingRadiationIntensity(locations.GetValue(j, 1), locations.GetValue(j, 0), dates[i], cloudcover[0, i, j]);
                }
                progress = i * 100 / ndays;
                if (progress == 5 * np)
                {
                    cancelProgressHandler.Progress("Package_Tool", progress, "Processing step: " + progress + "%");
                    np++;
                }
            }
            Workspace.Add(swmat);
            return(true);
        }
Esempio n. 11
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            var           fs_source = FeatureSet.Open(SourceFeatureFile);
            var           fs_target = FeatureSet.Open(TargetFeatureFile);
            CSVFileStream csv       = new CSVFileStream(DataFileName);
            var           ts_data   = csv.Load <double>();

            cancelProgressHandler.Progress("Package_Tool", 1, "Time series at known sites loaded");
            int    nsource_sites = fs_source.DataTable.Rows.Count;
            int    ntar_sites    = fs_target.DataTable.Rows.Count;
            int    nstep         = ts_data.Size[0];
            int    nsite_data    = ts_data.Size[1];
            int    progress      = 0;
            double sumOfDis      = 0;
            double sumOfVa       = 0;

            if (nsite_data != nsource_sites)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "the number of sites in the data file dose not match to that in the source feature file");
                return(false);
            }
            else
            {
                if (Neighbors > nsource_sites)
                {
                    Neighbors = nsource_sites;
                }
                var known_sites      = new Site[nsource_sites];
                DataCube <float> mat = new DataCube <float>(1, nstep, ntar_sites);
                mat.DateTimes      = new DateTime[nstep];
                mat.Name           = OutputMatrix;
                mat.TimeBrowsable  = true;
                mat.AllowTableEdit = false;

                double[][] xvalues = new double[nsource_sites][];
                double[]   yvalues = new double[nsource_sites];
                for (int i = 0; i < nsource_sites; i++)
                {
                    var cor = fs_source.Features[i].Geometry.Coordinate;
                    var ele = double.Parse(fs_source.Features[i].DataRow[_ValueField].ToString());
                    xvalues[i]     = new double[3];
                    known_sites[i] = new Site()
                    {
                        LocalX    = cor.X,
                        LocalY    = cor.Y,
                        ID        = i,
                        Elevation = ele
                    };
                    xvalues[i][0] = cor.X;
                    xvalues[i][1] = cor.Y;
                    xvalues[i][2] = ele;
                }
                for (int i = 0; i < nsource_sites; i++)
                {
                    var    count = 0;
                    double sum   = 0;
                    for (int t = 0; t < nstep; t++)
                    {
                        if (ts_data.GetValue(t, i) < MaximumValue)
                        {
                            sum += ts_data.GetValue(t, i);
                            count++;
                        }
                    }
                    yvalues[i] = sum / count;
                }
                MultipleLinearRegression mlineRegrsn = new MultipleLinearRegression(xvalues, yvalues, true);
                Matrix result = new Matrix();
                mlineRegrsn.ComputeFactorCoref(result);
                double[] coeffs = result[0, Matrix.mCol];
                var      cx     = coeffs[0];
                var      cy     = coeffs[1];
                var      ce     = coeffs[2];
                cancelProgressHandler.Progress("Package_Tool", 2, "Regression coefficients calculated");

                for (int i = 0; i < ntar_sites; i++)
                {
                    var cor        = fs_target.Features[i].Geometry.Coordinate;
                    var site_intep = new Site()
                    {
                        LocalX    = cor.X,
                        LocalY    = cor.Y,
                        ID        = i,
                        Elevation = double.Parse(fs_target.Features[i].DataRow[_ValueField].ToString())
                    };
                    var neighborSites = FindNeareastSites(Neighbors, known_sites, site_intep);
                    for (int j = 0; j < nstep; j++)
                    {
                        sumOfDis = 0;
                        sumOfVa  = 0;
                        foreach (var nsite in neighborSites)
                        {
                            var vv = ts_data.GetValue(j, nsite.ID);
                            if (vv < MaximumValue)
                            {
                                double temp = 1 / System.Math.Pow(nsite.Distance, Power);
                                double gd   = (site_intep.LocalX - nsite.LocalX) * cx + (site_intep.LocalY - nsite.LocalY) * cy + (site_intep.Elevation - nsite.Elevation) * ce;
                                sumOfVa  += vv * temp;
                                sumOfDis += temp;
                            }
                        }
                        if (sumOfDis != 0)
                        {
                            mat[0, j, i] = (float)(sumOfVa / sumOfDis);
                            if (!AllowNegative && mat[0, j, i] < 0)
                            {
                                mat[0, j, i] = MinmumValue;
                            }
                        }
                        else
                        {
                            mat[0, j, i] = MinmumValue;
                        }
                    }
                    progress = (i + 1) * 100 / ntar_sites;
                    cancelProgressHandler.Progress("Package_Tool", progress, "Caculating Cell: " + (i + 1));
                }
                for (int j = 0; j < nstep; j++)
                {
                    mat.DateTimes[j] = Start.AddSeconds(j * TimeStep);
                }
                cancelProgressHandler.Progress("Package_Tool", 100, "");
                Workspace.Add(mat);
                fs_source.Close();
                fs_target.Close();
                return(true);
            }
        }
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            //SaveObj();
            //return true;
            EcoDemandFile = @"E:\Project\HRB\水库调度\Process\WithDraw Input File\eco_demand_full.csv";
            int[]    mid_zone_id = new int[] { 10, 11, 12, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, 28, 29, 30, 31 };
            string[] quo_fn      = new string[] { @"E:\Project\HRB\水库调度\Process\WithDraw Input File\unit2000.txt",
                                                  @"E:\Project\HRB\水库调度\Process\WithDraw Input File\unit2007.txt",
                                                  @"E:\Project\HRB\水库调度\Process\WithDraw Input File\unit2011.txt" };
            string out_dic = @"E:\Project\HRB\水库调度\Scenario\2018-7-29\";

            string[] folders = new string[] { "SLN0", "SLN1", "SLN2", "SLN3_GW" };

            //for (int f = 0; f < 4; f++)
            //{
            int f = 3;

            EcoSolutionColIndex = 3;
            for (int k = 0; k < 3; k++)
            {
                QuotaFileName = quo_fn[k];
                if (k == 0)
                {
                    StartCycle     = 1;
                    EndCycle       = 4;
                    OutputFileName = out_dic + folders[f] + "\\HRB_wra_2000.unit";
                }
                else if (k == 1)
                {
                    StartCycle     = 5;
                    EndCycle       = 10;
                    OutputFileName = out_dic + folders[f] + "\\HRB_wra_2007.unit";
                }
                else if (k == 2)
                {
                    StartCycle     = 11;
                    EndCycle       = 13;
                    OutputFileName = out_dic + folders[f] + "\\HRB_wra_2011.unit";
                }

                bool     has_ecodemand = false;
                int      num_well_layer = 3;
                int[]    well_layer = new int[] { 1, 2, 3 };
                double[] layer_ratio = new double[] { 0.6, 0.1, 0.3 };
                int      num_irrg_obj, num_indust_obj;
                float[,] eco_demand = null;

                StreamReader sr_quota = new StreamReader(QuotaFileName);
                StreamWriter sw_out   = new StreamWriter(OutputFileName);
                string       newline  = "";

                if (TypeConverterEx.IsNotNull(EcoDemandFile))
                {
                    CSVFileStream csv = new CSVFileStream(EcoDemandFile);
                    csv.HasHeader = false;
                    eco_demand    = csv.LoadFloatMatrix();
                    has_ecodemand = true;
                }

                int nquota = 1;
                int ntime  = 36;
                var line   = sr_quota.ReadLine();

                var strs_buf = TypeConverterEx.Split <string>(line);
                nquota = int.Parse(strs_buf[0]);
                ntime  = int.Parse(strs_buf[1]);
                double[,] quota_src = new double[ntime, nquota];
                double[,] quota     = new double[366, nquota];
                int day   = 0;
                var start = new DateTime(2000, 1, 1);
                for (int i = 0; i < ntime; i++)
                {
                    line = sr_quota.ReadLine().Trim();
                    var buf  = TypeConverterEx.Split <string>(line);
                    var ss   = DateTime.Parse(buf[0]);
                    var ee   = DateTime.Parse(buf[1]);
                    var cur  = ss;
                    var step = (ee - ss).Days + 1;
                    while (cur <= ee)
                    {
                        for (int j = 0; j < nquota; j++)
                        {
                            quota[day, j] = System.Math.Round(double.Parse(buf[2 + j]) / step, 2);
                        }
                        day++;
                        cur = cur.AddDays(1);
                    }
                }

                line = sr_quota.ReadLine().Trim();
                var inttemp = TypeConverterEx.Split <int>(line.Trim());
                num_irrg_obj   = inttemp[0];
                num_indust_obj = inttemp[1];
                //ID	NAME	地表水比例  用水类型  允许降深
                line = sr_quota.ReadLine();
                irrg_obj_list.Clear();
                indust_obj_list.Clear();
                ReadObj(sr_quota, num_irrg_obj, irrg_obj_list);
                ReadObj(sr_quota, num_indust_obj, indust_obj_list);

                newline = "# Water resources allocation package " + DateTime.Now;
                sw_out.WriteLine(newline);
                newline = string.Format("{0}\t{1}\t0\t0\t # num_irrg_obj, num_indu_obj, num_doms_obj, num_ecos_obj ", num_irrg_obj, num_indust_obj);
                sw_out.WriteLine(newline);

                sw_out.WriteLine("# irrigation objects");
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    var obj = irrg_obj_list[i];
                    int oid = i + 1;
                    newline = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t#	oid, hrunum, iseg, ireach, num_well_layer, inlet_type {6}", obj.ID, obj.HRU_Num, obj.SegID, obj.ReachID, num_well_layer, obj.Inlet_Type, obj.Name);
                    sw_out.WriteLine(newline);
                    newline = string.Join("\t", obj.HRU_List);
                    sw_out.WriteLine(newline);
                    var canal_eff   = new double[obj.HRU_Num];
                    var canal_ratio = new double[obj.HRU_Num];
                    for (int j = 0; j < obj.HRU_Num; j++)
                    {
                        canal_eff[j]   = obj.Canal_Efficiency;
                        canal_ratio[j] = obj.Canal_Ratio;
                    }
                    newline = string.Join("\t", canal_eff);
                    sw_out.WriteLine(newline);
                    newline = string.Join("\t", canal_ratio);
                    sw_out.WriteLine(newline);
                    for (int j = 0; j < num_well_layer; j++)
                    {
                        newline = well_layer[j] + "\t" + layer_ratio[j] + " # well_layer layer_ratio";
                        sw_out.WriteLine(newline);
                    }
                    newline = string.Format("{0}\t#	drawdown constaint of object {1}", irrg_obj_list[i].Drawdown, oid);
                    sw_out.WriteLine(newline);
                    newline = string.Format("{0}\t{1}\t{2}\t#  inlet	min flow,  max flow and flow ratio  for object {3}", irrg_obj_list[i].Inlet_MinFlow, irrg_obj_list[i].Inlet_MaxFlow, irrg_obj_list[i].Inlet_Flow_Ratio,
                                            irrg_obj_list[i].ID);
                    sw_out.WriteLine(newline);
                }
                sw_out.WriteLine("# industrial objects");
                for (int i = 0; i < num_indust_obj; i++)
                {
                    var obj = indust_obj_list[i];
                    newline = string.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t#	oid, hrunum, iseg, ireach, num_well_layer, inlet_type {6}", obj.ID, obj.HRU_Num, obj.SegID, obj.ReachID, num_well_layer,
                                            obj.Inlet_Type, obj.Name);
                    sw_out.WriteLine(newline);
                    newline = string.Format("{0}\t#	hru_id_list", string.Join(" ", obj.HRU_List));
                    sw_out.WriteLine(newline);
                    for (int j = 0; j < num_well_layer; j++)
                    {
                        newline = well_layer[j] + "\t" + layer_ratio[j] + " # well_layer layer_ratio";
                        sw_out.WriteLine(newline);
                    }
                    newline = string.Format("{0}\t#	drawdown constaint of object {1}", obj.Drawdown, obj.ID);
                    sw_out.WriteLine(newline);
                    newline = string.Format("{0}\t{1}\t{2}\t#  inlet	min flow,  max flow and flow ratio for object {3}", obj.Inlet_MinFlow, obj.Inlet_MaxFlow, obj.Inlet_Flow_Ratio, obj.ID);
                    sw_out.WriteLine(newline);
                    newline = string.Format("{0}\t#	return_ratio", 0);
                    sw_out.WriteLine(newline);
                }

                sw_out.WriteLine(StartCycle + " # cycle index");
                sw_out.WriteLine("1	#	quota_flag");

                //if (has_ecodemand)
                //{
                //    for (int i = 0; i < nquota; i++)
                //    {
                //        for (int j = 0; j < 366; j++)
                //        {
                //            if (eco_demand[j, EcoSolutionColIndex] > 0)
                //                quota[j, i] = 0;
                //        }
                //    }
                //}
                for (int i = 0; i < nquota; i++)
                {
                    newline = "";
                    for (int j = 0; j < 366; j++)
                    {
                        newline += quota[j, i].ToString("0.0") + "\t";
                    }
                    newline += "quota of object " + (i + 1);
                    sw_out.WriteLine(newline);
                }

                newline = "# irrigation objects";
                sw_out.WriteLine(newline);
                newline = "1 1	1	1	1 #	sw_ratio_flag, swctrl_factor_flag , gwctrl_factor_flag, Withdraw_type_flag,plantarea_flag";
                sw_out.WriteLine(newline);
                //地表水比例
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    var ratio = irrg_obj_list[i].SW_Ratio;
                    //if (mid_zone_id.Contains(irrg_obj_list[i].ID))
                    //{
                    //    ratio = ratio * sw_scale[k];
                    //}
                    newline = "";
                    for (int j = 0; j < 366; j++)
                    {
                        newline += ratio.ToString("0.00") + "\t";
                    }
                    newline += "#SW ratio of object " + irrg_obj_list[i].ID;
                    sw_out.WriteLine(newline);
                }
                //地表引水控制系数
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    if (mid_zone_id.Contains(irrg_obj_list[i].ID) && has_ecodemand)
                    {
                        string str = "";
                        for (int j = 0; j < 366; j++)
                        {
                            if (eco_demand[j, EcoSolutionColIndex] > 0)
                            {
                                str += "0\t";
                            }
                            else
                            {
                                str += "1\t";
                            }
                        }
                        newline = string.Format("{0}\t#SW control factor of object {1}", str, irrg_obj_list[i].ID);
                        sw_out.WriteLine(newline);
                    }
                    else
                    {
                        newline = string.Format("{0}\t#SW control factor of object {1}", irrg_obj_list[i].SW_Cntl_Factor, irrg_obj_list[i].ID);
                        sw_out.WriteLine(newline);
                    }
                }
                //地下引水控制系数
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    newline = string.Format("{0}\t#GW control factor of object {1}", irrg_obj_list[i].GW_Cntl_Factor, irrg_obj_list[i].ID);
                    sw_out.WriteLine(newline);
                }
                //作物类型
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    newline = "";
                    for (int j = 0; j < irrg_obj_list[i].HRU_Num; j++)
                    {
                        newline += irrg_obj_list[i].ObjType + "\t";
                    }
                    newline += "# Plant type of object " + (i + 1);
                    sw_out.WriteLine(newline);
                }
                //种植面积
                for (int i = 0; i < num_irrg_obj; i++)
                {
                    newline  = string.Join("\t", irrg_obj_list[i].HRU_Area);
                    newline += "\t" + "# Plant area of object " + irrg_obj_list[i].ID;
                    sw_out.WriteLine(newline);
                }

                newline = "# industrial objects";
                sw_out.WriteLine(newline);
                newline = "1 1	1	1	1 #	sw_ratio_flag, swctrl_factor_flag , gwctrl_factor_flag, Withdraw_type_flag";
                sw_out.WriteLine(newline);

                for (int i = 0; i < num_indust_obj; i++)
                {
                    newline = "";
                    var control = 1;
                    for (int j = 0; j < 366; j++)
                    {
                        newline += control + "\t";
                    }
                    newline += "# SW control factor of object " + (indust_obj_list[i].ID);
                    sw_out.WriteLine(newline);
                }

                //地表引水控制系数
                for (int i = 0; i < num_indust_obj; i++)
                {
                    newline = string.Format("{0}\t#SW control factor of object {1}", indust_obj_list[i].SW_Cntl_Factor, indust_obj_list[i].ID);
                    sw_out.WriteLine(newline);
                }

                //地下引水控制系数
                for (int i = 0; i < num_indust_obj; i++)
                {
                    newline = string.Format("{0}\t#GW control factor of object {1}", indust_obj_list[i].GW_Cntl_Factor, indust_obj_list[i].ID);
                    sw_out.WriteLine(newline);
                }

                //用水类型
                for (int i = 0; i < num_indust_obj; i++)
                {
                    var obj = indust_obj_list[i];
                    newline = string.Format("{0} # Withdraw type of object {1}", obj.ObjType, obj.ID);
                    sw_out.WriteLine(newline);
                }

                for (int i = StartCycle + 1; i <= EndCycle; i++)
                {
                    sw_out.WriteLine(i + " # cycle index");
                    sw_out.WriteLine("-1 # quota_flag");
                    sw_out.WriteLine("# irrigation objects");
                    sw_out.WriteLine("-1 -1	-1	-1	-1  #	sw_ratio_flag, swctrl_factor_flag , gwctrl_factor_flag, Withdraw_type_flag,plantarea_flag");
                    sw_out.WriteLine("# industrial objects");
                    sw_out.WriteLine("-1 -1	-1	-1	-1  #	sw_ratio_flag, swctrl_factor_flag , gwctrl_factor_flag, Withdraw_type_flag");
                }

                sr_quota.Close();
                sw_out.Close();
                cancelProgressHandler.Progress("Package_Tool", 100, "Done");
            }
            //}
            return(true);
        }
Esempio n. 13
0
        public override bool Execute(DotSpatial.Data.ICancelProgressHandler cancelProgressHandler)
        {
            IFeatureSet fs_source = null;
            IFeatureSet fs_target = null;

            if (SourceFeatureLayer != null)
            {
                fs_source = SourceFeatureLayer.DataSet as IFeatureSet;
            }
            else if (TypeConverterEx.IsNotNull(SourceFeatureFile))
            {
                fs_source = FeatureSet.Open(SourceFeatureFile);
            }

            if (TargetFeatureLayer != null)
            {
                fs_target = TargetFeatureLayer.DataSet as IFeatureSet;
            }
            else if (TypeConverterEx.IsNotNull(TargetFeatureFile))
            {
                fs_target = FeatureSet.Open(TargetFeatureFile);
            }

            if (fs_source == null || fs_target == null)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "Failed. The inputs are invalid.");
                return(false);
            }

            CSVFileStream csv     = new CSVFileStream(DataFileName);
            var           ts_data = csv.Load <double>();

            cancelProgressHandler.Progress("Package_Tool", 1, "Time series at known sites loaded");
            int    nsource_sites = fs_source.DataTable.Rows.Count;
            int    ntar_sites    = fs_target.DataTable.Rows.Count;
            int    nstep         = ts_data.Size[0];
            int    nsite_data    = ts_data.Size[1];
            int    progress      = 0;
            int    count         = 1;
            double sumOfDis      = 0;
            double sumOfVa       = 0;

            if (nsite_data != nsource_sites)
            {
                cancelProgressHandler.Progress("Package_Tool", 100, "the number of sites in the data file dose not match to that in the source feature file");
                return(false);
            }
            else
            {
                if (Neighbors > nsource_sites)
                {
                    Neighbors = nsource_sites;
                }
                var known_sites      = new Site[nsource_sites];
                DataCube <float> mat = new DataCube <float>(1, nstep, ntar_sites);
                mat.DateTimes      = new DateTime[nstep];
                mat.Name           = OutputDataCube;
                mat.TimeBrowsable  = true;
                mat.AllowTableEdit = false;
                for (int i = 0; i < nsource_sites; i++)
                {
                    var cor = fs_source.Features[i].Geometry.Coordinate;
                    known_sites[i] = new Site()
                    {
                        LocalX = cor.X,
                        LocalY = cor.Y,
                        ID     = i
                    };
                }
                for (int i = 0; i < ntar_sites; i++)
                {
                    var cor        = fs_target.Features[i].Geometry.Coordinate;
                    var site_intep = new Site()
                    {
                        LocalX = cor.X,
                        LocalY = cor.Y,
                        ID     = i
                    };
                    var neighborSites = FindNeareastSites(Neighbors, known_sites, site_intep);
                    for (int j = 0; j < nstep; j++)
                    {
                        sumOfDis = 0;
                        sumOfVa  = 0;
                        foreach (var nsite in neighborSites)
                        {
                            var vv = ts_data.GetValue(j, nsite.ID);
                            if (vv < MaximumValue)
                            {
                                double temp = 1 / System.Math.Pow(nsite.Distance, Power);
                                sumOfVa  += vv * temp;
                                sumOfDis += temp;
                            }
                        }
                        if (sumOfDis != 0)
                        {
                            mat[0, j, i] = (float)(sumOfVa / sumOfDis);
                            if (!AllowNegative && mat[0, j, i] < 0)
                            {
                                mat[0, j, i] = MinmumValue;
                            }
                        }
                        else
                        {
                            mat[0, j, i] = MinmumValue;
                        }
                    }
                    progress = (i + 1) * 100 / ntar_sites;
                    if (progress > count)
                    {
                        cancelProgressHandler.Progress("Package_Tool", progress, "Caculating Cell: " + (i + 1));
                        count++;
                    }
                }
                for (int j = 0; j < nstep; j++)
                {
                    mat.DateTimes[j] = Start.AddSeconds(j * TimeStep);
                }
                cancelProgressHandler.Progress("Package_Tool", 100, "");
                Workspace.Add(mat);
                fs_source.Close();
                fs_target.Close();
                return(true);
            }
        }