示例#1
0
        public void Export(string ac_filename, string[] dbffiles, int[] index)
        {
            int steps = dbffiles.Length;
            DBFReader dbf = new DBFReader(dbffiles[0]);
            int nfeature = dbf.RecordCount;
            var buf = new DataCube<float>(index.Length, steps, nfeature);
            string[] field = new string[index.Length];
            for (int i = 0; i < index.Length; i++)
            {
                field[i] = dbf.Fields[index[i]].Name;
            }
              
            dbf.Close();

            for (int t = 0; t < steps; t++)
            {
                dbf = new DBFReader(dbffiles[t]);
                for (int n = 0; n < dbf.RecordCount; n++)
                {
                    var obj = dbf.NextRecord();
                    for (int i = 0; i < index.Length; i++)
                    {
                        buf[i, t, n] = float.Parse(obj[index[i]].ToString());
                    }
                }
                dbf.Close();
            }
            buf.Variables = field;
            DataCubeStreamWriter ac = new DataCubeStreamWriter(ac_filename);
            ac.WriteAll(buf);
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            DBFReader dbf = new DBFReader("d:\\skl\\3\\TOVAR.DBF");

            dbf.Open();

            DBFColumn     s    = null;
            List <string> keys = new List <string>();
            int           i;

            for (i = 0; i < 2; i++)
            {
                s = dbf.GetColumn(i);
                keys.Add(s.ColumnName);
            }

            IDataRecord irow;
            string      key;

            Dictionary <string, IDataRecord> data = new Dictionary <string, IDataRecord>();

            for (i = 0; i < dbf.Count; i++)
            {
                irow = (IDataRecord)dbf[i];
                key  = ((DBFRow)irow).GetKey(keys.ToArray());
                data.Add(key, irow);
            }

            dbf.Close();
        }
示例#3
0
        public void Export(string dbfile, string ascfile, int nrow, int ncol, int cellsize, float xcorner, float ycorner, float nodatavalue = -999)
        {
            DBFReader        dbf        = new DBFReader(dbfile);
            int              act_index  = dbf.GetFiledNameIndex("active");
            int              row_index  = dbf.GetFiledNameIndex("row");
            int              col_index  = dbf.GetFiledNameIndex("col");
            int              elev_index = dbf.GetFiledNameIndex("elev");
            DataCube <float> mat        = new DataCube <float>(1, nrow, ncol);
            int              nact       = 0;

            for (int n = 0; n < dbf.RecordCount; n++)
            {
                var obj = dbf.NextRecord();
                int row = int.Parse(obj[row_index].ToString());
                int col = int.Parse(obj[col_index].ToString());
                int act = int.Parse(obj[act_index].ToString());
                if (act > 0)
                {
                    mat[0, row - 1, col - 1] = float.Parse(obj[elev_index].ToString());
                    nact++;
                }
                else
                {
                    mat[0, row - 1, col - 1] = nodatavalue;
                }
            }

            dbf.Close();
            //  this.Save<float>(ascfile, Value, nrow, ncol, cellsize, xcorner, ycorner, nodatavalue);
        }
示例#4
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);
        }
示例#5
0
        static void Main(string[] args)
        {
            // считывание настроек
            //for (i = 0; i < n; i++)

            string path1 = "D:\\skl\\3",
                   path2 = "D:\\skl\\1";

            string file1 = Path.Combine(path1, "TOVAR.DBF"),
                   file2 = Path.Combine(path2, "TOVAR.DBF");

            DBFReader dbfr1 = new DBFReader(file1),
                      dbfr2 = new DBFReader(file2);

            if (dbfr1.Open())
            {
                int i;
                #region ключевые поля
                DBFColumn     col;
                List <string> keys = new List <string>();

                for (i = 0; i < 2; i++)
                {
                    col = dbfr1.GetColumn(i);
                    keys.Add(col.ColumnName);
                }
                #endregion

                Dictionary <string, byte[]> data1 = dbfr1.ReadData(keys), data2 = null;
                Directory.CreateDirectory(path2);
                // файла нет
                if (!File.Exists(file2))
                {
                    File.Copy(file1, file2);
                }
                else
                {
                    if (dbfr2.Open())
                    {
                        data2 = dbfr2.ReadData(keys);
                    }
                }

                #region синхронизация

                string key;
                byte[] buf1, buf2;
                object obj1, obj2;

                foreach (KeyValuePair <string, byte[]> kvp in data1)
                {
                    key  = kvp.Key;
                    buf1 = kvp.Value;

                    char[] c = dbfr1.Encoding.GetChars(buf1);

                    if (data2.ContainsKey(key))
                    {
                        buf2 = data2[key];

                        for (i = 2; i < dbfr2.ColumnCount; i++)
                        {
                            col = dbfr2.GetColumn(i);

                            obj1 = buf1[col.Size];
                            obj2 = buf2[col.Size];
                            //if (T == typeof(int))  = "System.Convert.ToInt32(row1[i])";
                        }
                    }
                    else
                    {
                        data2.Add(key, buf1);
                    }
                }
                #endregion

                data1.Clear();
                data2.Clear();
                keys.Clear();
            }
            dbfr1.Close();
            dbfr2.Close();

            dbfr1 = null;
            dbfr2 = null;
        }
 public void Close()
 {
     dbf.Close();
 }