View License

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

» Watch video

Highlights from
wgs2utm (version 2)

4.8 | 5 ratings Rate this file 33 Downloads (last 30 days) File Size: 3.1 KB File ID: #14804 Version: 1.2

wgs2utm (version 2)



26 Apr 2007 (Updated )

Convert WGS84 coordinates (Latitude, Longitude) into UTM coordinates (northing, easting).

| Watch this File

File Information

function similar to Rafael Palacios's deg2utm.m but using formulas from "Map Projections - A Working Manual" by J.P. Snyder (1987) for better precision in Southern hemisphere.

This second version allows forcing UTM zone and hemisphere in input, but can still be used like the previous version in which the function finds the appropriate zone.

Lat=[48.866667; 34.05; -36.85 ];
Lon=[2.333056; -118.25; 174.783333];
% data zones:
[x1,y1,utmzone1,utmhemi1] = wgs2utm(Lat,Lon)
% forced zone:
[x2,y2,utmzone2,utmhemi2] = wgs2utm(Lat,Lon,60,'S')


Deg2utm inspired this file.

MATLAB release MATLAB 7.13 (R2011b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (14)
22 Oct 2015 Kurt

Kurt (view profile)

Works great, and gives better results in southern hemisphere than others on File Exchange. I guess the only thing I would have done differently would be the order of inputs - since the output is X then Y, I would have made the inputs Longitude then Latitude, but obviously not a big deal. Thanks for contributing

26 Sep 2014 Pavel

Pavel (view profile)

Sorry, really simple question. I need this code to work but i`m not very good in matlab.
Could you please explain how to put the inputs?
Sorry for the question

Comment only
30 Jul 2014 Gonzalo

Thank you very much. This function works perfectly for me. I'm working on geolocation of buses in London and the function has no problems and is helping me a lot in my research.

27 Feb 2014 Esteban

18 Feb 2014 jack

jack (view profile)

really thanks.

Comment only
30 Jun 2012 M Sohrabinia

M Sohrabinia (view profile)

Hey again, had been working on this issue since I wrote the comment, it appears Matlab's built-in functions need more tweaking (I checked this with ArcGIS too), your function works accuratesly with sub-meter precision. Please ignore my previous comment.

Comment only
30 Jun 2012 M Sohrabinia

M Sohrabinia (view profile)

Hi and thanks for your code,
I just did a quick comparison between your code and Matlab's built-in functions to calculate UTM values based on LatLon, here are the results:
mstruct = defaultm('utm');,172.5);
mstruct = defaultm(mstruct);
[x,y] = mfwdtran(mstruct,-43.5,172.5)
Result: 621272.828768645 5182478.29916538
Your code:
[x,y,zone1,utmhemi1] = wgs2utm(-43.5, 172.5)
Result: 621267.241003134 5182565.80639284
(there is almost 100 meter diff in y).
By the way, you have used utmzone as variable name in the output which conflicts with Matlab's built-in function name, it took me a while why I am getting weird errors after trying your function (output from your function stops utmzone function from working). Good luck

Comment only
08 Feb 2012 S K

S K (view profile)

01 Feb 2012 Alexandre Schimel

FYI. I just submitted a new version of the wgs2utm allowing to force UTM zone and hemisphere in input, as per requests.

You can still use it like the old one though, ie with no forcing and let the function choose the appropriate zone. The new function should be compatible with any code using the old version. Check function's help for more info on use.

Comment only
03 Jun 2011 Andrew McGillis

Thanks for the tip - I will use that when needed.

Comment only
05 Jun 2009 Alexandre Schimel

Comment about forcing output UTM zone.

Two parameters change for each UTM zone: the reference longitude and the false northing. In the current code, these values are caculated from the input data at lines 63 and 68:
Lon0 = floor(Lon./6).*6+3; % reference longitude in degrees
FN = (Lat < 0).*10000000; % false northing

In order to force the output UTM zone, one can force these two parameters to their desired value. If you know your reference longitude, just replace Lon0 by this value. If you know the zone number ii, replace Lon0 by 6*ii-183

Set FN to 0 for northern hemisphere, or 10000000 for southern hemisphere.

Comment only
07 Sep 2008 Alexandre Schimel

Thanks Andrew, I understand your concern. I have been working on data from an area in between two zones and my code didn't handle this issue.

I completely modified my original code to be able to force the UTM zone but also:
- to allow converting to local Transverse Mercator projections (NZ projections are preset)
- to compute grid convergence (difference between true north and grid north, absolutely needed information when dealing with orientation data)

I suggest you move to local projections if possible. If your data span on several UTM zones, your deformations will be huge.

I can provide you with the new function if you mail me directly. I am not sure of putting it online here for the moment. Same comment for everyone else who is interested.

Comment only
24 Jul 2008 Andrew McGillis

Very good, thank you. Any chance to force output into a single zone? I work with models that cannot handle multiple UTM zones, yet sometimes my datasets span multiple zones, so it would be nice to re-project everything to a specified zone (recognizing that this will reduce the accuracy for those data points outside of the correct zone). Very nice regardless. Many thanks!

08 May 2007 Alexandre Schimel

Users, can you please write reviews to assess the transformation quality in your areas of interest ? thanks

Comment only
31 Jan 2012 1.1

Following requests, this second version allows forcing utm input

01 Feb 2012 1.2

completed descriptions and examples

Contact us