3
$\begingroup$

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?

$\endgroup$

3 Answers 3

9
$\begingroup$

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).

$\endgroup$
3
$\begingroup$

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;
$\endgroup$
2
  • 1
    $\begingroup$ 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. $\endgroup$ Jan 5, 2018 at 10:16
  • 1
    $\begingroup$ You are right, I've edited the answer accordingly. $\endgroup$ Jan 5, 2018 at 16:32
0
$\begingroup$

If you wish to convert west-east longitude to eastward longitude, you can use the loop below, where lon represents your matrix with west-east longitude:

N = length (lon)

long = abs (lon);

i=1;

while i<N+1;

  eastward_long(i) = (long(i) - floor(long(i) / 360) * 360) * (lon(i) / long(i)) - 180 * ((lon(i) / long(i)) - 1); 

  i = i + 1;

end
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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