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

Download Eye4Software GPS Toolkit free trial Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free
Download Eye4Software Coordinate GPS Toolkit Manual Download Eye4Software GPS Toolkit Manual
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 and the Eye4Software GPS Component installed on your computer. We will use Visual Basic 6.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

Start the Visual Basic IDE, and select the "New Project" option from the "File" menu. The "New Project" dialog now appears, select the "Standard EXE" option to generate a Windows GUI application.

State Plane Coordinate System transformations using Visual Basic

Add a reference to the ActiveX component

In order to declare and create the objects from your Visual Basic application, you need to add a reference to the ActiveX object, by choosing the "References" option from the "Project" menu. A list of components installed on the system is displayed. Just check the checkbox in front of the "Eye4Software GPS Toolkit 3.0" and click "OK".

State Plane Coordinate System transformations using Visual Basic

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 Form_Load handler. Paste the following code in this function:

Set objProjection = CreateObject ("Eye4Software.GpsProjection")
Set objGridSrc    = CreateObject ("Eye4Software.GpsGridParameters")
Set objGridDst    = CreateObject ("Eye4Software.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 NAD27 to SPCS27 Arizona Central. For a list of other U.S. State Plane zones, please refer to our U.S. State Plane information page.

Option Explicit

'/////////////////////////////////////////////////////////////////////////

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

'/////////////////////////////////////////////////////////////////////////

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

    ' Set Destination Grid ( SPCS27 Arizona Central )
    ' The ID for SPCS27 Arizona Central is 10202, see 'http://www.eye4software.com/resources/stateplane' for a list of grids 
    ' To convert to another grid, just change the code below (SPCS code)
    objGridDst.LoadStatePlane (10202)
    
    ' Set Source coordinates
    objProjection.Latitude  = CDbl(TextLatitude.Text)
    objProjection.Longitude = CDbl(TextLongitude.Text)

    ' Perform the datum transformation
    objProjection.TransformGrid objGridSrc, objGridDst

    ' Display the result
    TextNorthing.Text = objProjection.Northing
    TextEasting.Text = objProjection.Easting
    
End Sub

'/////////////////////////////////////////////////////////////////////////

Private Sub Form_Load()
    ' Create the objects
    Set objProjection = CreateObject("Eye4Software.GpsProjection")
    Set objGridSrc = CreateObject("Eye4Software.GpsGridParameters")
    Set objGridDst = CreateObject("Eye4Software.GpsGridParameters")
      
    ' Set default values for input boxes
    TextLatitude.Text = "35.835573"
    TextLongitude.Text = "-111.768163"
End Sub

'/////////////////////////////////////////////////////////////////////////

The following sample shows how to implement the reverse conversion (from State Plane Coordinate System to Latitude and Longitude).

Option Explicit

'/////////////////////////////////////////////////////////////////////////

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

'/////////////////////////////////////////////////////////////////////////

Private Sub CommandTranslate_Click()

    ' Set Source Grid ( SPCS27 Arizona Central )
    ' The ID for SPCS27 Arizona Central is 10202, see 'http://www.eye4software.com/resources/stateplane' for a list of grids 
    ' To convert to another grid, just change the code below (SPCS code)
    objGridSrc.LoadStatePlane (10202)
    
	' Set Destination Grid ( NAD27, Geographic Latitude and Longitude  )
    ' The ID for NAD27 is 4267, see 'http://www.eye4software.com/resources/datums' for a list of supported datums 
    ' To convert from another datum or grid, just change the code below (EPSG code)
    objGridDst.LoadFromId(4267)
	
    ' Set Source coordinates
    objProjection.Northing  = CDbl(TextNorthing.Text)
    objProjection.Easting   = CDbl(TextEasting.Text)

    ' Perform the datum transformation
    objProjection.TransformGrid objGridSrc, objGridDst

    ' Display the result
    TextLatitude.Text  = objProjection.Latitude
    TextLongitude.Text = objProjection.Longitude
    
End Sub

'/////////////////////////////////////////////////////////////////////////

Private Sub Form_Load()
    ' Create the objects
    Set objProjection = CreateObject("Eye4Software.GpsProjection")
    Set objGridSrc = CreateObject("Eye4Software.GpsGridParameters")
    Set objGridDst = CreateObject("Eye4Software.GpsGridParameters")
      
    ' Set default values for input boxes
    TextNorthing.Text  = "1147929.095"
    TextLongitude.Text =  "323008.538"
End Sub

'/////////////////////////////////////////////////////////////////////////