Share |

Convert GPS coordinates from one map datum to another using VBScript

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 a VB Script editor and the Eye4Software GPS Component installed on your computer. If you do not have a dedicated VBScript editor, notepad will do. You can download the Eye4Software GPS Component here.

Creating the project

To create your VB Script, you can just use notepad or any other text editor. Create a file with a ".vbs" extension.

Declare and create the object(s)

On top of your script, please add the following code to declare the objects:

Dim objProjection
Dim objDatumSrc
Dim objDatumDst

And the following code to create an instance of the object:

Set objProjection   = CreateObject ( "Eye4Software.GpsProjection" )
Set objDatumSrc     = CreateObject ( "Eye4Software.GpsDatumParameters" )
Set objDatumDst     = CreateObject ( "Eye4Software.GpsDatumParameters" )

The source code

The following script demonstrates how to perform a geodetic datum transformation using the Eye4Software GPS Toolkit and VBScript. To specify another map datum as source or destination, lookup the datum's ID in the map datum list.

' ConvDatum VBScript demo - Eye4Software GPS Toolkit
' This demo shows how to convert a latitude/longitude coordinate from one map datum to another.
' For more information on how to use the Eye4Software GPS Toolkit with VBScript, 
' visit http://www.eye4software.com/products/gpstoolkit/source#vbscript

Option Explicit

Dim objSrcDatum, objDstDatum, objProjection

Set objSrcDatum		= CreateObject ( "Eye4Software.GpsDatumParameters" )
Set objDstDatum		= CreateObject ( "Eye4Software.GpsDatumParameters" )
Set objProjection = CreateObject ( "Eye4Software.GpsProjection" )

' Set Source Datum ( WGS84 )
' The ID for WGS84 is 4326, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums 
' To convert from another datum, just change the code below (EPSG code)
' To define your own datum, please have a look at on of the 'ConvGridUser' VBScript demos.

objSrcDatum.LoadFromId(4326)

' Set Destination Datum ( NAD27 )
' The ID for NAD27 is 4267, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums 
' To convert to another datum, just change the code below (EPSG code)
' To define your own datum, please have a look at on of the 'ConvGridUser' VBScript demos.

objDstDatum.LoadFromId(4267)

' Set source latitude and longitude coordinates
objProjection.Latitude  =   33.59
objProjection.Longitude = -112.15

' Perform map datum conversion

WScript.Echo "Convert from WGS84 to NAD27"
WScript.Echo
WScript.Echo "Latitude    = " & objProjection.Latitude
WScript.Echo "Longitude   = " & objProjection.Longitude
WScript.Echo

objProjection.TransformDatum objSrcDatum, objDstDatum

' Return the result and display converted latitude and longitude coordinates
WScript.Echo "Result: " & objProjection.LastError & " (" & objProjection.LastErrorDescription & ")"
WScript.Echo
If ( objProjection.LastError = 0 ) Then
	WScript.Echo "Latitude    = " & objProjection.Latitude
	WScript.Echo "Longitude   = " & objProjection.Longitude
End If

WScript.Echo "Ready."