GPS- Deriving British Ordnance Survey Grid Reference from NMEA data

Part 1 - modify NMEAinterpreter class

The NMEA data exported by GPS units gives latitude and longitude and geometric distance above the WGS84 (GRS80) reference ellipsoid.
The Ordnance Survey maps for Great Britain use grid references based on the Airy Spheroid (OSGB36) reference ellipsoid.

The following article discusses a C# class to convert GPS derived NMEA data to the British Ordnance Survey Grid.

This article assumes that the NMEA data is being derived using Jon Person's excellent NMEA interpreter class as discussed in Writing Your Own GPS Applications: Part 2.

In order to perform the transformation, some additional data is required in the form of ellipsoid height, which can be derived from the NMEA $GPGGA sentence.

The $GPGGA sentence is not parsed in the original from of the NMEAinterpreter so this must be added.

First off, we need to make a couple of small alterations to the NMEAinterpreter class, for an explanation of these changes read the "Re: Love this product!...just 1 minor Logical ERROR" comments.

In public bool ParseGPGSV(string sentence) where it says
SignalToNoiseRatio = Convert.ToInt32(Words[Count * 4 + 2]);

it should say
SignalToNoiseRatio = Convert.ToInt32(Words[Count * 4 + 3]);

Also public string[] GetWords(string sentence) should be modified as follows

public string[] GetWords(string sentence)
    {
        //remove the * and checksum from the end of the sentence
        sentence = sentence.Substring(0, sentence.IndexOf("*"));
        //now split it up
        return sentence.Split(',');
    }

Now we need to add parsing of the $GPGGA sentence.
First we will need to add a new delegate for the ellipsoid height event:

Below the line
    public delegate void PDOPReceivedEventHandler(double value);

add the line
    public delegate void EllipsoidHeightReceivedEventHandler(double value);

We also need to add a new event:

Below the line
   public event PDOPReceivedEventHandler PDOPReceived;

add the line
    public event EllipsoidHeightReceivedEventHandler EllipsoidHeightReceived;

The public bool Parse(string sentence) routine needs a new case added for the $GPGGA sentence.

Replace
      case "$GPGSA":
return ParseGPGSA(sentence);
default:
// Indicate that the sentence was not recognised
return false;

with
      case "$GPGSA":
        return ParseGPGSA(sentence);
      case "$GPGGA":
        return ParseGPGGA(sentence);
      default:
         // Indicate that the sentence was not recognised
         return false;

Now we need to add parsing of the $GPGGA sentence.

There are numerous web pages which detail the structure of the various NMEA sentences, I got my information from http://www.commlinx.com.au/NMEA_sentences.htm. If the first word of the GPGGA sentence is word 0 then word 9 contains the ellipsoid height.

public bool ParseGPGGA(string sentence) could be added below public bool ParseGPGSA(string sentence)
    public bool ParseGPGGA(string sentence)
    {
        // Divide the sentence into words
        string[] Words = GetWords(sentence);
        if (Words[9] != "")
        {
            if (EllipsoidHeightReceived != null)
                EllipsoidHeightReceived(double.Parse(Words[9]));
        }
       return true;
    }

So now we have modified Jon Person's NMEAinterpreter class to give us the ellipsoid height. (In practice you may want to pull out various other bits of data too).

On the next page we will make a start on the coordinate transformation class.

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.” - Donald Knuth