Monday, November 14, 2011

C# code snippet to read an Applanix SBET file

The smoothed best estimated trajectory (SBET) file of an air survey flight created and exported by the Applanix PosPac software is a simple binary format. The SBET file is just a series of records with the following double fields, as described by the C# code below:

public class SbetRecord
{
    public double time;    //GPS seconds of week
    public double latRad;    //latitude in radians
    public double lonRad;    //longitude in radians
    public double alt;    //altitude
    public double xVel;    //velocity in x direction
    public double yVel;    //velocity in y direction
    public double zVel;    //velocity in z direction
    public double roll;    //roll angle
    public double pitch;    //pitch angle
    public double heading;    //heading angle
    public double wander;    //wander
    public double xForce;    //force in x direction
    public double yForce;    //force in y direction
    public double zForce;    //force in z direction
    public double xAngRate;    //angular rate in x direction
    public double yAngRate;    //angular rate in y direction
    public double zAngRate;    //angular rate in z direction
}

Then just use a BinaryReader to open up the file and read in the fields as doubles as shown in the code snippet below.
SbetRecord rec = new SbetRecord();
// Open an SBET file for reading...
BinaryReader reader = new BinaryReader(File.Open(@"C:\Temp\sbet1.out", FileMode.Open, FileAccess.Read));
 
// ...read a record...
rec.time = reader.ReadDouble();
rec.latRad = reader.ReadDouble();
rec.lonRad = reader.ReadDouble();
rec.alt = reader.ReadDouble();
rec.xVel = reader.ReadDouble();
rec.yVel = reader.ReadDouble();
rec.zVel = reader.ReadDouble();
rec.roll = reader.ReadDouble();
rec.pitch = reader.ReadDouble();
rec.heading = reader.ReadDouble();
rec.wander = reader.ReadDouble();
rec.xForce = reader.ReadDouble();
rec.yForce = reader.ReadDouble();
rec.zForce = reader.ReadDouble();
rec.xAngRate = reader.ReadDouble();
rec.yAngRate = reader.ReadDouble();
rec.zAngRate = reader.ReadDouble();
 
// ... etc ...

No comments:

Post a Comment