function [ ] = createXMLShape( d, filename , varargin)
% function [ ] = createXMLShape( d, filename , ...)
% The Function createXMLShape creates XML shape for SWIP5 maps
% It creates only one shape
%
% Input parameters:
% d - the structure with two fields of tables:
% Lat are latitudes of pollyline points od border of the shape .
% Long are longitudes of pollyline points od border of the shape.
% Number of pointd in Lat and Log must be the same.
% filename - the name of file whre the shape will be written
% The extension of the file name should be '.xml'
% Optional parameters
% 'Contour' the RGB color of the contour of the shape
% folowed by the table [r,g,b,w] where: r - red, g - green,
% b - blue, and w - width of the line. Default value is [0,0,0,1]
% (black)
% 'Face' the RGB color of the face of the shape
% folowed by the table [r,g,b,a] where a - translucency.
% Default value is [1,1,1,1] (white)
Pen = arparameters('Contour',[0,0,0,1],varargin{:});
Brush = arparameters('Face',[1,1,1,1],varargin{:});
fileID = fopen(filename,'w');
fprintf(fileID,'<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>\r\n');
fprintf(fileID,'<!DOCTYPE boost_serialization>\r\n');
fprintf(fileID,'<boost_serialization signature="serialization::archive" version="12">\r\n');
fprintf(fileID,'<Shapes class_id="0" tracking_level="0" version="0">\r\n');
fprintf(fileID,'\t<count>1</count>\r\n');
fprintf(fileID,'\t<item_version>0</item_version>\r\n');
fprintf(fileID,'\t<item class_id="1" tracking_level="0" version="0">\r\n');
fprintf(fileID,'\t\t<penRed>%d</penRed>\r\n', Pen(1)*128);
fprintf(fileID,'\t\t<penGreen>%d</penGreen>\r\n', Pen(2)*128);
fprintf(fileID,'\t\t<penBlue>%d</penBlue>\r\n', Pen(3)*128);
fprintf(fileID,'\t\t<penWidth>%d</penWidth>\r\n', Pen(4));
fprintf(fileID,'\t\t<brushRed>%d</brushRed>\r\n',Brush(1)*128);
fprintf(fileID,'\t\t<brushGreen>%d</brushGreen>\r\n',Brush(2)*128);
fprintf(fileID,'\t\t<brushBlue>%d</brushBlue>\r\n',Brush(3)*128);
fprintf(fileID,'\t\t<fill>%f</fill>\r\n',Brush(4));
fprintf(fileID,'\t\t<coords class_id="2" tracking_level="0" version="0">\r\n');
fprintf(fileID,'\t\t\t<count>%d</count>\r\n',numel(d.Lat));
fprintf(fileID,'\t\t\t<item_version>0</item_version>\r\n');
for i = 1:numel(d.Lat)
if i == 1
fprintf(fileID,'\t\t\t<item class_id="3" tracking_level="0" version="0">\r\n');
else
fprintf(fileID,'\t\t\t<item>\r\n');
end
fprintf(fileID,'\t\t\t\t<latitude>%f</latitude>\r\n\t\t\t\t<longitude>%f</longitude>\r\n',d.Lat(i),d.Long(i));
fprintf(fileID,'\t\t\t</item>\r\n');
end
fprintf(fileID,'\t\t</coords>\r\n');
fprintf(fileID,'\t</item>\r\n');
fprintf(fileID,'</Shapes>\r\n');
fprintf(fileID,'</boost_serialization>\r\n');
fclose(fileID);
end