5,781,349 members and growing! (89 online)
Email Password   helpLost your password?
General Programming » Algorithms & Recipes » Data Structures     Intermediate

Java GIS Coordinate class

By Tomer Petel

This is a JAVA class that can represent a GIS coordinate in your program, and allow you to "move", or translate, the coordinate given distance and direction.
Java, Java, Win2K, WinXP, Win2003, Windows, Architect, Dev

Posted: 23 Jun 2004
Updated: 23 Jun 2004
Views: 25,153
Bookmarked: 10 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
3 votes for this Article.
Popularity: 1.62 Rating: 3.40 out of 5
1 vote, 33.3%
1
0 votes, 0.0%
2
1 vote, 33.3%
3
0 votes, 0.0%
4
1 vote, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article presents GISCoordinate.java - a class that allows you to represent a GIS coordinate in your JAVA code in decimal degrees (38.4443, e.g. 122.33433) , minute degrees (33 44 22E, 122 33 44N), or radian degrees. Also, you can use this class to manipulate the coordinate, moving it around the globe by giving it distances in feet and direction of travel. You can then extract the new coordinate that is calculated after the travel.

Background

In one of my application I had to be able to export data that was drawn on a bitmap map to GIS software. I realized I needed some class to represent a GIS coordinate and allow me to manipulate (move) it. The complication here lies in the fact that to generate a new coordinate using an existing coordinate, direction of travel and distance of travel, one needs to take into account the fact that the earth is round, not flat and its roundness is not defined by any standard geometrical shape. Therefore, there are various formulas that you may use for this calculation, depending on what you believe the earth shape to be. The common methods are:

Sphere
WGS84/NAD83/GRS80
Clarke (1866)/NAD27
International
Krasovsky
Bessel (1841)
WGS72
WGS66
FAI sphere

The class presented here allows you to:

Construct itself given a set of coordinates in degree minutes format or decimal degrees (e.g. 37:55:15N , 122:20:59W or their decimal equivalents).

Move the coordinate any number of feet and to any direction (0-360 deg) and have the new Latitude and Longitude automatically updated to the new location. The calculation for the movement will be done using a method of your choice from the above 9 mentioned.

Print out the latitude and longitude in either Decimal Degrees or Degrees Minutes Seconds.

Credits: I based my code on the JavaScript code presented by Ed Williams, at: http://williams.best.vwh.net/gccalc.htm which of course had to be completely re-written in Java and wrapped in a nice object oriented wrapper.

Using the code

GISCoordinate.java does have a main method that exemplifies the usage of the class. Basically here are a few pointers:

You typically instantiate the class as follows:

GISCoordinate g = new GISCoordinate("37:55:15","N","122:20:59","W");

This provides you with an object that represents the GIS coordinate:
Longitude:37 degrees 55 minutes 15 seconds North
Latitude:  122 degrees 20 minutes 59 seconds West

To see the representation of this in Decimal Degrees:

g.printDEGDEC(System.out);

You can then move the coordinate to any direction and any distance:

double movedist=2640;//5280.0;

double movedeg=167; 
System.out.println("Moving "+movedist+" Feet, in a direction of "+movedeg+" degrees...");
g.move(movedist, movedeg, NAD83);

Note that movedist is the distance in feet to move (in this case half a mile) and movedeg is the degree of movement (from 0-360, so this would be south east'ish). Also note that NAD83 method was picked, which assumes the earth to be of a certain shape. Of course, another method could have been used out of the aforementioned 9. Look at the constants declared in the beginning of the class implementation, to see the variable names of the different ones you can choose from.

The new location can be printed again:

g.printDEGDEC(System.out);

The demo is self contained in the actual class. To compile and run the demo:

1. Extract the zip file (Attached to this article) contents into c:\temp while preserving the zip dir structure.
2. open cmd and cd into temp. Then issue on the command line:

 javac com\ha\common\gis\*.java

3. Then, to run the demo, issue on the command line:

java -classpath c:\temp\ com.ha.common.gis.GISCoordinate

To use this class in your code, you can modify the package name to suit your package scheme and call on it as per the examples in the main() method

History

Initial version: 6-24-2004

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Tomer Petel



Location: United States United States

Other popular Algorithms & Recipes articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneralThanksmembertomolsz6:24 1 Jul '08  
GeneralThat was the BestmemberH_LionHeart14:43 11 Jul '04  
GeneralRe: That was the BestmemberTomer Petel15:28 11 Jul '04  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 23 Jun 2004
Editor:
Copyright 2004 by Tomer Petel
Everything else Copyright © CodeProject, 1999-2009
Java | Advertise on the Code Project