Share |

Convert (GPS) coordinates to U.S. State Plane coordinates using Visual C# .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 C# .Net and the Eye4Software GPS Component installed on your computer. We will use Visual C# .NET 2003 in this document, but also 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 C# .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 GpsProjection      objProjection;
private GpsGridParameters  objGridSrc;
private GpsGridParameters  objGridDst;

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 Florida East. For a list of other U.S. State Plane zones, please refer to our U.S. State Plane information page.

// ConvStatePlane Visual C# .NET demo - Eye4Software GPS Toolkit
// This demo shows how to convert a latitude/longitude coordinate to U.S. State Plane coordinates.
// For more information on how to use the Eye4Software GPS Toolkit with Visual C# .NET, 
// visit http://www.eye4software.com/products/gpstoolkit/source#vcnet

using System;
using GpsToolkit;

namespace ConvStatePlane
{
	/// 
	/// Summary description for Class1.
	/// 
	class Class1
	{
		/// 
		/// The main entry point for the application.
		/// 
		[STAThread]
		static void Main(string[] args)
		{
			GpsProjection		objProjection	= new GpsProjection ();
			GpsGridParameters	objSrcGrid		= new GpsGridParameters ();
			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 C# .NET demo.
			objSrcGrid.LoadFromId ( 4269 );

			// Set Destination Grid ( State Plane SPCS83 )
			// The ID for Florida East is 0901, 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 C# .NET demo.
			objDstGrid.LoadStatePlane ( 901 );

			// Set source latitude and longitude
			objProjection.Latitude  =  25.606400;
			objProjection.Longitude = -80.502124;

			// Convert the grid
			object objSrc = (object)objSrcGrid;
			object objDst = (object)objDstGrid;
			
			objProjection.TransformGrid ( ref objSrc, ref objDst);

			// Get and display result
			if (objProjection.LastError == 0) 
			{
				Console.WriteLine("(NAD83 => State Plane SPCS83 Florida East)" );
				Console.WriteLine("Northing: {0:0.00} , Easting: {1:0.00} (Meters)", objProjection.Northing, objProjection.Easting);
			}
			else
			{
				Console.WriteLine("Error occured during map grid transformation: {0} ({1})", objProjection.LastError, objProjection.LastErrorDescription);
			}
            
			Console.WriteLine("Ready.");
		}
	}
}

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

(NAD83 => State Plane SPCS83 Florida East)
Northing: 141106,35 , Easting: 250008,59 (Meters)
Ready.