function output = ge_polys(X,Y,varargin)
% Reference page in help browser:
%
% This routine is based on ge_poly in OpenearthTools
%
% link to html documentation
% show license statement
%
AuthorizedOptions = authoptions( mfilename );
Y=Y(:);
X=X(:);
altitude = 1.0;
altitudeMode = 'clampToGround';
description = '';
extrude = 0;
autoClose = true;
id = 'poly';
idTag = 'id';
lineColor = 'ffffffff';
lineWidth = 5.0;
msgToScreen = false;
name = 'ge_poly';
polyColor = 'ffffffff';
snippet = ' ';
tessellate = 0;
timeStamp = ' ';
timeSpanStart = ' ';
timeSpanStop = ' ';
visibility = 1;
innerBoundsStr = '';
region = ' ';
parsepairs %script that parses Parameter/Value pairs.
if msgToScreen
disp(['Running :',mfilename,'...'])
end
if ( isempty( Y ) || isempty(X) )
error('empty coordinates passed to ge_poly(...).');
elseif length(Y) ~= length(X)
error('Length of Y is different to length of X');
end
if ~(isequal(altitudeMode,'clampToGround')||...
isequal(altitudeMode,'relativeToGround')||...
isequal(altitudeMode,'absolute'))
error(['Variable ',39,'altitudeMode',39, ' should be one of ' ,39,...
'clampToGround',39,', ',10,39,'relativeToGround',39,...
', or ',39,'absolute',39,'.' ])
end
if region == ' '
region_chars = '';
else
region_chars = [ region, 10 ];
end
cdata = ['
Rijkswaterstaat coastline data.',10,...
'
Deltares open earth repository.
',10,...
'Provided by:',10,...
'
' ]]> '];
id_chars = [ idTag '="' id '"' ];
poly_id_chars = [ idTag '="poly_' id '"' ];
name_chars = [ '',10,name,10,'',10 ];
% description_chars = [ '',10,'',10,'',10 ];
description_chars = [ '',10,cdata,10,'',10 ];
visibility_chars = [ '',10,int2str(visibility),10,'',10 ];
lineColor_chars = [ '',10, lineColor ,10,'',10 ];
a=hex2str(randi(255));
b=hex2str(randi(255));
c=hex2str(randi(255));
transparency = lower(dec2hex(127));
polyColor_chars = [ '',10, sprintf('%2s%2s%2s%2s',transparency,a, b, c),10,'',10 ];
lineWidth_chars= [ '',10, num2str(lineWidth, '%.2f'),10, '',10 ];
altitudeMode_chars = [ '',10, altitudeMode ,10,'',10 ];
if snippet == ' '
snippet_chars = '';
else
snippet_chars = [ '' snippet '',10 ];
end
extrude_chars = [ '' int2str(extrude) '',10 ];
tessellate_chars = [ '' int2str(tessellate) '',10 ];
if timeStamp == ' '
timeStamp_chars = '';
else
timeStamp_chars = [ '' timeStamp '\n' ];
end
if timeSpanStart == ' '
timeSpan_chars = '';
else
if timeSpanStop == ' '
timeSpan_chars = [ '',timeSpanStart,...
'',10 ];
else
timeSpan_chars = [ '',timeSpanStart,...
'' timeSpanStop '',10 ];
end
end
header = ['',10,...
name_chars,...
timeStamp_chars,...
timeSpan_chars,...
visibility_chars,...
snippet_chars,...
description_chars,...
region_chars, ...
'',10,...
'',10,...
extrude_chars,...
altitudeMode_chars,...
'',10,...
extrude_chars,...
'',10,...
extrude_chars,...
tessellate_chars,...
altitudeMode_chars,...
'',10];
footer = ['',10,...
'',10,...
'',10,...
innerBoundsStr,...
'',10,...
'',10];
X=[NaN;X;NaN];
Y=[NaN;Y;NaN];
nanIX = isnan(X.*Y);
polyStartIx = 1+find(nanIX(1:end-1)&~nanIX(2:end));
polyEndIx = find(~nanIX(1:end-1)&nanIX(2:end));
%nPolygons = length(polyStartIx);
output = '';
for x = 1:length(polyStartIx)
%generate Coords
coordinates = [];
if (polyEndIx(x)-polyStartIx(x))>=2
for ii = polyStartIx(x):polyEndIx(x)
coordinates = [ coordinates, ...
sprintf('%.16g,%.16g,%.16g ', X(ii), Y(ii), altitude),10];
end %for
%close unclosed polygons if necessary
if autoClose&&...
(X(polyEndIx(x))~=X(polyStartIx(x))||Y(polyEndIx(x))~=Y(polyStartIx(x)))
if msgToScreen
disp('Closing unclosed polygon...')
end
coordinates = [ coordinates, ...
sprintf('%.16g,%.16g,%.16g ',...
X(polyStartIx(x)), Y(polyStartIx(x)), altitude),10];
if msgToScreen
disp('Closing unclosed polygon...Done')
end
end % if
output = [ output, header, coordinates, footer];
end %if
end
if msgToScreen
disp(['Running ',mfilename,'...Done'])
end