Share |

Convert (GPS) coordinates to U.S. State Plane coordinates using Visual Basic .NET

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 Visual Basic .Net and the Eye4Software GPS Component installed on your computer. We will use Visual Basic .NET 2003 in this document, but other versions from 2002 and up can be used. You can download the Eye4Software GPS Component here.

Creating the project

Start the Visual Studio IDE, and select the "New" => "Project" option from the "File" menu. The "New Project" dialog now appears, select the "Windows Application" option to generate a Windows GUI application.

Add a reference to the ActiveX component

In order to declare and create the objects from your Visual Basic .Net application, you need to add a reference to the ActiveX object, by choosing the "Add Reference..." option from the "Project" menu. A list of components installed on the system is displayed. Just select the "COM" tab, and select the "Eye4Software GPS Toolkit 3.0", click "Select" and finally click "OK".

Declare and create the object(s)

After adding the reference to the control, you can declare the objects like this:

Private objProjection As GpsProjection
Private objGridSrc    As GpsGridParameters
Private objGridDst    As GpsGridParameters

The objects can be created in your code by double clicking on the Form you created, this will open the Formx_Load handler. Paste the following code in this function:

objProjection = New GpsProjection
objGridSrc    = New GpsGridParameters
objGridDst    = New GpsGridParameters

The source code

The following samples show how to perform a coordinate conversion from (GPS) latitude / longitude coordinates to U.S. State Plane coordinates using the GPS Toolkit. In this example a position is transformed from NAD83 to SPCS83 Arizona Central. For a list of other U.S. State Plane zones, please refer to our U.S. State Plane information page.

' ConvGrid Visual Basic .NET 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 Visual Basic .NET, 
' visit http://www.eye4software.com/products/gpstoolkit/source#vbnet

Imports GpsToolkit

Module Module1

    Private objProjection As GpsProjection
    Private objSrcGrid As GpsGridParameters
    Private objDstGrid As GpsGridParameters

    Sub Main()

        objProjection = New GpsProjection
        objSrcGrid = New GpsGridParameters
        objDstGrid = New GpsGridParameters

        ' 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)
        ' To define your own grid or datum, please have a look at the 'ConvUserGrid' Visual Basic .NET demo.
        objSrcGrid.LoadFromId(4269)

        ' Set Destination Grid ( Arizona Central State Plane NAD83)
        ' The ID for the SPCS83 Arizona Central is 0202, see 'http://www.eye4software.com/resources/stateplane' for a full list of supported grids 
        ' To convert to another grid, just change the code below (SPCS code)
        ' To define your own grid or datum, please have a look at the 'ConvUserGrid' Visual Basic .NET demo.
        objDstGrid.LoadStatePlane(202)

        ' Set source latitude and longitude
        objProjection.Latitude = 35.835573
        objProjection.Longitude = -111.768163

        ' Perform map grid transformation
        objProjection.TransformGrid(objSrcGrid, objDstGrid)

        ' Get and display result
        If (objProjection.LastError = 0) Then
            Console.WriteLine("(NAD27 => SPCS83 Arizona Central #0202)")
            Console.WriteLine("Norhing: {0:0.00}, Easting: {1:0.00} (Meter)", objProjection.Northing, objProjection.Easting)
        Else
            Console.WriteLine("Error occured during map grid transformation: {0} ({1})", objProjection.LastError, objProjection.LastErrorDescription)
        End If

        Console.WriteLine("Ready.")
    End Sub
End Module

After a successful run of this demo application, the following output is returned on the command prompt:

(NAD27 => SPCS83 Arizona Central #0202)
Norhing: 536280,49, Easting: 226776,04 (Meter)
Ready.