Utilisateur:Ikonact/Cartographie/wmtp plotpath

function wmtp_plotpath(fid, handle, pictsize, varargin)
%#

%# The WMT tool is a collection of Octave/Matlab scripts able to generate geographic maps images.
%#
%# Copyright 2012 ikonact
%# http://commons.wikimedia.org/wiki/User:Ikonact
%#
%# This file is part of the WMT tool.
%#
%# WMT is free software: you can redistribute it and/or modify
%# it under the terms of the GNU General Public License as published by
%# the Free Software Foundation, either version 3 of the License, or
%# (at your option) any later version.
%#
%# WMT is distributed in the hope that it will be useful,
%# but WITHOUT ANY WARRANTY; without even the implied warranty of
%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%# GNU General Public License for more details.
%#
%# You should have received a copy of the GNU General Public License
%# along with WMT.  If not, see <http://www.gnu.org/licenses/>.

[x1, y1] = wmtp_reproject(gca, get(handle, 'XData'), get(handle, 'YData'));

%# turn column vector into row vector in order to use correctly sprintf
if size(x1, 1) < size(x1, 2) x1 = x1'; end
if size(y1, 1) < size(y1, 2) y1 = y1'; end

%# remove nan
indnonan = find (~isnan(x1) & ~isnan(y1));
x1 =x1(indnonan);
y1 =y1(indnonan);

if (~isnan(x1) & ~isnan(y1))

    temp_string = sprintf('M%0.2f %0.2f',x1(1)*pictsize(1), y1(1)*pictsize(2));
    temp_string1 = sprintf(' L%0.2f %0.2f',[x1(2:end)'*pictsize(1);y1(2:end)'*pictsize(2)]);

    if nargin >= 4
        fprintf(fid, '<path %s d="%s %s"/>\n',varargin{1}, temp_string, temp_string1);
    else
        fprintf(fid, '<path d="%s %s"/>\n',temp_string, temp_string1);
    end
end