Code covered by the BSD License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

### Highlights from utm2deg

4.47059
4.5 | 17 ratings Rate this file 71 Downloads (last 30 days) File Size: 2.75 KB File ID: #10914 Version: 1.0

# utm2deg

### Rafael Palacios (view profile)

29 Apr 2006 (Updated )

Function to convert vectors of UTM coordinates into Lat/Lon vectors (WGS84)

File Information
Description

This function is based on UTMIP.m function by Gabriel Ruiz Martinez, but instead of providing a GUI it works with vectors of coordinates.

[Lat,Lon] = utm2deg(x,y,utmzone)

% Example 1:
% x=[ 458731; 407653; 239027; 230253; 343898; 362850];
% y=[4462881; 5126290; 4163083; 3171843; 4302285; 2772478];
% utmzone=['30 T'; '32 T'; '11 S'; '28 R'; '15 S'; '51 R'];
% [Lat, Lon]=utm2deg(x,y,utmzone);
% fprintf('%11.6f ',lat)
% 40.315430 46.283902 37.577834 28.645647 38.855552 25.061780
% fprintf('%11.6f ',lon)
% -3.485713 7.801235 -119.955246 -17.759537 -94.799019 121.640266
%
% Example 2: If you need Lat/Lon coordinates in Degrees, Minutes and Seconds
% [Lat, Lon]=utm2deg(x,y,utmzone);
% LatDMS=dms2mat(deg2dms(Lat))
%LatDMS =
% 40.00 18.00 55.55
% 46.00 17.00 2.01
% 37.00 34.00 40.17
% 28.00 38.00 44.33
% 38.00 51.00 19.96
% 25.00 3.00 42.41
% LonDMS=dms2mat(deg2dms(Lon))
%LonDMS =
% -3.00 29.00 8.61
% 7.00 48.00 4.40
% -119.00 57.00 18.93
% -17.00 45.00 34.33
% -94.00 47.00 56.47
% 121.00 38.00 24.96

Acknowledgements

Conversion Of Utm Coordinates To Spherical Coordinates inspired this file.

This file inspired Utm2lonlat.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
 Please login to add a comment or rating.
Comments and Ratings (28)
13 Apr 2016 Andrea Libri

### Andrea Libri (view profile)

16 Dec 2014 Greg Milette

### Greg Milette (view profile)

Usage note: This code requires positive zone values, if you pass in negative zone values it will not return the correct result.

26 May 2014 Stephanie

### Stephanie (view profile)

This one didn't work for me. There is this one on the file exchange as well: utm2ll. It worked and was easy to use (in particular for vectors and matrices).

Comment only
22 May 2014 Cl

### Cl (view profile)

17 Apr 2014 Francesc Melia

### Francesc Melia (view profile)

Thanks for this .m file !

What I like: Useful function and good explanation in the help

What I dislike: just one small comment, input values have to be in float format, not accepting doubles (since 'cos' function does not accept them). Nonetheless, I think it's a great function.

28 Feb 2014 Victor Jara

### Victor Jara (view profile)

This is a great and handy code. I am from the Southern Hemisphere and when using the code I was getting the wrong Lat and Long. I replaced line 80 with what Kristen did and now I get the correct answer. Thanks a lot

18 Feb 2014 jack

### jack (view profile)

thank you so much.

Comment only
11 Dec 2012 r nawaz

### r nawaz (view profile)

Kristen There is nothing wrong at line 80.

It only checks whether the given northing is from Northern or Southern Hemisphere. The S is for Southern hemisphere, and will be subsequently used to determine the latitude.

The script only determines how much above or below the given point is from the Equator. For Northern hemisphere, northing gives this measure. For Southern hemisphere, you find it by subtrating northing - 10000000. Note that in UTM for Southern hemisphere, the equator is given a northing of 10000000.

Comment only
11 Dec 2012 Kristen

### Kristen (view profile)

My comment was incomplete... I fixed my version by replacing line 80 with:

if and(utmzone(i,4)>'M',utmzone(i,4)lessthan'R')

Comment only
11 Dec 2012 Kristen

### Kristen (view profile)

I agree with Carlos Castillo, on line 80 there is no option for it to go to "S". If the utmzone is N or S, it will always default to hemis = 'N'; so I fixed this in my version by replacing this line with :
if and(utmzone(i,4)>'M',utmzone(i,4)<'R')

Otherwise, a very useful script! Thank you.

Comment only
08 Dec 2012 r nawaz

### r nawaz (view profile)

Daniel... you may look details of the UTMIP.m function by Gabriel Ruiz Martinez.

It seems you only need to give different parameters for NAD27 and rest of the script remains the same.

Comment only
28 Nov 2012 Daniel

### Daniel (view profile)

Is there a simple way that I can change this script to output the data in NAD27 instead of WGS94, or would it be a complete rewrite?

Comment only
06 May 2012 r nawaz

### r nawaz (view profile)

Well, if it is the same '30 T' for all values, just set a variable zonn = '30 T', and use it for all conversions.

[lat long] = utm2deg(easting, northing, zonn)

Comment only
05 May 2012 Jane

### Jane (view profile)

For large datasets from the same utm zone, is there an easy way to create the 'utmzone'-variable? (without e.g. having to write utmzone=['30 T'; '30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T';'30 T' (and a 1000 more times '30 T';)...];

Comment only
22 Mar 2012 r nawaz

### r nawaz (view profile)

Zhiyong

In Matlab you may convert your matrix to vector....do the transformation and convert back to matrix.

Comment only
21 Mar 2012 Zhiyong

### Zhiyong (view profile)

Excellent. Will be better if it is possible to do coordinate transformation on a matrix instead of just a vector.

23 Aug 2011 r nawaz

### r nawaz (view profile)

Dear Val Schmidt

While calculating latitude, the function checks whether the alphabetical letter represents Northern Hemisphere or Souther Hemisphere. The Latitude is then calculated by looking at the northing values. The hemisphere is Northern for both X and N. That is why you get the same result for latitude.

Comment only
17 Aug 2011 Val Schmidt

### Val Schmidt (view profile)

I think I must be missing something. I don't see in this code where it offsets the latitude correctly based on the UTM zone character field. For example, I get the same result with '17 N' and '17 X'. The first is at the equator, the second is near Greenland.

09 Feb 2011 Orlando RodrÃ­guez

### Orlando RodrÃ­guez (view profile)

Nice contribution. Thanks Rafael!

15 Nov 2010 Aaron Holtzman

### Aaron Holtzman (view profile)

24 Feb 2010 Cegeon

### Cegeon (view profile)

I like how it converts the lat/lon to the corresponding UTM. Did the same thing via GlobalMapper and matches quite well.

However, if you have a big domain (spanning multiple UTM zones) and you want ALL of the data on just ONE particular UTM zone, that cannot be done (as far as I can tell.)

14 Oct 2008 Carlos Castillo

I found a mistake at line 80.

02 Apr 2008 Oriol Badia
25 Oct 2007 Oren Fromberg

sweet proggy

24 Aug 2007 Zack Moratto

Thanks for this!

30 May 2007 Eddie Mayhew

Rafael,
This function is exactly what I was looking for. Perfect. Simple and easy to use. Results are dead-on accurate. Instructions are well explained in the function's "help" section. Nice.

Eddie

19 Sep 2006 Karel Castro
01 Sep 2006 Sang-Ho Yun

Simple and useful. Thank you!

Updates
29 Jun 2006

Update description. Minor fixes in code.

Contact us