|
Download the Eye4Software GPS Toolkit fully functional 30 day trial version for free |
|
Browse through the Eye4Software GPS Toolkit manual |
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 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.
First you must have Visual C++ and the Eye4Software GPS Component installed on your computer. We will use Visual C++ 6.0 in this document, but all versions from 6.0 and up can be used. You can download the Eye4Software GPS Component here.
Start the Visual C++ IDE, and select the "New" option from the "File" menu. The "New Project" dialog now appears, you can use the dialog to enter the name of your product. Select "Win32 Console Application" if you wish to create a console application, or select the "MFC AppWizard" option to create a project with a GUI.
In order to declare and create the objects from your Visual C++ application, you need to copy the include files of the ActiveX control to your project directory. You can create an include folder in your project folder where you store these files. These files can be found in the "Samples\Visual C++\Include" folder from the installation directory.
Once you copied the include files, you have to declare these files in your source code like this:
#include "include\GpsCtrl.h" #include "include\GpsConstantsX.h" #include "include\GpsCtrl_i.c"
You can also include the ".c" file in your project instead of using the #include directive for this file.
The objects can be declared in your code like this:
IGpsProjection * pProjection = NULL; ' The projection object IGpsGridParameters * pGridSrc = NULL; ' The Source Grid IGpsGridParameters * pGridDst = NULL; ' The Destination Grid
You can create instances of the objects like this:
CoCreateInstance ( CLSID_GpsProjection, NULL, CLSCTX_INPROC_SERVER, IID_IGpsProjection, ( void ** ) &pProjection ); CoCreateInstance ( CLSID_GpsGridParameters, NULL, CLSCTX_INPROC_SERVER, IID_IGpsGridParameters, ( void ** ) &pGridSrc ); CoCreateInstance ( CLSID_GpsGridParameters, NULL, CLSCTX_INPROC_SERVER, IID_IGpsGridParameters, ( void ** ) &pGridDst );
The pProjection, pGridSrc and pGridDst pointers should not be zero after the CoCreateInstance calls, if this is the case, creation of the instance has failed. In this case please check the following:
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 NAD23 to SPCS27 California Zone III. For a list of other U.S. State Plane zones, please refer to our U.S. State Plane information page.
// ConvStatePlane Visual C++ demo - Eye4Software GPS Toolkit
// This demo shows how to convert a GPS coordinate to a State Plane Coordinate System coordinate.
// For more information on how to use the Eye4Software GPS Toolkit with Visual C++,
// visit http://www.eye4software.com/products/gpstoolkit/source#vc
////////////////////////////////////////////////////////////////////////////////////////////
#include <windows.h>
#include <comutil.h>
#include <stdio.h>
////////////////////////////////////////////////////////////////////////////////////////////
#include "..\Include\GpsCtrl.h"
////////////////////////////////////////////////////////////////////////////////////////////
IGpsProjection * pProjection = NULL;
IGpsGridParameters * pGridSrc = NULL;
IGpsGridParameters * pGridDst = NULL;
DOUBLE fNorthing = 0.0;
DOUBLE fEasting = 0.0;
LONG lLastError = 0L;
BSTR bstrLastError = NULL;
////////////////////////////////////////////////////////////////////////////////////////////
int main(int argc, char* argv[])
{
// Initialize COM
CoInitialize ( NULL );
// Create instance of GpsProjection object
CoCreateInstance ( CLSID_GpsProjection, NULL, CLSCTX_INPROC_SERVER, IID_IGpsProjection, ( void ** ) &pProjection );
if ( pProjection == NULL )
{
printf ( "Failed to create instance of GpsProjection object\n" );
goto _EndMain;
}
// Create instances of the GpsGridParameters object to specify source and destination grid
CoCreateInstance ( CLSID_GpsGridParameters, NULL, CLSCTX_INPROC_SERVER, IID_IGpsGridParameters, ( void ** ) &pGridSrc );
CoCreateInstance ( CLSID_GpsGridParameters, NULL, CLSCTX_INPROC_SERVER, IID_IGpsGridParameters, ( void ** ) &pGridDst );
if ( pGridDst == NULL )
{
printf ( "Failed to create instance of GpsgridParameters object\n" );
goto _EndMain;
}
if ( pGridSrc == NULL )
{
printf ( "Failed to create instance of GpsgridParameters object\n" );
goto _EndMain;
}
// Set Source Grid ( NAD27, Geographic Latitude and Longitude )
// The ID for NAD27 is 4267, 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++ demo.
pGridSrc->LoadFromId ( 4267 );
// Set Destination Grid ( State Plane Coordinate System SPCS27 California Zone III)
// The ID for California Zone III is 10403, see 'http://www.eye4software.com/resources/stateplane' for a full list
// 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++ demo.
pGridDst->LoadStatePlane ( 10403 );
// Set Source Latitude and Longitude in decimal degrees format
pProjection->put_Latitude ( 37.793250 );
pProjection->put_Longitude ( -122.554783 );
// Perform the map projection
// For reverse operation, just swap the pGridSrc and pGridDst parameters,
// and use put_Northing and put_Easting to set source coordinates
pProjection->TransformGrid ( &variant_t ( ( IDispatch * ) pGridSrc ), &_variant_t ( ( IDispatch * ) pGridDst ) );
// Get the result of the operation
pProjection->get_LastError ( &lLastError );
// If success, print the result, otherwise display error description:
if ( lLastError == 0L )
{
pProjection->get_Northing ( &fNorthing );
pProjection->get_Easting ( &fEasting );
printf ( "(NAD27 => California Zone III SPCS27 #0403)\n" );
printf ( "Northing = %3.2lf, Easting = %3.2lf (U.S. Feet)\n" , fNorthing, fEasting );
}
else
{
pProjection->get_LastErrorDescription ( &bstrLastError );
printf ( "Error occured map projection: %ld (%ls)\n", lLastError, bstrLastError );
SysFreeString ( bstrLastError );
}
printf ( "Ready.\n\n" );
_EndMain:
if ( pProjection )
{
pProjection->Release ();
pProjection = NULL;
}
if ( pGridSrc )
{
pGridSrc->Release ();
pGridSrc = NULL;
}
if ( pGridDst )
{
pGridDst->Release ();
pGridDst = NULL;
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////////////////
After running this sample application, the following output is returned on the command line:
(NAD27 => California Zone III SPCS27 #0403) Northing = 477392.55, Easting = 1406302.54 (U.S. Feet) Ready.