Geographic coordinate conversion

From Wikipedia, the free encyclopedia

Geographic coordinates consist of latitude and longitude. There are many ways of writing coordinates, and converting between the different ways is non-obvious but also quite trivial.

Contents

All of the following are valid and acceptable ways to write geographic coordinates:

  • 40:26:46N,79:56:55W
  • 40:26:46.302N 79:56:55.903W
  • 40°26'21"N 79°58'36"W
  • 40d 26' 21" N 79d 58' 36" W
  • 40.446195N 79.948862W
  • 40.446195, -79.948862
  • 40° 26.7717, -79° 56.93172

Coordinates here are generally written as 40°26′21″N, 79°58′36″W.

There are three basic forms of a coordinate.

  1. Coordinate containing degrees (integer), minutes (integer), and seconds (integer, or real number) (DMS).
  2. Coordinate containing degrees (integer) and minutes (real number) (MinDec).
  3. Coordinate containing only degrees (real number) (DegDec).

All forms of coordinates are capable of representing the same amount of data and the same precision. Depending on which type of coordinate you are provided with, and which type you would like to work with, you may have to do some conversion.

In its most simple form a coordinate is just a number of degrees. The tricky part comes in when you need to differentiate North/South latitude or West/East longitude, or make the number more digestible by writing it with minutes and seconds instead of as a decimal number.

The degrees portion of the coordinate is always going to be the easiest to figure out. The degrees is always the left-most whole number. For example:

40:26:46N         40
W87°43'41         87

A sphere is divided into 360 degrees. The number space is divided into two halves, East and West in the case of longitude and North and South in the case of latitude. The maximum ranges are as follows:

Longitude
 180 W   = -180
 180 E   =  180
Latitude
  90 N   =   90
  90 S   =  -90

Technically you could have latitudes greater than 90 or less than -90, but this is an ambiguous case, since there would be an equivalent coordinate with an inverse longitude.

The minimal case is that you have only degrees:

 40.446111  or
 40.446111N

Minutes are an optional component, as is implied by the minimal case of degrees. If there is no minutes component, the degrees component contains the entire precision of the coordinate and there must not be a seconds component. Minutes are actually the numerator component of a fraction with denominator 60 of one degree.

With the same examples as above:

40:26:46N         26
W87°43'41         43

In the first case, the number of minutes is 26.

Seconds are also an optional component, and can only exist if the minutes component also exists. Seconds are the numerator component of a fraction with denominator 60 of one minute.

40:26:46N         46
W87°43'41         41

In the second case, the number of seconds is 41.

To convert, 41 seconds is equal to \frac{41}{60} = 0.68\bar{3} minutes.

Given a DMS coordinate such as W87°43'41", it's trivial to convert it to a number of decimal degrees using the following method:

  • Calculate the total number of seconds, 43'41" = (43*60 + 41) = 2621 seconds.
  • The fractional part is total number of seconds divided by 3600. 2621 / 3600 = ~0.728056
  • Add fractional degrees to whole degrees to produce the final result: 87 + 0.728056 = 87.728056
  • Since it is a West longitude coordinate, negate the result.
  • The final result is -87.728056.

Given a decimal longitudinal coordinate such as -87.728055 it is trivial to convert it to DMS form. It will be necessary to know whether it is a latitudinal or longitudinal coordinate in order to fully convert it. The method is as follows:

  • Subtract the whole number portion of the coordinate, leaving the fractional part. The whole number is the number of degrees. 87.728055 = 87 degrees.
  • Multiply the remaining fractional part by 60. This will produce a number of minutes in the whole number portion. 0.728055 x 60 = 43.6833 = 43 minutes.
  • Multiply the fractional part of the number of minutes by 60, producing a number of seconds. 0.6833 x 60 = 40.998 = 41 seconds. It is possible to count this as 40 seconds, truncating the decimal, round it to 41, or keep the entire number.
  • Depending on whether the source number was a latitudinal or longitudinal coordinate, and the sign of the number, add the N/S/E/W specifier. The following table shows the possibilities:
  Type   Dir.   Sign    Test
  Lat.   N      +       > 0
  Lat.   S      -       < 0
  Long.  E      +       > 0
  Long.  W      -       < 0

A coordinate with at 0°0'0" latitude or longitude is neither North nor South, East nor West. It is simply zero latitude or zero longitude.

  • The final result is: W 87°43'41".

The most common programmatical use of these processes is to display a coordinate to an end user in the more common DMS form instead of decimal form. Some example code in the PHP programming language to do this is:

function pretty_coord($coord) {
  return sprintf("%0.0f° %2.3f",
                 floor(abs($coord)),
                 60*(abs($coord)-floor(abs($coord))));
}
function pretty_coords($latitude, $longitude) {
  return sprintf("%s %s, %s %s",
                 ($latitude>0)?"N":"S",  pretty_coord($latitude),
                 ($longitude>0)?"E":"W", pretty_coord($longitude));
}


Alternatively, a more elaborate but easier to follow PHP example:

function gpsconv_dec_dms( $fl_deg ) {

// assume input is in the form "123.45678"

$fl_deg = abs( $fl_deg );

while ( $fl_deg > 360.0 )
  { $fl_deg -= 360.0; }

$deg = intval( $fl_deg );

$fl_secs = 3600.0 * ( $fl_deg - floatval( $deg ) );

$min = intval( $fl_secs / 60.0 );

$fl_fract = ( $fl_secs / 60.0 ) - floatval( $min );

$sec = round( 60.0 * $fl_fract );
if ( $sec < 10 )
  { $sec = '0' . $sec; }

return( "$deg:$min:$sec" );
}

Advanced Search
Included Web Search Engines


Safe Search

close

Top Matching Results

Occasionally Search.com will highlight specialized results that are based on the context of your query. Examples of specialized results include specific links to news, images, or video.

Top Matching Results may highlight information from other Search.com pages, content from the CNET Network of sites, or third party content. The listings are based purely on relevance. Search.com does not receive payment for listings in this section but our partners that provide this data may get paid for listing these products.

Sponsored Links

This section contains paid listings which have been purchased by companies that want to have their sites appear for specific search terms and related content. These listings are administered, sorted and maintained by a third party and are not endorsed by Search.com.

Search Results

Search.com sends your search query to several search engines at one time and integrates the results into one list which has been sorted by relevance using Search.com's proprietary algorithm. You can customize the list of search engines included in your metasearch from the preferences.

The search engines that are used in your metasearch may allow companies to pay to have their Web sites included within the results. To view the Paid Inclusion policy for a specific search engine, please visit their Web site. Search.com does not accept payment or share revenue with any search engine partner for listings in this section.