%LDB*  rewrites Deltares landboundary file with segment names file (line segments) to nc file
%
%See also: SNCTOOLS, LANDBOUNDARY, POLY_SPLIT, POLY_JOIN, POLY_FUN

% $Id: ldb2nc.m 
% $Date: 2011-04-28 12:18:10 +0200 (do, 28 apr 2011) $
% $Author: boer_g $
% $Revision: 4984 $
% $HeadURL: https://repos.deltares.nl/repos/OpenEarthRawData/trunk/deltares/landboundaries/scripts/ldb2nc.m $
% $Keywords: $
 
%% Load

   OPT.ldb               = ['zeeland_2004.ldb'];
  %OPT.ann               = ['euro-par-names.txt'];
   OPT.title             = 'Vector coastline of Zeeland.';
   OPT.epsg              = 28992;
   OPT.ID                = 'zeeland_4326';

  [P.x,P.y]              = landboundary('read',OPT.ldb);% ,999.999
  [P.lon,P.lat]          = convertCoordinates(P.x,P.y,'CS1.code',OPT.epsg,'CS2.code',4326);
  %P.names               = textread(OPT.ann,'%s','delimiter','','commentstyle','matlab');
  %P.names               = char(P.names);
   
%% NC: will display as dots, not as lines

   nc_cf_line([OPT.ID,'.nc'],P.lon,P.lat,...
         'title',OPT.title,...
       'version','$Id: waddensea2005.m 5645 2013-08-12 08:58:15Z boer_g $ $HeadURL: https://svn.oss.deltares.nl/repos/openearthrawdata/trunk/deltares/landboundaries/waddensea2005/waddensea2005.m $',...
          'dump',[OPT.ID,'.cdl'])

%% SHP

   PP.lon = poly_split(P.lon');
   PP.lat = poly_split(P.lat');
   for i=1:length(PP.lon)
       PP.LL{i} = [PP.lon{i}' PP.lat{i}'];
   end
   shape('write',[OPT.ID,'.shp'],'polyline',PP.LL); % polygon is closed, polylien is open
   
%% LDB

   landboundary('write',[OPT.ID,'.ldb'],P.lon,P.lat);   