简体   繁体   English

使用NMEA2OSG类– C#将WGS84纬度Lon坐标转换为OSGR

[英]Convert WGS84 Lat Lon coordinates to OSGR using NMEA2OSG Class – C#

I need to convert from the WGS84 Lat Lon coordinate system (basically what Google maps and Bing use) to the British Ordinance Survey Coordinates system. 我需要将WGS84 Lat Lon坐标系(基本上是Google的地图和Bing使用的坐标系)转换为英国条例调查坐标系。 As the calculation is rather complicated (something about ellipsoids and projection etc) there is an off the shelf C# class that is commonly used called “NMEA2OSG”. 由于计算相当复杂(有关椭球和投影等),因此有一种现成的C#类,通常称为“ NMEA2OSG”。

Link to the NMEA2OSG Class: NMEA2OSG Class 链接到NMEA2OSG类: NMEA2OSG类

I'm struggling to understand how to use this class. 我正在努力了解如何使用此类。 Whilst there are several questions on SO about how to convert WGS84 to OSGR there are non on how to use the NMEA2OSG class. 尽管有一些关于如何将WGS84转换为OSGR的问题,但还没有关于如何使用NMEA2OSG类的问题。

I've tried running it's second method, which seems like the correct method as it accepts long lat decimals as an input. 我尝试运行第二种方法,这似乎是正确的方法,因为它接受长的十进制小数作为输入。 Attempt as follows: 尝试如下:

NMEA2OSG nMEA2OSG = new NMEA2OSG();
bool coord = nMEA2OSG.Transform(52.3, -0.1, 50);

However, this method only returns a bool, so presumable I need to access the output from the method from the instance of the class. 但是,此方法仅返回布尔值,因此大概我需要从类的实例访问该方法的输出。 Unfortunately I don't understand how to do this. 不幸的是我不知道该怎么做。

Can anyone advise how to return converted coordinates from the NMEA2OSG class? 谁能建议如何从NMEA2OSG类返回转换后的坐标?

Bonus question, if anyone knows that the height variables means in the 'Transform' method that would also be useful. 奖励问题,如果有人知道高度变量在'Transform'方法中的含义也将是有用的。 Thanks 谢谢

The NMEA20SG class has events for notifying you of the results. NMEA20SG类具有用于将结果通知您的事件。 Here's the code for setting that up: 这是设置代码:

static void Main(string[] args)
{
    NMEA2OSG nMEA2OSG = new NMEA2OSG();
    nMEA2OSG.NorthingEastingReceived += NMEA2OSG_NorthingEastingReceived;
    nMEA2OSG.NatGridRefReceived += NMEA2OSG_NatGridRefReceived;
    bool coord = nMEA2OSG.Transform(52.3, -0.1, 50);
    Console.ReadKey();
}

private static void NMEA2OSG_NatGridRefReceived(string ngr)
{
    Console.WriteLine("NatGrid: {0}", ngr);
}

private static void NMEA2OSG_NorthingEastingReceived(double northing, double easting)
{
    Console.WriteLine("Northing = {0}, Easting = {1}", northing, easting);
}

Results for your input: 输入结果:

Northing = 268576, Easting = 529657
NatGrid: TL 29657 68576

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM