# How do I convert between different east longitude coordinates?

I have two datasets that represent longitude in different ways. The first represents longitude as degrees from east to 180, but then as negative east so that I have a series which looks like:

[0:180, -180:0];


I then have another dataset that represents longitude as degrees east but with a range of 0 to 360, i.e.:

0:360;


In order to convert these to the same format, can I simply use this?

lon2(lon2 > 180) = lon2(lon2 > 180)-360;


Note my example here is written in MATLAB. This basically shows that I can change the second longitude coordinates by simply subtracting 360 from those longitude values that are greater than 180. Does this make sense?

The database with the negative longitude angles is storing longitude as eastings and westings, whereas the other database is storing everything as eastings.

It appears you prefer your data as eastings and westings. Your methodology for changing eastings greater than 180 degrees to westings is correct: where the longitude angle is greater than 180 subtract 360 from it (i.e. longitude angle - 360).

In Matlab if you have the mapping toolbox you can simply do:

lon2=wrapTo180(lon2);

And your approach is totally right, but if you have to do it more often or with other dataset with diferent conventions you can set up functions analogous to those in the maping toolbox. Such as:

function lon = wrapTo180(lon)
q = (lon < -180) | (180 < lon);
lon(q) = wrapTo360(lon(q) + 180) - 180;


And

function lon = wrapTo360(lon)
positiveInput = (lon > 0);
lon = mod(lon, 360);
lon((lon == 0) & positiveInput) = 360;

• This requires the Mapping Toolbox. If the OP's institution has not paid for this, it might be worth creating a similar function using the (correct) formulation in the question. Jan 5 '18 at 10:16
• You are right, I've edited the answer accordingly. Jan 5 '18 at 16:32