public void LoadMatFromASC()
        {
            string dic     = @"E:\Heihe\HRB\GeoData\GBHM\IHRB\上游模型集成数据_qy151228\3.merge_soil\";
            string ascfile = dic + "soil_200001.asc";
            // string acfile = @"C:\Users\Administrator\Documents\GBHM\GBHM\result\sm_month_2000-2012_gbhm.ac";
            AscReader        asc   = new AscReader();
            AcFile           ac    = new AcFile();
            var              vec   = asc.LoadSerial(ascfile, _ProjectService.Project.Model.Grid as IRegularGrid);
            int              nfeat = vec.Length;
            DataCube <float> mat   = new DataCube <float>(1, 156, nfeat);

            int i = 0;

            for (int y = 2000; y < 2013; y++)
            {
                for (int m = 1; m < 13; m++)
                {
                    string fn = dic + "soil_" + y + m.ToString("00") + ".asc";
                    vec = asc.LoadSerial(fn, _ProjectService.Project.Model.Grid as IRegularGrid);
                    var buf = vec;
                    for (int c = 0; c < buf.Length; c++)
                    {
                        if (buf[c] < 0)
                        {
                            buf[c] = 0;
                        }
                    }
                    mat[0, i.ToString(), ":"] = buf;
                    i++;
                }
            }
            // ac.Save(acfile, mat, new string[] { "Monthly Soil Moisture" });
        }
Example #2
0
        public IGrid Provide(string filename)
        {
            AscReader asc    = new AscReader();
            var       mat    = asc.Load(filename);
            var       mfgrid = new MFGrid();

            mfgrid.RowCount    = mat.Size[1];
            mfgrid.ColumnCount = mat.Size[2];
            //mfgrid.RowInteval = new MyScalar<float>(asc.CellSize);
            //mfgrid.ColInteval = new MyScalar<float>(asc.CellSize);

            mfgrid.IBound = new DataCube <float>(1, mfgrid.RowCount, mfgrid.ColumnCount);

            mfgrid.ActiveCellCount = 0;

            for (int r = 0; r < mat.Size[0]; r++)
            {
                for (int c = 0; c < mat.Size[1]; c++)
                {
                    if (mat[0, r, c] == asc.NoDataValue)
                    {
                        mfgrid.IBound[0, r, c] = 0;
                    }
                    else
                    {
                        mfgrid.IBound[0, r, c] = 1;
                        mfgrid.ActiveCellCount++;
                    }
                }
            }
            mfgrid.Elevations = new DataCube <float>(1, 1, mfgrid.ActiveCellCount);

            var vector = asc.LoadSerial(filename, mfgrid);

            mfgrid.Elevations[0]["0", ":"] = vector;

            return(mfgrid);
        }