示例#1
0
        /// <summary>
        /// Read a *.dem file
        /// </summary>
        /// <param name="filename"></param>
        public void Read(string filename)
        {
            StreamReader reader = new StreamReader(filename);

            char[] buffer = new char[1024]; // size of A Record
            reader.Read(buffer, 0, 1024);

            _mARecord                        = new ARecord();
            _mARecord.file_name              = ParseString(buffer, 0, 40).ToCharArray();
            _mARecord.free_text_format       = ParseString(buffer, 40, 40).ToCharArray();
            _mARecord.SE_geographic_corner_S = ParseString(buffer, 109, 13).ToCharArray();
            _mARecord.SE_geographic_corner_E = ParseString(buffer, 122, 13).ToCharArray();
            _mARecord.process_code           = buffer[135];
            _mARecord.origin_code            = ParseString(buffer, 140, 4).ToCharArray();
            _mARecord.dem_level_code         = ParseInt(buffer, 144);
            _mARecord.elevation_pattern      = ParseInt(buffer, 150);
            _mARecord.ground_ref_system      = ParseInt(buffer, 156);
            _mARecord.ground_ref_zone        = ParseInt(buffer, 162);
            for (int i = 0; i < 15; i++)
            {
                _mARecord.projection[0] = ParseDouble(buffer, 168 + i * 24);
            }
            _mARecord.ground_unit        = ParseInt(buffer, 528);
            _mARecord.elevation_unit     = ParseInt(buffer, 534);
            _mARecord.side_count         = ParseInt(buffer, 540);
            _mARecord.sw_coord[0]        = (float)ParseDouble(buffer, 546); // UTM grid (measured in meters)
            _mARecord.sw_coord[1]        = (float)ParseDouble(buffer, 570);
            _mARecord.nw_coord[0]        = (float)ParseDouble(buffer, 594);
            _mARecord.nw_coord[1]        = (float)ParseDouble(buffer, 618);
            _mARecord.ne_coord[0]        = (float)ParseDouble(buffer, 642);
            _mARecord.ne_coord[1]        = (float)ParseDouble(buffer, 666);
            _mARecord.se_coord[0]        = (float)ParseDouble(buffer, 690);
            _mARecord.se_coord[1]        = (float)ParseDouble(buffer, 714);
            _mARecord.elevation_min      = ParseDouble(buffer, 738);
            _mARecord.elevation_max      = ParseDouble(buffer, 762);
            _mARecord.ccw_angle          = ParseDouble(buffer, 786);
            _mARecord.elevation_accuracy = ParseInt(buffer, 810);
            _mARecord.xyz_resolution[0]  = ParseFloat(buffer, 816);
            _mARecord.xyz_resolution[1]  = ParseFloat(buffer, 828);
            _mARecord.xyz_resolution[2]  = ParseFloat(buffer, 840);
            _mARecord.eastings_cols      = ParseInt(buffer, 858);
            _mARecord.northings_rows     = ParseInt(buffer, 858); // WARNING. SHOULD NOT USE THIS VALUE. BUT WE ASSUME IS THE SAME WITH eastings SINCE IT IS ALWAYS THE CASE.
            _mARecord.suspect_void       = ParseInt(buffer, 886, 2);
            _mARecord.percent_void       = ParseInt(buffer, 896);

            // read the rest of the DEM
            StreamTokenizer tokenizer = new StreamTokenizer(reader, new char[] { ' ' });

            _mBRecord = null;
            for (int col = 0; col < _mARecord.eastings_cols; col++)
            {
                tokenizer.Next(); // row id
                tokenizer.Next(); // col id
                _mARecord.northings_rows = ToInt(tokenizer.Next());

                if (_mBRecord == null)
                {
                    _mBRecord = new BRecord(_mARecord.eastings_cols, _mARecord.northings_rows);
                }

                tokenizer.Next(); // skip next six fields
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();
                tokenizer.Next();

                // for (int row = record.northings_rows - 1; row >= 0; row--)
                for (int row = 0; row < _mARecord.northings_rows; row++)
                {
                    _mBRecord.elevations[col, row] = ToShort(tokenizer.Next());
                }
            }

            reader.Close();
        }
示例#2
0
 public DemDocument()
 {
     _mARecord = null;
     _mBRecord = null;
 }