In the Netherlands "Rijksdriehoek" coordinates are used to show the exact position of an object on a chart. To convert "Rijksdriehoek" coordinates to lat and long coordinates in C# use the following class:

 

Note

This code is base on the information found in  http://www.dekoepel.nl/pdf/Transformatieformules.pdf

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Research.Core
{
public interface IRijksdriehoekComponent
{
string ConvertToLatLong(double x, double y);
}

public class RijksdriehoekComponent : IRijksdriehoekComponent
{
public string ConvertToLatLong(double x, double y)
{
    string result = null;

    // The city "Amsterfoort" is used as reference "Rijksdriehoek" coordinate.
    int referenceRdX = 155000;
    int referenceRdY = 463000;

    double dX = (double)(x - referenceRdX) * (double)(Math.Pow(10,-5));
    double dY = (double)(y - referenceRdY) * (double)(Math.Pow(10,-5));

    double sumN = 
        (3235.65389 * dY) + 
        (-32.58297 * Math.Pow(dX, 2)) + 
        (-0.2475 * Math.Pow(dY, 2)) + 
        (-0.84978 * Math.Pow(dX, 2) * dY) + 
        (-0.0655 * Math.Pow(dY, 3)) + 
        (-0.01709 * Math.Pow(dX, 2) * Math.Pow(dY, 2)) + 
        (-0.00738 * dX) + 
        (0.0053 * Math.Pow(dX, 4)) + 
        (-0.00039 * Math.Pow(dX, 2) * Math.Pow(dY, 3)) + 
        (0.00033 * Math.Pow(dX, 4) * dY) + 
        (-0.00012 * dX * dY);
    double sumE = 
        (5260.52916 * dX) + 
        (105.94684 * dX * dY) + 
        (2.45656 * dX * Math.Pow(dY, 2)) + 
        (-0.81885 * Math.Pow(dX, 3)) + 
        (0.05594 * dX * Math.Pow(dY, 3)) + 
        (-0.05607 * Math.Pow(dX, 3) * dY) + 
        (0.01199 * dY) + 
        (-0.00256 * Math.Pow(dX, 3) * Math.Pow(dY, 2)) + 
        (0.00128 * dX * Math.Pow(dY, 4)) + 
        (0.00022 * Math.Pow(dY, 2)) + 
        (-0.00022 * Math.Pow(dX, 2)) + 
        (0.00026 * Math.Pow(dX, 5));


    // The city "Amsterfoort" is used as reference "WGS84" coordinate.
    double referenceWgs84X = 52.15517;
    double referenceWgs84Y = 5.387206;

    double latitude = referenceWgs84X + (sumN / 3600);
    double longitude = referenceWgs84Y + (sumE / 3600);

    // Input
    // x = 122202
    // y = 487250
    //
    // Result
    // "52.372143838117, 4.90559760435224"
    result = string.Format("{0}, {1}", 
        latitude.ToString(CultureInfo.InvariantCulture.NumberFormat),
        longitude.ToString(CultureInfo.InvariantCulture.NumberFormat));

    return result;
}
}
}

Test

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Research.Core;

namespace UnitTest
{
[TestClass]
public class RijksdriehoekComponentTests
{
    [TestMethod]
    public void TestMethod1()
    {
        IRijksdriehoekComponent component = new RijksdriehoekComponent();
        double x = 122202;
        double y = 487250;
        string result = component.ConvertToLatLong(x, y);
        Assert.AreEqual("52.372143838117, 4.90559760435224", result);
    }
}
}

