I've got a python script that is comparing extents of rasters in various projections. Generally it works, but sometimes, especially when the rasters are global in extent or cross the dateline it fails. In effect I need an algorithm that will return if a longitude is 'more east' of another one. A simple greater than breaks down is some cases.

For example:

lon1 = 175
lon2 = 177
lon3 = -181

lon1 > lon2 #returns True lon2 is 'more east' than lon1  
lon1 > lon3 #falsely returns False even though lon3 is more east than lon 1  

And I don't think I can do a simple transform of my longitude to 0-360 as I don't have control over the incoming coordinate system. For example, in one custom Mollweide projection I'm working on 'x' is in meters and range from -18040094 to 18043982

  • 1
    FYI, longitude, not latitude. Some sort of check for +/-, and you might want to put everything into +/-180 range first (-181 = +179). It shouldn't matter what CRS the data has as you could convert the extent to degrees. – mkennedy Jul 17 '13 at 16:57
  • Surely you mean "lon1 > lon2 #returns False which is correct because lon2 is 'more east' than lon1"? And "lon1 > lon3 # returns True even though lon3 is more east than lon 1"? Difficult to answer when there are so many errors in the question. – Martin F Jul 17 '13 at 17:32
  • Also, are you sure your Mollweide coords are in meters and not degrees x 10 to the 5th? If they are meters then, as mkennedy says, you're mixing units (or projections) and you have a bigger problem. – Martin F Jul 17 '13 at 17:40

I think mkennedy and martin f are right in the comments; you're mixing up units. No matter what projection you use, you can't go beyond +/- 180 degrees longitude.** So the X value you are seeing isn't degrees, it just happens to look like it.

For instance, if you were to convert that Mollweide X = -18040094 you should get approximately -179.99999 degrees.

** At least I think this statement is right, please correct me if not.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.