File Exchange

image thumbnail

GPX file reader

version 1.0 (2.73 KB) by

%LOADGPX Loads route points from a GPS interchange file

27 Downloads

Updated

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:
% http://www.gmap-pedometer.com/
% http://www.elsewhere.org/journal/gmaptogpx/
%
% See also xmlread

Comments and Ratings (9)

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

lat_mean=mean(route(:,COL_LAT));

Useful contribution, but mistakenly computed for meter units. should be like that:
KM_PER_ARCMINUTE = 1.852;
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'
MILES_PER_ARCMINUTE = 1.15;
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'
KM_PER_ARCMINUTE = 1.852;
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

Bernd (view profile)

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

Evan

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');
into
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
with

COL_TIMEVEC = 7:12;

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?

Thanks!

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