Share |

Convert (GPS) coordinates to U.S. State Plane coordinates using VBScript

Download 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 State Plane Coordinate System (SPS or SPCS) is a set of 124 coordinate systems designed for specific regions of the United States. There are two variations of the system, one uses NAD27 as map datum, also called SPCS27, the second one uses NAD83 as map datum, this system is known as SPCS83. SPCS27 grids mostly use U.S. Survey Foot as output units, while the SPCS83 grids use Meters. Each state contains one or more state plane zones, the boundaries of which usually follow county lines. There are 110 zones in the continental US, with 10 more in Alaska, 5 in Hawaii, and one for Puerto Rico and US Virgin Islands.

The system is widely used for geographic data by state and local governments. Its popularity is due to at least two factors. First, it uses a simple Cartesian coordinate system to specify locations rather than a more complex spherical coordinate system (the geographic coordinate system of latitude and longitude). By thus ignoring the curvature of the Earth, "plane surveying" methods can be used, speeding up and simplifying calculations. Second, the system is highly accurate within each zone (error less than 1:10,000). Outside a specific state plane zone accuracy rapidly declines, thus the system is not useful for regional or national mapping.

The Eye4Software GPS Toolkit

The Eye4Software GPS toolkit allows software developers to add GPS functionality to their programs or scripts, like reading position information from a GPS, calculating distance and azimuth between two coordinates, map datum and map grid conversion. Using the GPS toolkit, it is not required to have any knowledge on serial communications, GPS protocols like RS-232 and NMEA0183, math and geodesy.

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 VBScript 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 VBScript, 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 objGridSrc
Dim objGridDst

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

Set objProjection   = CreateObject ( "Eye4Software.GpsProjection" )
Set objGridSrc      = CreateObject ( "Eye4Software.GpsGridParameters" )
Set objGridDst      = CreateObject ( "Eye4Software.GpsGridParameters" )

The source code

The source code below demonstrates how to add latitude / longitude to SPCS transformation functionality to your scripts using the GPS Toolkit. If this code runs correctly, it should return the following output:

Eye4Software GPS Toolkit 3.2.10.823 (x64) - StatePlane Conversion Demo

Convert from Latitude / Longitude to State Plane (SPCS83) #0202

Latitude    = 31.523864
Longitude   = -110.836469

Result: 0 (Success)

Northing    = 58582.7381004059
Easting     = 315947.72870971
Ready.

Paste the following code in your VBScript editor to run the code. The following code is also shipped with the GPS Toolkit package:

' ConvStatePlane VBScript demo - Eye4Software GPS Toolkit
' This demo shows how to convert a latitude/longitude coordinate to an U.S. State Plane coordinate.
' 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 objProjection
Dim objGridSrc
Dim objGridDst

Set objProjection   = CreateObject ( "Eye4Software.GpsProjection"     )
Set objGridSrc      = CreateObject ( "Eye4Software.GpsGridParameters" )
Set objGridDst      = CreateObject ( "Eye4Software.GpsGridParameters" )

WScript.Echo "Eye4Software GPS Toolkit " & objProjection.Version & " - StatePlane Conversion Demo" 
WScript.Echo

' Set Source Grid ( NAD83, Geographic Latitude and Longitude  )
' The ID for NAD83 is 4269, see 'http://www.eye4software.com/resources/datums' for a full list of supported datums 
' To convert from another datum or grid, just change the code below (EPSG code)
objGridSrc.LoadFromId ( 4269 )

' Set Destination Grid ( State Plane SPCS83 )
' The ID for the Arizona Central is 0202, see 'http://www.eye4software.com/resources/stateplane' for a full list 
' To convert to another datum or grid, just change the code below (SPC27 or SPC83 code)
objGridDst.LoadStatePlane ( 202 )

' Set Source coordinates ( NAD83 )
objProjection.Latitude		=   31.523864
objProjection.Longitude		= -110.836469

WScript.Echo "Convert from Latitude / Longitude to State Plane (SPCS83) #0202"
WScript.Echo
WScript.Echo "Latitude    = " & objProjection.Latitude
WScript.Echo "Longitude   = " & objProjection.Longitude
WScript.Echo

' Perform the transformation
objProjection.TransformGrid objGridSrc, objGridDst

' Return the result
WScript.Echo "Result: " & objProjection.LastError & " (" & objProjection.LastErrorDescription & ")"
WScript.Echo
If ( objProjection.LastError = 0 ) Then
	WScript.Echo "Northing    = " & objProjection.Northing
	WScript.Echo "Easting     = " & objProjection.Easting
End If

WScript.Echo "Ready."