Share |

Performing geodetic datum transformations using Borland Delphi

Dowload Eye4Software GPS Toolkit free trial Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free
Browse through the Eye4Software GPS Toolkit for Windows manual Browse through the Eye4Software GPS Toolkit manual

Introduction

The Eye4Software GPS toolkit allows software developers to add GPS functionality to their own programs without the need to have any knowledge on serial communications and GPS protocols like RS-232 and NMEA0183.

The product can be used in many programming environments, such as Visual Basic, Visual C++, Visual Studio.Net, Borland C++ Builder, Borland Delphi and VBA, but also web oriented applications such as ASP, ASP.NET and PHP, and all other programming environments that support ActiveX.

Prerequisites

First you must have Borland Delphi and the Eye4Software GPS Component installed on your computer. We will use Borland Delphi 7.0 in this document, but other versions from 6.0 and up can be used. You can download the Eye4Software GPS Component here.

Creating the project

For this demo, a console application is used. To create a simple console application project in Delphi, follow the next steps: Select the "Other..." option from the "File" => "New" Menu and select the "Console Application" option, and click "OK".

Performing geodetic datum transformations using Borland Delphi

Declare and create the object(s)

To use ActiveX controls in a Delphi Console Application project, you first have to specify some units to add ActiveX support. Modify the "uses" block at the top of the code like this:

uses SysUtils, OleServer, ComObj, ActiveX;

Declare the objects like this:

var

objGpsProjection 	: Variant;
objGpsDatumDst 		: Variant;
objGpsDatumSrc 		: Variant;

Before the program is able to load OLE objects, we have to initialize OLE/COM, otherwise an exception is thrown when we try to execute the program:

OleInitialize ( nill );

It is now time to create the objects:

objGpsProjection  := CreateOleObject ( 'Eye4Software.GpsProjection'      );
objGpsDatumSrc    := CreateOleObject ( 'Eye4Software.GpsDatumParameters' );
objGpsDatumDst    := CreateOleObject ( 'Eye4Software.GpsDatumParameters' );

The source code

The source code below demonstrates how to build a very simple datum transformation program using Borland Delphi. To modify the code to use another source or destination datum, please have a look at the list of geodetic datums page.

program DatumTrans;

{$APPTYPE CONSOLE}

uses
  SysUtils, OleServer, ComObj, ActiveX;

  {Declare the GPS Toolkit objects}

var
  objGpsProjection    : Variant;
  objGpsDatumSrc      : Variant;
  objGpsDatumDst      : Variant;

begin

  { Initialize OLE }
  OleInitialize ( nil  );

  { Create Objects }
  objGpsProjection  := CreateOleObject ( 'Eye4Software.GpsProjection'      );
  objGpsDatumSrc    := CreateOleObject ( 'Eye4Software.GpsDatumParameters' );
  objGpsDatumDst    := CreateOleObject ( 'Eye4Software.GpsDatumParameters' );

  { Set Source Datum }
  objGpsDatumSrc.Axis         := 6378137.0;
  objGpsDatumSrc.Flattening   := 298.257223563;

  { Set Destination Datum }
  objGpsDatumDst.Axis         := 6377397.155;
  objGpsDatumDst.Flattening   := 299.152818368523;

  objGpsDatumDst.TranslationX := 582.0;
  objGpsDatumDst.TranslationY := 105.0;
  objGpsDatumDst.TranslationY := 414.0;

  objGpsDatumDst.RotationX    :=  1.040;
  objGpsDatumDst.RotationY    :=  0.350;
  objGpsDatumDst.RotationZ    := -0.308;

  { Set Source Latitude and Longitude }
  objGpsProjection.Latitude   :=  52.0;
  objGpsProjection.Longitude  :=   6.0;

  { Display the result }
  WriteLn ( 'Latitude  (WGS84) : ' + FloatToStr ( objGpsProjection.Latitude  ) );
  WriteLn ( 'Longitude (WGS84) : ' + FloatToStr ( objGpsProjection.Longitude ) );

  { Transform }
  objGpsProjection.TransformDatum ( objGpsDatumSrc, objGpsDatumDst );

  WriteLn ( 'Latitude  (New)   : ' + FloatToStr ( objGpsProjection.Latitude  ) );
  WriteLn ( 'Longitude (New)   : ' + FloatToStr ( objGpsProjection.Longitude ) );
end.