File Exchange

image thumbnail

GPX file reader

version 1.0 (2.73 KB) by

%LOADGPX Loads route points from a GPS interchange file



View License

% ROUTE = LOADGPX(FILENAME) Loads route point information from a .GPX
% GPS interchange file. This utility is not a general-purpose
% implementation of GPX reading and is intended mostly for reading the
% files output by the "gmap pedometer" tool.
% ROUTE is a Nx6 array where each row is a route point.
% Columns 1-3 are the X, Y, and Z coordinates.
% Columns 4-5 are latitude and longitude
% Column 6 is cumulative route length.
% Note that the mapping of latitude/longitude assumes an approximate spherical
% transformation to rectangular coordinates.
% Additional property/value arguments:
% LOADGPX(...,'ElevationUnits','meters',...) uses meters for elevation
% LOADGPX(...,'Viz',true,...) displays the route and elevation map
% For more information on the gmap pedometer and GPX output:
% See also xmlread

Comments and Ratings (9)

sorry, I forgot this line, to put before the switch line:


Useful contribution, but mistakenly computed for meter units. should be like that:
route(:,COL_X:COL_Y) = KM_PER_ARCMINUTE*1000*60*route(:,COL_X:COL_Y);

and forget to take into account latitude. must add this line:
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi);

all in all should be like that:

case 'feet'
route(:,COL_X:COL_Y) = MILES_PER_ARCMINUTE*5280*60*route(:,COL_X:COL_Y);
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi); %correction de latitude
distMult = 1/5280; %5280 feets = 1 Mile
case 'meters'
route(:,COL_X:COL_Y) = KM_PER_ARCMINUTE*1000*60*route(:,COL_X:COL_Y);
route(:,COL_X) = route(:,COL_X)*cos(lat_mean/180*pi);
distMult = 1/1000;


Bernd (view profile)

very helpful...but I also had to impement the changes from Georg. please think about updating the file


Evan (view profile)

Can't figure out the units of the X, Y, and Z columns. I did the same as George to get gpx files with trkpt instead of rtept. Also converted time to Matlab serial time using datenum.

Georg Ogris

To read my Garmin data change

ptList = d.getElementsByTagName('rtept');
ptList = d.getElementsByTagName('trkpt');

and add:

tim = pt.getElementsByTagName('time') ;
timChar = char(tim.item(0).getTextContent) ;
route(i,COL_TIMEVEC) = datevec([timChar(1:10) ' ' timChar(12:19)]) ;

before the end of the main for-loop


Georg Ogris

David Longin

Andrew Bliss

Andrew Bliss (view profile)

This is a useful, good file. A few adjustments could improve it.

To allow the output, 1st line should be:
function route=loadgpx(fileName,varargin)

Calculate range before the viz section, so it can be output too if the viz option is off.

Something about the units is off but I didn't take the time to figure out what is wrong with it... gmaptogpx is outputting elevations in meters, right?


Andrew Bliss

Andrew Bliss (view profile)

MATLAB Release
MATLAB 7.7 (R2008b)

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

» Watch video