Code covered by the BSD License  

Highlights from
Geodetic Toolbox

4.7

4.7 | 10 ratings Rate this file 173 Downloads (last 30 days) File Size: 39.38 KB File ID: #15285

Geodetic Toolbox

by Mike Craymer

 

13 Jun 2007 (Updated 31 Mar 2011)

Toolbox for angle, coordinate and date conversions and transformations. Version 2.95.

| Watch this File

File Information
Description

A collection of geodetic functions that solve a variety of problems in geodesy. Supports a wide range of common and user-defined reference ellipsoids. Most functions are vectorized. Functions include:

Angle Conversions
  deg2rad - Degrees to radians
  dms2deg - Degrees,minutes,seconds to degrees
  dms2rad - Degrees,minutes,seconds to radians
  rad2deg - Radians to degrees
  rad2dms - Radians to degrees,minutes,seconds
  rad2sec - Radians to seconds
  sec2rad - Seconds to radians
 
Coordinate Conversions
  ell2utm - Ellipsoidal (lat,long) to UTM (N,E) coordinates
  ell2xyz - Ellipsoidal (lat,long) to Cartesian (x,y,z) coodinates
  sph2xyz - Shperical (az,va,dist) to Cartesian (x,y,z) coordinates
  xyz2sph - Cartesian (x,y,z) to spherical (az,va,dist) coordinates
  xyz2ell - Cartesian (x,y,z) to ellipsoidal (lat,long,ht) coordinates
  xyz2ell2 - xyz2ell with Bowring height formula
  xyz2ell3 - xyz2ell using complete Bowring version
 
Coordinate Transformations
  refell - Reference ellipsoid definition
  ellradii - Various radii of curvature
  cct2clg - Conventional terrestrial to local geodetic cov. matrix
  clg2cct - Local geodetic to conventional terrestrial cov. matrix
  ct2lg - Conventional terrestrial (ECEF) to local geodetic (NEU)
  dg2lg - Differences in Geodetic (lat,lon) to local geodetic (NEU)
  lg2ct - Local geodetic (NEU) to conventional terrestrial (ECEF)
  lg2dg - Local geodetic (NEU) to differences in geodetic (lat,lon)
  direct - Direct geodetic problem (X1,Y1,Z1 + Az,VA,Dist to X2,Y2,Z2)
  inverse - Inverse geodetic problem (X1,Y1,Z1 + X2,Y2,Z2 to Az,VA,Dist)
  simil - Similarity transformation (translation,rotation,scale change)
 
Date Conversions
  cal2jd - Calendar date to Julian date
  dates - Converts between different date formats
  doy2jd - Year and day of year to Julian date
  gps2jd - GPS week & seconds of week to Julian date
  jd2cal - Julian date to calenar date
  jd2dow - Julian date to day of week
  jd2doy - Julian date to year & day of year
  jd2gps - Julian date to GPS week & seconds of week
  jd2mjd - Julian date to Modified Julian date
  jd2yr - Julian date to year & decimal year
  mjd2jd - Modified Julian date to Julian date
  yr2jd - Year & decimal year to Julian date
 
Error Ellipses
  errell2 - Computes error ellipse semi-axes and azimuth
  errell3 - Computes error ellipsoid semi-axes, azimuths, inclinations
  plterrel - Plots error ellipse for covariance matrix
 
Miscellaneous
  findfixed - Finds fixed station based on 3D covariance matrix
  pltnet - Plots network of points with labels
 
Example Scripts
  DirInv - Simple partial GUI script for direct and inverse problems
  DirProb - Example of direct problem
  Dist3D - Example to compute incremental 3D distances between points.
  InvProb - Example of inverse problem
  PltNetEl - Example plot of network error ellipses
  ToUTM - Example of conversion from latitude,longitude to UTM

The most recent version can be found at http://www.craymer.com/software/matlab/geodetic/.

