Transform from Irish NGR to WGS84 not working

Issue #7 resolved
Former user created an issue

Hi, I created a function based on your access database to transform from WGS84 to English and Irish NGR and back (see below). It works when I transform from NGR to WGS84 and back for OSG36 but not for Irish NGR. The transform returns 0s. Strangely, once this has happened, the other transformations do not work anymore which is really bizarre. Any idea why? Thanks Marc

Public Function OutputCoordinates(Xcord As Double, Ycord As Double, Zcord As Double, InputCoordSystem As Long, OutputCoordSystem As Long) As Coordinates 'This function transforms from WGS84 latitude and longitude to Irish or British NGR eastings and northings or the other way around 'Do not use for any other transforms

Dim InputCoordinates As Coordinates Dim OutCoordinates As Coordinates Dim OutputDatum As Integer Dim ResultOk As Boolean ' Set the source coordinates. If InputCoordSystem = 4937 Then 'we transform from WGS84 InputCoordinates.X = DegToRad(Xcord) ' 7 Deg. West - Longitude in radians. InputCoordinates.Y = DegToRad(Ycord) ' 53 Deg. North - Latitude in radians. Else InputCoordinates.X = Xcord InputCoordinates.Y = Ycord End If InputCoordinates.Z = Zcord ' Altitude in metres. ' Call the conversion function. ResultOk = Transform(InputCoordSystem, OutputCoordSystem, InputCoordinates, OutCoordinates, OutputDatum) ' Process the resuls. If InputCoordSystem = 27700 Or InputCoordSystem = 29903 Then 'we transform from Irish or British grid references OutputCoordinates.X = RadtoDeg(OutCoordinates.X) OutputCoordinates.Y = RadtoDeg(OutCoordinates.Y) OutputCoordinates.Z = OutCoordinates.Z Else OutputCoordinates.X = OutCoordinates.X OutputCoordinates.Y = OutCoordinates.Y OutputCoordinates.Z = OutCoordinates.Z End If

If ResultOk Then Debug.Print OutputCoordinates.X Debug.Print OutputCoordinates.Y Debug.Print OutputCoordinates.Z Else MsgBox "Unable to convert coordinates.", vbCritical End If End Function

Sub ExampleNotWorking() Debug.Print OutputCoordinates(122304, 327505, 0, 29903, 4937).X Debug.Print OutputCoordinates(-9.19100476797852, 54.1906514343878, 0, 4937, 29903).X End Sub

Comments (2)

  1. Paul Michell repo owner

    Marc,

    You have too few parameters in your call to Transform in the sample code you have posted:

    ResultOk = Transform(InputCoordSystem, OutputCoordSystem, InputCoordinates, OutCoordinates, OutputDatum) 

    You are missing the revision values (the two zeros in my example). I can’t compile this to test unfortunately. Please upload a working code sample.

    Kind regards,

    Paul

  2. Log in to comment