Ejemplo n.º 1
0
        /// <summary>
        /// Parses the grid table header and returns an appropriate <see cref="GridTable"/>
        /// </summary>
        /// <param name="table">The grid tabel to initialize</param>
        /// <returns>true if the header could be read.</returns>
        internal override bool ReadHeader(GridTable table)
        {
            var headerBuffer = new byte[176];

            using (var s = OpenGridTableStream())
            {
                s.Seek(_dataOffset, SeekOrigin.Current);
                if (s.Read(headerBuffer, 0, 176) != 176)
                {
                    return(false);
                }
            }

            return(_dataOffset == 0
                       ? ReadOverviewHeader(headerBuffer, table)
                       : ReadHeader(headerBuffer, table));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Factory method to load a grid table
        /// </summary>
        /// <param name="location"></param>
        /// <returns></returns>
        public static GridTable Load(Uri location)
        {
            GridTable table;

            if (!GridTables.TryGetValue(location, out table))
            {
                lock (GridTablesLock)
                {
                    if (!GridTables.TryGetValue(location, out table))
                    {
                        var             ext = Path.GetExtension(location.LocalPath) ?? string.Empty;
                        GridTableLoader loader;
                        switch (ext.ToLower())
                        {
                        case "":
                        case ".lla":
                            loader = new LlaGridTableLoader(location);
                            break;

                        case ".gsb":
                            loader = new GsbGridTableLoader(location);
                            break;

                        case ".dat":
                            loader = new DatGridTableLoader(location);
                            break;

                        case ".los":
                            loader = new LasLosGridTableLoader(location);
                            break;

                        default:
                            throw new ArgumentException();
                        }
                        table = new GridTable(loader);
                        GridTables.Add(location, table);
                    }
                }
            }
            return(table);
        }
Ejemplo n.º 3
0
        internal override bool ReadHeader(GridTable table)
        {
            using (var stream = OpenGridTableStream())
            {
                var header = new byte[176];
                if (stream.Read(header, 0, 176) != 176)
                {
                    return(false);
                }

                table.LowerLeft = new PhiLambda
                {
                    Phi    = GetBigEndianDouble(header, 24),
                    Lambda = -GetBigEndianDouble(header, 72)
                };

                table.UpperRight = new PhiLambda
                {
                    Phi    = GetBigEndianDouble(header, 40),
                    Lambda = -GetBigEndianDouble(header, 56)
                };

                table.SizeOfGridCell = new PhiLambda
                {
                    Phi    = GetBigEndianDouble(header, 88),
                    Lambda = -GetBigEndianDouble(header, 104)
                };

                var size = table.UpperRight - table.LowerLeft;
                table.NumLambdas = (int)(Math.Abs(size.Lambda) / table.SizeOfGridCell.Lambda + 0.5) + 1;
                table.NumPhis    = (int)(Math.Abs(size.Phi) / table.SizeOfGridCell.Phi + 0.5) + 1;

                table.LowerLeft      = PhiLambda.DegreesToRadians(table.LowerLeft);
                table.UpperRight     = PhiLambda.DegreesToRadians(table.UpperRight);
                table.SizeOfGridCell = PhiLambda.DegreesToRadians(table.SizeOfGridCell);

                return(true);
            }
        }
Ejemplo n.º 4
0
        internal override bool ReadData(GridTable table)
        {
            using (var br = new BinaryReader(OpenGridTableStream()))
            {
                br.BaseStream.Seek(176, SeekOrigin.Current);
                var coeffs = new PhiLambda[table.NumPhis][];
                for (var row = 0; row < table.NumPhis; row++)
                {
                    coeffs[row] = new PhiLambda[table.NumLambdas];

                    // NTV order is flipped compared with a normal CVS table
                    for (var col = table.NumLambdas - 1; col >= 0; col--)
                    {
                        const double degToArcSec = (Math.PI / 180) / 3600;
                        // shift values are given in "arc-seconds" and need to be converted to radians.
                        coeffs[row][col].Phi    = ReadBigEndianDouble(br) * degToArcSec;
                        coeffs[row][col].Lambda = ReadBigEndianDouble(br) * degToArcSec;
                    }
                }
                table.Coefficients = coeffs;
                return(true);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Parses the grid table header and returns an appropriate <see cref="GridTable"/>
        /// </summary>
        /// <param name="table">The grid tabel to initialize</param>
        /// <returns>true if the header could be read.</returns>
        internal override bool ReadHeader(GridTable table)
        {
            using (var br = new BinaryReader(OpenGridTableStream()))
            {
                br.BaseStream.Seek(64, SeekOrigin.Current);

                table.NumLambdas = br.ReadInt32();
                table.NumPhis    = br.ReadInt32();
                br.ReadBytes(4);

                PhiLambda ll, cs;
                ll.Lambda = br.ReadSingle();
                cs.Lambda = br.ReadSingle();
                ll.Phi    = br.ReadSingle();
                cs.Phi    = br.ReadSingle();

                table.LowerLeft      = PhiLambda.DegreesToRadians(ll);
                table.SizeOfGridCell = PhiLambda.DegreesToRadians(cs);
                table.UpperRight     = ll + cs.Times(table.NumPhis, table.NumLambdas);

                return(true);
            }
        }
Ejemplo n.º 6
0
 internal void AddSubGrid(GridTable subGridTable)
 {
     _subGridTables.Add(subGridTable);
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Parses the grid table data
 /// </summary>
 /// <param name="table">The table to fill</param>
 /// <returns>true if the data could be read.</returns>
 internal abstract bool ReadData(GridTable table);
Ejemplo n.º 8
0
 /// <summary>
 /// Parses the grid table header and returns an appropriate <see cref="GridTable"/>
 /// </summary>
 /// <param name="table">The grid tabel to initialize</param>
 /// <returns>true if the header could be read.</returns>
 internal abstract bool ReadHeader(GridTable table);
Ejemplo n.º 9
0
        internal override bool ReadData(GridTable table)
        {
            using (var sr = new StreamReader(OpenGridTableStream()))
            {
                //Skip first 2 lines
                sr.ReadLine();
                sr.ReadLine();

                var phiIndex    = -1;
                var lambdaIndex = 0;

                double phi = 0, lambda = 0;
                var    coeff = new PhiLambda[table.NumPhis][];
                while (!sr.EndOfStream)
                {
                    var line = sr.ReadLine();
                    if (string.IsNullOrEmpty(line))
                    {
                        continue;
                    }
                    var      posColon = line.IndexOf(':');
                    string[] values;
                    int      valueIndex;
                    if (posColon > 0)
                    {
                        phiIndex                  = int.Parse(line.Substring(0, posColon), NumberStyles.Integer);
                        coeff[phiIndex]           = new PhiLambda[table.NumLambdas];
                        line                      = line.Substring(posColon + 1);
                        values                    = line.Split(new[] { ' ' });
                        lambda                    = ProjectionMath.ArcSecondsToRadians(long.Parse(values[0], NumberStyles.Integer));
                        phi                       = ProjectionMath.ArcSecondsToRadians(long.Parse(values[1], NumberStyles.Integer));
                        coeff[phiIndex][0].Phi    = phi;
                        coeff[phiIndex][0].Lambda = lambda;
                        lambdaIndex               = 1;
                        valueIndex                = 2;
                    }
                    else
                    {
                        values     = line.Split(new[] { ' ' });
                        valueIndex = 0;
                    }

                    if (phiIndex >= 0)
                    {
                        while (lambdaIndex < table.NumLambdas)
                        {
                            lambda += ProjectionMath.ArcMicroSecondsToRadians(
                                long.Parse(values[valueIndex++], NumberStyles.Integer));
                            phi += ProjectionMath.ArcMicroSecondsToRadians(
                                long.Parse(values[valueIndex++], NumberStyles.Integer));

                            coeff[phiIndex][lambdaIndex].Phi    = phi;
                            coeff[phiIndex][lambdaIndex].Lambda = lambda;
                            lambdaIndex++;
                        }
                    }
                }
                table.Coefficients = coeff;
            }
            return(true);
        }