Exemple #1
0
        /// <summary>
        /// Export Mike SHP Results to AC file
        /// </summary>
        /// <param name="grid"></param>
        /// <param name="ac_filename"></param>
        /// <param name="shpfiles"></param>
        /// <param name="field"></param>
        public void Export(ITriangularGrid grid, string ac_filename, string[] shpfiles, string field)
        {
            int steps = shpfiles.Length;
            int nfeature = grid.VertexCount;
            var buf = new DataCube<float>(1, steps, nfeature);

            for (int i = 0; i < steps; i++)
            {
                var fs = FeatureSet.Open(shpfiles[i]);
                var vec = (from dr in fs.DataTable.AsEnumerable() select (float)dr.Field<double>(field)).ToArray();
                for (int k = 0; k < grid.VertexCount; k++)
                {
                    var cells = grid.Topology.NodeConnectedCells[k];
                    float temp = 0;
                    for (int c = 0; c < cells.Length; c++)
                    {
                        temp += vec[cells[c]];
                    }
                    temp /= cells.Length;
                    buf[0, i, k] = temp;
                }
                fs.Close();
            }
            buf.Variables = new string[] { field };
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);
            ac.WriteAll(buf);
        }
Exemple #2
0
        public void Export(ITriangularGrid grid, string ac_filename, string[] dbffiles, int[] index)
        {
            int steps = dbffiles.Length;
            int nfeature = grid.VertexCount;
            var buf = new DataCube<float>(index.Length, steps, nfeature);
            string[] field = new string[index.Length];
            for (int i = 0; i < steps; i++)
            {
                DBFReader dbf = new DBFReader(dbffiles[i]);
                var vec = new double[index.Length][];
                for (int t = 0; t < index.Length; t++)
                {
                    vec[t] = new double[dbf.RecordCount];
                }
                for (int n = 0; n < dbf.RecordCount; n++)
                {
                    var obj = dbf.NextRecord();
                    for (int t = 0; t < index.Length; t++)
                    {
                        vec[t][n] = double.Parse(obj[index[t]].ToString());
                    }
                }

                for (int t = 0; t < index.Length; t++)
                {
                    for (int k = 0; k < grid.VertexCount; k++)
                    {
                        var cells = grid.Topology.NodeConnectedCells[k];
                        double temp = 0;
                        for (int c = 0; c < cells.Length; c++)
                        {
                            temp += vec[t][cells[c]];
                        }
                        temp /= cells.Length;
                        buf[t, i, k] = (float)temp;
                    }
                    field[t] = dbf.Fields[index[t]].Name;
                }
                dbf.Close();
            }
            buf.Variables = field;
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);    
            ac.WriteAll(buf);
        }