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

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 for Java

The Eye4Software GPS toolkit allows software developers to add GPS functionality to their own programs without the need to have any knowledge on geodesy and map projection formulas.

The product can be used to develop software for many operating systems, including: Linux, Windows, Solaris and Android. But also web oriented platforms by using Applets.

Prerequisites

In order to develop GPS software using the GPS Toolkit and Java, you have to download and install the Java Developer Kit (JDK) from Oracle. The next step is to install a code editor. It is very well possible to develop Java applications from the command line interface (CLI), however, we strongly suggest to download a (free) Java IDE such as Eclipse or Netbeans. Finally, you have to download and install the Eye4Software GPS toolkit for Java.

Creating the project

Import, declare and create the object(s)

Add the following import statement on top of the code that will be using the GPS Toolkit classes and interfaces:

import GpsToolkit.*;

In your class, add the following code to declare the GPS Toolkit interfaces:

IGpsDatumParameters objDatumSrc;
IGpsDatumParameters objDatumDst;
IGpsGridParameters  objGridSrc;
IGpsGridParameters  objGridDst;
IGpsGridParameters  objProjection;

And the following code to create an instance of the objects (for instance in the constructor of your class):

IGpsDatumParameters objSrcDatum = new GpsDatumParameters ();
IGpsDatumParameters objDstDatum = new GpsDatumParameters ();
IGpsGridParameters objSrcGrid = new GpsGridParameters ();
IGpsGridParameters objDstGrid = new GpsGridParameters ();
IGpsProjection objProjection = new GpsProjection ();

The source code

The source code below demonstrates how to add latitude / longitude to SPCS transformation functionality (and inverse) to your Java applications using the GPS Toolkit for Java. If this code runs correctly, it should return the following output:

Converting Geographic NAD83 coordinates to State Plane Coordinate System coordinates
(NAD83) 25.606400 N, 80.502124 W => (SPCS83) Northing: 141106.346, Easting: 250008.594
Ready.

Paste the following code in your Java IDE to run the code. The following code is also shipped with the GPS Toolkit for Java package:

package Samples;

import GpsToolkit.*;

public class ConvStatePlane 
{
  public static void main(String[] args) 
  {
    IGpsProjection objProjection = new GpsProjection ();
    IGpsGridParameters objSrcGrid = new GpsGridParameters ();
    IGpsGridParameters 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' Java demo.
    objSrcGrid.LoadFromId ( 4269 );
		
    // Set Destination Grid ( State Plane CPCS83 )
    // 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' Java demo.
    objDstGrid.LoadStatePlane ( 901 );
		
    // Set source latitude and longitude
    objProjection.set_Latitude  (  25.606400 );
    objProjection.set_Longitude ( -80.502124 );
					
    System.out.println ( "Converting Geographic NAD83 coordinates to State Plane Coordinate System coordinates");
		
    try
    {
      objProjection.TransformGrid ( objSrcGrid, objDstGrid );
			
      System.out.format ("(NAD83) 25.606400 N, 80.502124 W => (SPCS83) Northing: %3.3f, Easting: %3.3f\n", 
                          objProjection.get_Northing(), objProjection.get_Easting() );
    }
    catch (GpsException e)
    {
      System.out.println( "An error occured during conversion: " + e.get_ErrorDescription() );
    }
		
    System.out.println ( "Ready." );
  }
}