Acknowledgements
This submission has inspired the following:
Equinoxes and Solstices
MATLAB release MATLAB 7.9 (2009b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (25)
15 Jun 2007 John D'Errico

This seems pretty good from what I checked. There are many conversions in here.

A couple of minor points. I notice that there is no error checking. For example, in ellradii one must provide an axis length and eccentricity (squared). But there are no checks on the proper number of parameters or even on the sign of the eccentricity.

In dms2deg, I noticed one interesting feature. Converting from 32 degrees, 12 minutes, -3 seconds, results in a degree prediction of:

dms2deg([32 12 -3])
ans =
      -32.201

Overall, its still pretty good.

28 Jun 2007 Nice Work

Nice work

05 Oct 2007 Ali Ebrahimi  
25 Feb 2008 Jagkrich A.warangkul

Thanks

01 Mar 2008 Ray Borough

Very Useful

09 Jul 2008 Gene Newton

Thank you.

11 Sep 2008 jaime torres

gracias

27 Jan 2009 Christopher

under matlab which file do i put this in so that it is being used?

18 Feb 2009 Sebastian Hölz

There is a potential bug in function ell2UTM, which may lead to wrong results in the calculated northing, if the funciton is called with a vector containing coordinates from both southern and northern hemisphere. Change lines 23-27, which read ...

if lat>=0
  No=0;
else
  No=10000000;
end

to ...

No(size(lat))=0; % False northing (north)
No(lat<0) = 1e7; % False northing (south)

Sebastian

24 Feb 2009 Mike Craymer

I corrected the bug for vector and array input to function ell2utm per Sebastian Holz's comments and posted a new version 2.91. Unfortunately, the fix only worked for row vectors. I've corrected it again in version 2.92 and tested it this time to make sure it works. Sorry for any problems this may have caused. In addition to error checking, I'll consider adding array input to all functions in the next major release (this Summer I hope).

29 Jul 2009 Sepideh

Thanks for that, very useful

16 Oct 2009 Jonathan

Hello,

Thank you for such a useful toolbox! I have a question, however, regarding transforming lat,lon on the WGS84 ellipsoid to local North East Up. If I use the same lat,lon coordinate as both my point to convert and my origin, why would I get a -21.5 km local North value? Shouldn't North and East both be zero?

Thanks again,
Jon

<SNIP>

>> [a,b,e2,finv] = refell('WGS84'); %get ellipsoid params
rlat = deg2rad(40); rlon = deg2rad(-108); %lat,lon
[Xec Yec Zec] = ell2xyz(rlat,rlon,0,a,e2) %convert to ECEF xyz
[N E Up] = ct2lg(Xec,Yec,Zec,rlat,rlon) %convert to local NEU

Xec =
  -1.5119e+06
Yec =
  -4.6532e+06
Zec =
   4.0780e+06

N =
  -2.1054e+04
E =
     0
Up =
   6.3693e+06

</SNIP>

06 Feb 2010 Mike Craymer

Dear Jonathon,

I just saw your question about transforming lat,lon to N,E,U. The ct2lg function in your last step requires as input the X,Y,Z coordinate *differences* between the two points. In your example, you entered the X,Y,Z coordinates for just one point. ct2lg would have interpreted this as very large X,Y,Z coordinate differences. The correct conversion for your example is given below (you need to enter the X,Y,Z differences in ct2lg as Xec-Xec, Yec-Yec, Zec-Zec).

Thanks for your comments!
-Mike

>> [a,b,e2,finv] = refell('WGS84'); %get ellipsoid params
rlat = deg2rad(40); rlon = deg2rad(-108); %lat,lon
[Xec Yec Zec] = ell2xyz(rlat,rlon,0,a,e2) %convert to ECEF xyz
[N E Up] = ct2lg(Xec-Xec,Yec-Yec,Zec-Zec,rlat,rlon) %convert to local NEU

Xec =

  -1.5119e+06

Yec =

  -4.6532e+06

Zec =

   4.0780e+06

N =

     0

E =

     0

Up =

     0

27 May 2010 Bryce

dates.m does a 'clear all' at the beginning of its loop. Not cool!

It would be much better to clear the actual names of variables that you use in the script. Resetting people's workspace variables is not nice.

Looks like a good toolbox, though. Thanks!

30 Sep 2010 Ram Acharya

It is a good tool. However, I couldn't make its use while I wanted to convert lat longs to UTM, for lats [26.4546 -- 30.4485 degrees North ] and longs [80.074 -- 88.23319 degrees East]. The UTM zone is 45R . However your tool splits it into 44R and 45R. Could you review your code for that particular region. Thanks.

07 Jan 2011 Ist

That's seems to be very useful package. Thank You!

21 Feb 2011 Mike Craymer

Dear Bryce,
You are right! The "clear all" in dates.m is not cool. I've replaced it with clearing the specific variables used in the script. A new version 2.95 of the toolbox will be posted shortly fixing this in dates.m as well as other affected example scripts. In the meantime, users should remove any "clear" or "clear all" when using the examples. Thank you for bringing this to my attention!
-Mike

21 Feb 2011 Mike Craymer

Dear Ram,
By default, the ell2utm function uses the standard UTM zone definition where the earth is divided into 60 zones each 6 deg of longitude in width. Zone 1 is bounded by longtiudes 180 deg E and 186 deg E.

<http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system>;

By this definition, Zone 44 is bounded by longitudes 78 deg E and 84 deg E, while Zone 45 is bounded by 84 deg E and 90 deg E. That is, Zone 44 starts at 180+(44-1)*6-360=78. The boundary between Zones 44 and 45 therefore bisects what you call Zone 45R. You can verify this with the on-line version of GeoConvert at

<http://geographiclib.sourceforge.net/cgi-bin/GeoConvert>;

In any case, the ell2utm function allows you to specify the central meridian for any non-standard zone definitions. See help ell2utm for more information.

-Mike

21 Feb 2011 Mike Craymer

Sorry the URL's in my previous comment did not format correctly. They should have been specified as:

http://en.wikipedia.org/wiki/Universal_Transverse_Mercator_coordinate_system

http://geographiclib.sourceforge.net/cgi-bin/GeoConvert

13 Mar 2011 Mike Craymer

A new version 2.95 of the Geodetic Toolbox is now available. Unfortunately, I am unable upload it to the MATLAB Central File Exchange (keep getting an error). Until the Mathworks resolves the problem, you can find the new version at <http://www.craymer.com/software/matlab/geodetic/>;.

Updates include:

- Added new jd2mjd & mjd2jd functions for modified Julian date conversions.
- Modified ct2lg & lg2ct functions to optionally use different lat,lon for each point.
- Corrected use of ell2utm function in ToUTM example script.
- Removed "clear all" in example scripts to avoid clearing user's workspace.
- Modified functions to use GRS80 reference ellipsoid by default.

See Content.m for the full list of changes.

13 Mar 2011 Mike Craymer

Sorry again! I keep forgetting that the MATLAB File Exchange doesn't like the use of the standard angle brackets enclosing URLs. Here is the clickable URL sans brackets:

http://www.craymer.com/software/matlab/geodetic/

19 Apr 2011 Vihang bhatt

It is really a good toolbox. Thank you for making my life little easy. One suggestion for the author on Julian dates. In the function jd2cal, jd has to be positive. jd can be negitive (if they exist), following modification needed to the code

if(a==0)
   dy = c - e - fix(30.6001*f) + rem((jd+0.5),max(a,1));
else
 dy = c - e - fix(30.6001*f) + rem((jd+0.5),a);
end

In above case you are able to get 1st gragorian date for zeroth julian day. otherwise greogrian calander start from 2nd jan.

Dr. Vihang Bhatt

23 Jul 2011 joo tan

mike..
if i wnat to set the central meridian, like zon 50, where can i get the central meridian value??

22 Sep 2011 Shien Kwun Leong

Very useful! Thank you very much.

25 Sep 2011 Mike Craymer

Re: 23 Jul 2011 post by muhammad faiz pa'suya

Dear Muhammad: The ell2utm function will automatically determine and output the standard UTM zone in which your input coordinates fall. To also have it output the central meridian for the zone(s), change the first line of the ell2utm.m function from

     function [N,E,Zone]=ell2utm(lat,lon,a,e2,lcm)
to
     function [N,E,Zone,lcm]=ell2utm(lat,lon,a,e2,lcm)

This will be implemented in the next version of the Toolbox. To understand how the zones are determined, see the Wikipedia entry for UTM.

Please login to add a comment or rating.
Updates
18 Feb 2009

Corrected ell2utm function for mixed north and south latitudes. Thanks to Sebastian Holz for pointing out the error and providing a fix.

24 Feb 2009

Corrected correction to ell2utm function in v2.91 (and tested it this time!).

31 May 2009

Added Matlab File Exchange BSD licensing. No changes to code since v2.92.

31 May 2009

Added Matlab File Exchange BSD licensing. No changes to code since v2.92.

11 Mar 2011

Added jd2mjd & mjd2jd for modified Julian date conversions. Modified ct2lg & lg2ct for different lat,lon for each point. Corrected ToUTM. Removed clear all in example scripts. Modified functions to use GRS80 reference ellipsoid by default.

Tag Activity for this File
Tag Applied By Date/Time
geodesy Mike Craymer 22 Oct 2008 09:15:20
geodetic Mike Craymer 22 Oct 2008 09:15:20
angle Mike Craymer 22 Oct 2008 09:15:20
date Mike Craymer 22 Oct 2008 09:15:20
julian Mike Craymer 22 Oct 2008 09:15:20
gps week Mike Craymer 22 Oct 2008 09:15:20
coordinate Mike Craymer 22 Oct 2008 09:15:20
coordinates Mike Craymer 18 Feb 2009 12:57:18
aerospace Mike Craymer 18 Feb 2009 12:57:18
mathematics Mike Craymer 18 Feb 2009 12:57:18
statistics Mike Craymer 18 Feb 2009 12:57:18
optimization Mike Craymer 18 Feb 2009 12:57:18
measurement Mike Craymer 18 Feb 2009 12:57:18
gps Mike Craymer 01 Jun 2009 09:57:52
earth science Mike Craymer 01 Jun 2009 09:57:52
geomatics Mike Craymer 01 Jun 2009 09:57:52
statistics surveying Mike Craymer 01 Jun 2009 09:57:52
angle Eric 07 Oct 2009 11:04:56
coordinate Rick Magnuson 27 May 2010 08:47:28
gps kuoping 29 Jun 2010 07:21:00
gps jhh 27 Sep 2010 11:33:49

Contact us at files@mathworks.com