function wmt_addshape(data, varargin)
%#WMT_ADDSHAPE plot a shape layer on a map.
%#
%# WMT_ADDSHAPE(data, 'name', layername);
%# data - data to plot. Data is a matrix with 3 columns - index of the line, lat, lon
%# values for each point. Data may be also a matrix with 2 columns -
%# lat, lon for each point. In this case the lines should be separated with
%# nan
%# layername - name of the layer to plot
%# 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/>.
global wmt_param;
for i = 2:2:nargin
switch(varargin{i-1})
case 'name'
name = varargin{i};
otherwise
disp(varargin{i});
end
end
fprintf(wmt_param.fid, '<g id="layer-%s" inkscape:groupmode="layer" inkscape:label="layer-%s" clip-path="url(#IDmain)">\n', name, name);
if iscell(data) == 1
for i = 1:length(data)
if isfield(wmt_param, 'projection') && ~strcmp(wmt_param.projection,'')
h = m_plot(data{i}(:,1), data{i}(:,2)); hold on;
xlim(wmt_param.relxlim);
ylim(wmt_param.relylim);
else
h = plot(data{i}(:,1), data{i}(:,2)); hold on;
ylim([wmt_param.limits(1) wmt_param.limits(2)]);
xlim([wmt_param.limits(3) wmt_param.limits(4)]);
end
wmtp_plotpath(wmt_param.fid, h, wmt_param.pictsize, ['class="' name '"']);
end
else
if size(data, 2) == 2
ind = find(isnan(data(:,1)));
ll = length(ind)-1;
for i = 1:ll
if isfield(wmt_param, 'projection') && ~strcmp(wmt_param.projection,'')
h = m_plot(data((ind(i)+1):(ind(i+1)-1), 1), data((ind(i)+1):(ind(i+1)-1), 2)); hold on;
xlim(wmt_param.relxlim);
ylim(wmt_param.relylim);
else
h = plot(data((ind(i)+1):(ind(i+1)-1), 1), data((ind(i)+1):(ind(i+1)-1), 2)); hold on;
ylim([wmt_param.limits(1) wmt_param.limits(2)]);
xlim([wmt_param.limits(3) wmt_param.limits(4)]);
end
wmtp_plotpath(wmt_param.fid, h, wmt_param.pictsize, ['class="' name '"']);
end
else if size(data, 2) >= 3
id = unique(data(:, 1));
ll = length(id);
for i = 1:ll
ind = find(data(:,1) == id(i));
if isfield(wmt_param, 'projection') && ~strcmp(wmt_param.projection,'')
h = m_plot(data(ind, 2), data(ind, 3)); hold on;
xlim(wmt_param.relxlim);
ylim(wmt_param.relylim);
else
h = plot(data(ind, 2), data(ind, 3)); hold on;
ylim([wmt_param.limits(1) wmt_param.limits(2)]);
xlim([wmt_param.limits(3) wmt_param.limits(4)]);
end
wmtp_plotpath(wmt_param.fid, h, wmt_param.pictsize, ['class="' name '" id="' name int2str(i) '"']);
end
end
end
end
fprintf(wmt_param.fid, '</g>\n');