4 Comments

  1. Op basis van http://sourceforge.net/projects/rd-wgs8

    public static double[] ConvertToRijksdriehoek(double wgs84_lattitude, double wgs84_longitude)
    {
    // The city “Amsterfoort” is used as reference “Rijksdriehoek” coordinate.
    int referenceRdX = 155000;
    int referenceRdY = 463000;

    // The city “Amsterfoort” is used as reference “WGS84” coordinate.
    double referenceWgs84X = 52.15517;
    double referenceWgs84Y = 5.387206;

    var Rpq = new double[4, 5];

    Rpq[0, 1] = 190094.945;
    Rpq[1, 1] = -11832.228;
    Rpq[2, 1] = -114.221;
    Rpq[0, 3] = -32.391;
    Rpq[1, 0] = -0.705;
    Rpq[3, 1] = -2.340;
    Rpq[0, 2] = -0.008;
    Rpq[1, 3] = -0.608;
    Rpq[2, 3] = 0.148;

    var Spq = new double[4, 5];
    Spq[0, 1] = 0.433;
    Spq[0, 2] = 3638.893;
    Spq[0, 4] = 0.092;
    Spq[1, 0] = 309056.544;
    Spq[2, 0] = 73.077;
    Spq[1, 2] = -157.984;
    Spq[3, 0] = 59.788;
    Spq[2, 2] = -6.439;
    Spq[1, 1] = -0.032;
    Spq[1, 4] = -0.054;

    var d_lattitude = (0.36 * (wgs84_lattitude – referenceWgs84X));
    var d_longitude = (0.36 * (wgs84_longitude – referenceWgs84Y));

    double calc_latt = 0;
    double calc_long = 0;

    for (int p = 0; p < 4; p++)
    {
    for (int q = 0; q < 5; q++)
    {
    calc_latt += Rpq[p, q] * Math.Pow(d_lattitude, p) * Math.Pow(d_longitude, q);
    calc_long += Spq[p, q] * Math.Pow(d_lattitude, p) * Math.Pow(d_longitude, q);
    }
    }

    var rd_x_coordinate = (referenceRdX + calc_latt);
    var rd_y_coordinate = (referenceRdY + calc_long);

    return new[] { rd_x_coordinate, rd_y_coordinate };
    }

    Ano
  2. Beste Roel,

    De tweede functie zou ik graag in VB.NET gebruiken, maar krijg in diverse conversie tools een foutmelding op Public Static Double[]

    Enig idee hoe ik dit in VB.NET voor elkaar kan krijgen?

    Ronald
  3. Ha Roel,
    Beter laat dan ooit, bijgaand mijn T-SQL versie (SQL Server) van bovenstaande RD to Lat Long.

    voorbeeld aanroep: select latitude,longitude from ConvertRD_To_LatLong(122202,487250)

    go
    create function ConvertRD_To_LatLong (@x as float, @y as float)
    RETURNS @tblLatLong TABLE
    (latitude float NOT NULL,
    longitude float NOT NULL)

    AS
    BEGIN

    –select latitude,longitude from ConvertRD_To_LatLong(122202,487250)
    –latitude longitude
    –52.372143838117 4.90559760435224

    — Input
    — x = 122202
    — y = 487250
    — latlong
    — “52.372143838117, 4.90559760435224”

    declare @latlong varchar(20)

    — The city “Amsterfoort” is used as reference “Rijksdriehoek” coordinate.
    declare @referenceRdX int = 155000
    declare @referenceRdY int = 463000
    declare @dX float
    declare @dY float

    set @dX = (@x – @referenceRdX) * power(cast(10 as float), -5)
    set @dY = (@y – @referenceRdY) * power(cast(10 as float), -5)
    — nort/east recalc
    declare @sumN float = (3235.65389 * @dY)
    + (-32.58297 * power(cast(@dX as float), 2))
    + (-0.2475 * power(cast(@dY as float), 2))
    + (-0.84978 * power(cast(@dX as float),2) * @dY )
    + (-0.0655 * power(cast(@dY as float), 3))
    + (-0.01709 * power(cast(@dX as float),2) * power(cast(@dY as float), 2))
    + (-0.00738 * @dX) + (0.0053 * power(cast(@dX as float), 4))
    + (-0.00039 * power(cast(@dX as float), 2) * power(cast(@dY as float), 3))
    + (0.00033 * power(cast(@dX as float), 4) * @dY)
    + (-0.00012 * @dX * @dY)

    declare @sumE float = (5260.52916 * @dX)
    + (105.94684 * @dX * @dY)
    + (2.45656 * @dX * power(cast(@dY as float),2))
    + (-0.81885 * power(cast(@dX as float),3))
    + (0.05594 * @dX * power(cast(@dY as float),3))
    + (-0.05607 * power(cast(@dX as float),3) * @dY)
    + (0.01199 * @dY)
    + (-0.00256 * power(cast(@dX as float),3) * power(cast(@dY as float),2))
    + (0.00128 * @dX * power(cast(@dY as float),4))
    + (0.00022 * power(cast(@dY as float),2))
    + (-0.00022 * power(cast(@dX as float),2) )
    + (0.00026 * power(cast(@dX as float),5))

    — The city “Amsterfoort” is used as reference “WGS84” coordinate.
    declare @referenceWgs84X float = 52.15517
    declare @referenceWgs84Y float = 5.387206
    — calculate to degrees
    declare @latitude float = @referenceWgs84X + (@sumN / 3600.0);
    declare @longitude float = @referenceWgs84Y + (@sumE / 3600.0);

    –set @latlong = cast(@latitude as char(10)) + ‘,’ + cast(@longitude as char(10))
    insert @tblLatLong SELECT @latitude,@longitude;

    return;
    END

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.