Longitude Range
QUESTION: My longitude values range from -180 to 180. To be consistent with some other programs, I need them to range from 0 to 360. I can't just add 180 to each longitude value, since that will rotate my coordinate system by 180 degrees. What is the proper algorithm to use to make this conversion?
ANSWER: The answer is supplied by Ken Bowman in a 2 May 2005 article on the IDL newsgroup.
The proper way to convert the longitude values (assumed to be in the variable lon) that are in the range -180 to 180 to the range 0 to 360 (in the variable t_lon) is like this:
t_lon = (lon + 360.0) MOD 360.0
The reverse transformation (converting data in the range 0 to 360, tlon, to the range -180 to 180) is done like this:
lon = t_lon - (LONG(t_lon )/180)*360.0
Another formula, offered by Craig Markwardt to do the same thing, is this:
lon = ((t_lon + 180) MOD 360) - 180
Copyright © 2005-2006 David W. Fanning
Last Updated 1 March 2006