%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$
% $Author$
% $Revision$
% $HeadURL$
% $Keywords: $
 
%% Load

   OPT.ldb               = ['holland-par.ldb'];
   OPT.ann               = ['holland-par-names.txt'];
   OPT.title             = 'Vector coastline of Netherlands.';
   OPT.epsg              = 28992;
   OPT.ID                = 'holland_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$ $HeadURL$',...
          '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);
