Library tutorials & articles
GPS- Deriving British Ordnance Survey Grid Reference from NMEA data
By Alex Etchells, published on 21 Mar 2006
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.
it should say
Also
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
add the line
We also need to add a new event:
Below the line
add the line
Replace
with
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.
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.
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.
Related articles
Related discussion
-
Using Microsoft Visual Studio to creat a C# Project that nests DLL source as well.
by Complete (0 replies)
-
"The binding handle is invalid" when debugging a .NET app
by James Crowley (1 replies)
Related podcasts
-
Looking into the C# Crystal Ball with Charlie Calvert and Bill Wagner
One of the most exciting announcements from PDC was the news about C# 4.0 and Visual Studio 2010. With all the excitement and discussion throughout the event about these new developer tools, we reached out to two experts in the fields. Charlie Calvert and Bill Wagner sat down with Keith and Woody...
Events coming up
-
Mar
23
DevWeek 2009
London, United Kingdom
DevWeek is Europe’s leading independent conference for software developers, database professionals and IT architects, and features expert speakers on a wide range of topics, including .NET Framework 4.0, Silverlight 2, WCF 4.0, Visual Studio 2010, RESTful services, Windows Workflow, ASP.NET AJAX 4.0, SQL Server 2008, LINQ, C# 3, .NET Patterns, Ruby, and more.
Comments
Leave a comment
Sign in or Join us (it's free).