Changeset 6461


Ignore:
Timestamp:
11/01/10 15:54:12 (14 years ago)
Author:
jschierm
Message:

Implementation of kml class hierarchy in kml plotting drivers.

Location:
issm/trunk/src/m/kml
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/kml/kml_mesh_elem.m

    r6417 r6461  
    22%  create kml polygons for the element mesh.
    33%
    4 %  []=kml_mesh_elem(fid,md,params)
     4%  [kfold]=kml_mesh_elem(md,params)
    55%
    66%  where the required input is:
    7 %    fid           (numeric, file ID of .kml file)
    87%    md            (model, model class object)
    98%
     
    1817%    cmap          (char or numeric, colormap definition)
    1918%
    20 function []=kml_mesh_elem(varargin)
     19%  and the required output is:
     20%    kfold         (kml_folder, folder of polygon placemarks)
     21%
     22function [kfold]=kml_mesh_elem(varargin)
    2123
    2224if ~nargin
     
    2931iarg=1;
    3032if (nargin >= 1)
    31     fid=varargin{1};
    32 end
    33 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    34     error('File ID ''%d'' must be open.',fid);
    35 end
    36 
    37 iarg=iarg+1;
    38 if (nargin >= 2)
    39     md=varargin{2};
     33    md=varargin{1};
    4034end
    4135if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    106100%%  write folder for mesh
    107101
    108 fprintf(fid,'    <Folder>\n');
     102kfold=kml_folder();
    109103if exist('cdata','var') && ~isempty(cdata)
    110     fprintf(fid,'      <name>Data: %s</name>\n',cdata);
     104    kfold.name      =sprintf('Data: %s',cdata);
    111105else
    112     fprintf(fid,'      <name>Mesh</name>\n');
     106    kfold.name      =sprintf('Mesh');
    113107end
    114 fprintf(fid,'      <visibility>1</visibility>\n');
    115 fprintf(fid,'      <description>Elements=%d, Grids=%d</description>\n',...
     108kfold.visibility=1;
     109kfold.descript  =sprintf('Elements=%d, Grids=%d',...
    116110    md.numberofelements,md.numberofgrids);
     111kfold.feature   ={repmat(kml_placemark(),1,size(md.elements,1))};
    117112
    118 %  write each element as a polygon
     113%  write each element as a polygon placemark
    119114
    120115disp(['Writing ' num2str(size(md.elements,1)) ' tria elements as KML polygons.']);
    121116for i=1:size(md.elements,1)
    122     fprintf(fid,'      <Placemark>\n');
    123     fprintf(fid,'        <name>Element %d</name>\n',i);
    124     fprintf(fid,'        <visibility>1</visibility>\n');
     117    kplace=kml_placemark();
     118    kplace.name      =sprintf('Element %d',i);
     119    kplace.visibility=1;
    125120    if exist('edata','var')
    126         fprintf(fid,'        <description>Element data: %g</description>\n',edata(i));
     121        kplace.descript  =sprintf('Element data: %g',edata(i));
    127122        imap = fix((edata(i)-cmin)/(cmax-cmin)*size(cmap,1))+1;
    128123        if     (imap >= 1) && (imap <= size(cmap,1))
    129             fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',imap);
     124            kplace.styleurl  =sprintf('#MatlabColor%d',imap);
    130125        elseif (edata(i) == cmax)
    131             fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',size(cmap,1));
     126            kplace.styleurl  =sprintf('#MatlabColor%d',size(cmap,1));
    132127        else
    133             fprintf(fid,'        <styleUrl>#BlackLineEmptyPoly</styleUrl>\n');
     128            kplace.styleurl  =sprintf('#BlackLineEmptyPoly');
    134129        end
    135130    else
    136         fprintf(fid,'        <styleUrl>#BlackLineRandomPoly</styleUrl>\n');
     131        kplace.styleurl  =sprintf('#BlackLineRandomPoly');
    137132    end
    138     fprintf(fid,'        <Polygon>\n');
    139     fprintf(fid,'          <extrude>1</extrude>\n');
    140     fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    141     fprintf(fid,'          <outerBoundaryIs>\n');
    142     fprintf(fid,'            <LinearRing>\n');
    143     fprintf(fid,'              <coordinates>\n');
     133
     134    kpoly=kml_polygon();
     135    kpoly.extrude   =1;
     136    kpoly.altmode   ='relativeToGround';
     137
     138    kring=kml_linearring();
     139    kring.coords    =zeros(size(md.elements,2)+1,3);
     140
    144141    for j=1:size(md.elements,2)
    145         [lat(j),long(j)]=mapxy(md.x(md.elements(i,j)),md.y(md.elements(i,j)),'s');
    146         fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(j),lat(j),alt);
     142        [lat,long]=mapxy(md.x(md.elements(i,j)),md.y(md.elements(i,j)),'s');
     143        kring.coords(j,:)=[long lat alt];
    147144    end
    148     fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(1),lat(1),alt);
     145    kring.coords(end,:)=kring.coords(1,:);
    149146
    150     fprintf(fid,'              </coordinates>\n');
    151     fprintf(fid,'            </LinearRing>\n');
    152     fprintf(fid,'          </outerBoundaryIs>\n');
    153     fprintf(fid,'        </Polygon>\n');
    154     fprintf(fid,'      </Placemark>\n');
     147    kpoly.outer=kring;
     148    kplace.geometry=kpoly;
     149    kfold.feature{1}(i)=kplace;
     150    clear kring kpoly kplace
    155151end
    156 fprintf(fid,'    </Folder>\n');
    157152
    158153end
  • issm/trunk/src/m/kml/kml_mesh_write.m

    r6417 r6461  
    114114fprintf(fid,'<?xml version="1.0" encoding="UTF-8"?>\n');
    115115fprintf(fid,'<kml xmlns="http://www.opengis.net/kml/2.2">\n');
    116 fprintf(fid,'  <Document>\n');
    117 fprintf(fid,'    <name>ISSM Mesh: %s</name>\n',md.name);
    118 fprintf(fid,'    <open>1</open>\n');
    119 fprintf(fid,'    <description>');
     116
     117kdoc=kml_document();
     118kdoc.name      =sprintf('ISSM Mesh: %s',md.name);
     119kdoc.open      =1;
    120120ifirst=true;
    121121for i=1:numel(md.notes)
    122122    if ~isempty(md.notes{i})
    123123        if ~ifirst
    124             fprintf(fid,'\n');
     124            kdoc.descript  =[kdoc.descript sprintf('\n')];
    125125        end
    126126        ifirst=false;
    127         fprintf(fid,'%s',md.notes{i});
    128     end
    129 end
    130 fprintf(fid,'</description>\n');
     127        kdoc.descript  =[kdoc.descript sprintf('%s',md.notes{i})];
     128    end
     129end
     130clear ifirst
     131kdoc.style     ={repmat(kml_style(),0,0)};
     132kdoc.feature   ={repmat(kml_folder(),0,0)};
    131133
    132134%  write style templates for defaults and for each color of the matlab
     
    142144end
    143145
    144 fprintf(fid,'    <Style id="BlackLineRandomPoly">\n');
    145 fprintf(fid,'      <LineStyle>\n');
    146 fprintf(fid,'        <color>ff000000</color>\n');
    147 fprintf(fid,'        <colorMode>normal</colorMode>\n');
    148 fprintf(fid,'        <width>%g</width>\n',lwidth);
    149 fprintf(fid,'      </LineStyle>\n');
    150 fprintf(fid,'      <PolyStyle>\n');
    151 fprintf(fid,'        <color>%02xffffff</color>\n',round(popac*255));
    152 fprintf(fid,'        <colorMode>random</colorMode>\n');
    153 fprintf(fid,'      </PolyStyle>\n');
    154 fprintf(fid,'    </Style>\n');
    155 fprintf(fid,'    <Style id="BlackLineEmptyPoly">\n');
    156 fprintf(fid,'      <LineStyle>\n');
    157 fprintf(fid,'        <color>ff000000</color>\n');
    158 fprintf(fid,'        <colorMode>normal</colorMode>\n');
    159 fprintf(fid,'        <width>%g</width>\n',lwidth);
    160 fprintf(fid,'      </LineStyle>\n');
    161 fprintf(fid,'      <PolyStyle>\n');
    162 fprintf(fid,'        <color>00ffffff</color>\n');
    163 fprintf(fid,'        <colorMode>random</colorMode>\n');
    164 fprintf(fid,'      </PolyStyle>\n');
    165 fprintf(fid,'    </Style>\n');
    166 fprintf(fid,'    <Style id="RedLineRedPoly">\n');
    167 fprintf(fid,'      <LineStyle>\n');
    168 fprintf(fid,'        <color>ff0000ff</color>\n');
    169 fprintf(fid,'        <colorMode>normal</colorMode>\n');
    170 fprintf(fid,'        <width>%g</width>\n',lwidth);
    171 fprintf(fid,'      </LineStyle>\n');
    172 fprintf(fid,'      <PolyStyle>\n');
    173 fprintf(fid,'        <color>%02x0000ff</color>\n',round(popac*255));
    174 fprintf(fid,'        <colorMode>random</colorMode>\n');
    175 fprintf(fid,'      </PolyStyle>\n');
    176 fprintf(fid,'    </Style>\n');
    177 if exist('edata','var')
     146klsty=kml_linestyle();
     147klsty.color     ='ff000000';
     148klsty.colormode ='normal';
     149klsty.width     =lwidth;
     150kpsty=kml_polystyle();
     151kpsty.color     =sprintf('%02xffffff',round(popac*255));
     152kpsty.colormode ='random';
     153kstyle=kml_style();
     154kstyle.id        =sprintf('BlackLineRandomPoly');
     155kstyle.line      =klsty;
     156kstyle.poly      =kpsty;
     157kdoc.style{1}(end+1)=kstyle;
     158clear kstyle kpoly kline
     159
     160klsty=kml_linestyle();
     161klsty.color     ='ff000000';
     162klsty.colormode ='normal';
     163klsty.width     =lwidth;
     164kpsty=kml_polystyle();
     165kpsty.color     =sprintf('00ffffff');
     166kpsty.colormode ='random';
     167kstyle=kml_style();
     168kstyle.id        =sprintf('BlackLineEmptyPoly');
     169kstyle.line      =klsty;
     170kstyle.poly      =kpsty;
     171kdoc.style{1}(end+1)=kstyle;
     172clear kstyle kpoly kline
     173
     174klsty=kml_linestyle();
     175klsty.color     ='ff0000ff';
     176klsty.colormode ='normal';
     177klsty.width     =lwidth;
     178kpsty=kml_polystyle();
     179kpsty.color     =sprintf('%02x0000ff',round(popac*255));
     180kpsty.colormode ='random';
     181kstyle=kml_style();
     182kstyle.id        =sprintf('RedLineRedPoly');
     183kstyle.line      =klsty;
     184kstyle.poly      =kpsty;
     185kdoc.style{1}(end+1)=kstyle;
     186clear kstyle kpoly kline
    178187
    179188%  colormap command operates on a figure, so create an invisible one
    180189%  (could also directly call colormaps, e.g. jet(64), but risky)
    181190
     191if exist('edata','var')
    182192    hfig=figure('Visible','off');
    183193    if exist('cmap','var')
     
    189199    disp(['Writing ' num2str(size(cmap,1)) ' Matlab colors as KML style templates.']);
    190200    for i=1:size(cmap,1)
    191         fprintf(fid,'    <Style id="MatlabColor%d">\n',i);
    192         fprintf(fid,'      <LineStyle>\n');
    193         fprintf(fid,'        <color>ff000000</color>\n');
    194         fprintf(fid,'        <colorMode>normal</colorMode>\n');
    195         fprintf(fid,'        <width>%g</width>\n',lwidth);
    196         fprintf(fid,'      </LineStyle>\n');
    197         fprintf(fid,'      <PolyStyle>\n');
    198         fprintf(fid,'        <color>%02x%02x%02x%02x</color>\n',round(popac*255),...
     201        klsty=kml_linestyle();
     202        klsty.color     ='ff000000';
     203        klsty.colormode ='normal';
     204        klsty.width     =lwidth;
     205        kpsty=kml_polystyle();
     206        kpsty.color     =sprintf('%02x%02x%02x%02x',round(popac*255),...
    199207            round(cmap(i,3)*255),round(cmap(i,2)*255),round(cmap(i,1)*255));
    200         fprintf(fid,'        <colorMode>normal</colorMode>\n');
    201         fprintf(fid,'      </PolyStyle>\n');
    202         fprintf(fid,'    </Style>\n');
     208        kpsty.colormode ='normal';
     209        kstyle=kml_style();
     210        kstyle.id        =sprintf('MatlabColor%d',i);
     211        kstyle.line      =klsty;
     212        kstyle.poly      =kpsty;
     213        kdoc.style{1}(end+1)=kstyle;
     214        clear kstyle kpoly kline
    203215    end
    204216end
     
    206218%  write folder for mesh
    207219
    208 kml_mesh_elem(fid,md,varargin{3:end});
     220kdoc.feature{1}(end+1)=kml_mesh_elem(md,varargin{3:end});
    209221
    210222%  write folder for partition segments
     
    212224if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    213225    md.npart
    214     kml_part_flagedges(fid,md,varargin{3:end});
     226    kdoc.feature{1}(end+1)=kml_part_flagedges(md,varargin{3:end});
    215227end
    216228
     
    219231if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    220232    md.npart
    221     kml_unsh_edges(fid,md,varargin{3:end});
     233    kdoc.feature{1}(end+1)=kml_unsh_edges(md,varargin{3:end});
    222234end
    223235
     
    226238if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    227239    md.npart
    228     kml_part_elems(fid,md,varargin{3:end});
     240    kdoc.feature{1}(end+1)=kml_part_elems(md,varargin{3:end});
    229241end
    230242
     
    233245if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    234246    md.npart
    235     kml_part_edges(fid,md,varargin{3:end});
     247    kdoc.feature{1}(end+1)=kml_part_edges(md,varargin{3:end});
    236248end
    237249
     
    240252if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    241253    md.npart
    242     kml_partitions(fid,md,varargin{3:end});
    243 end
     254    kdoc.feature{1}(end+1)=kml_partitions(md,varargin{3:end});
     255end
     256
     257%  write document
     258
     259display(sprintf('Writing kml file ''%s''.',filek2));
     260kml_write(kdoc,fid,'  ');
    244261
    245262%  write trailer data
    246263
    247 fprintf(fid,'  </Document>\n');
    248264fprintf(fid,'</kml>\n');
    249265
  • issm/trunk/src/m/kml/kml_part_edges.m

    r6417 r6461  
    22%  create kml linestrings for the partition edges.
    33%
    4 %  []=kml_part_edges(fid,md,params)
     4%  [kfold]=kml_part_edges(md,params)
    55%
    66%  where the required input is:
    7 %    fid           (char, file ID of .kml file)
    87%    md            (model, model class object)
    98%
     
    1918%    prtplt        (char, 'off'/'no' for partition segment plot)
    2019%
    21 function []=kml_part_edges(varargin)
     20%  and the required output is:
     21%    kfold         (kml_folder, folder of linestring placemarks)
     22%
     23function [kfold]=kml_part_edges(varargin)
    2224
    2325if ~nargin
     
    3032iarg=1;
    3133if (nargin >= 1)
    32     fid=varargin{1};
    33 end
    34 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    35     error('File ID ''%d'' must be open.',fid);
    36 end
    37 
    38 iarg=iarg+1;
    39 if (nargin >= 2)
    40     md=varargin{2};
     34    md=varargin{1};
    4135end
    4236if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    109103if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    110104    md.npart
    111     fprintf(fid,'    <Folder>\n');
    112     fprintf(fid,'      <name>Partition Edges</name>\n');
    113     fprintf(fid,'      <visibility>1</visibility>\n');
    114     fprintf(fid,'      <description>Partitions=%d, Nodes=%d</description>\n',...
     105    kfold=kml_folder();
     106    kfold.name      ='Partition Edges';
     107    kfold.visibility=1;
     108    kfold.descript  =sprintf('Partitions=%d, Nodes=%d',...
    115109        md.npart,md.numberofgrids);
    116 
    117 %  write each partition loop as linestrings
     110    kfold.feature   ={repmat(kml_placemark(),0,0)};
     111
     112%  write each partition loop as a linestring placemark
    118113
    119114    disp(['Writing ' num2str(md.npart) ' partitions as KML linestrings.']);
     
    160155
    161156        for i=1:length(iloop)-1
    162             fprintf(fid,'      <Placemark>\n');
     157            kplace=kml_placemark();
    163158            if (length(iloop)-1 > 1)
    164                 fprintf(fid,'        <name>Partition %d, Loop %d</name>\n',k,i);
     159                kplace.name      =sprintf('Partition %d, Loop %d',k,i);
    165160            else
    166                 fprintf(fid,'        <name>Partition %d</name>\n',k);
    167             end
    168             fprintf(fid,'        <visibility>1</visibility>\n');
     161                kplace.name      =sprintf('Partition %d',k);
     162            end
     163            kplace.visibility=1;
    169164            if exist('pdata','var')
    170                 fprintf(fid,'        <description>Partition data: %g</description>\n',pdata(k));
     165                kplace.descript  =sprintf('Partition data: %g',pdata(k));
    171166                imap = fix((pdata(k)-cmin)/(cmax-cmin)*size(cmap,1))+1;
    172167                if     (imap >= 1) && (imap <= size(cmap,1))
    173                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',imap);
     168                    kplace.styleurl  =sprintf('#MatlabColor%d',imap);
    174169                elseif (pdata(k) == cmax)
    175                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',size(cmap,1));
     170                    kplace.styleurl  =sprintf('#MatlabColor%d',size(cmap,1));
    176171                else
    177                     fprintf(fid,'        <styleUrl>#BlackLineEmptyPoly</styleUrl>\n');
     172                    kplace.styleurl  =sprintf('#BlackLineEmptyPoly');
    178173                end
    179174            else
    180                 fprintf(fid,'        <styleUrl>#BlackLineRandomPoly</styleUrl>\n');
    181             end
    182 %            fprintf(fid,'        <Polygon>\n');
    183 %            fprintf(fid,'          <extrude>1</extrude>\n');
    184 %            fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    185 %            fprintf(fid,'          <outerBoundaryIs>\n');
    186 %            fprintf(fid,'            <LinearRing>\n');
    187         fprintf(fid,'        <LineString>\n');
    188         fprintf(fid,'          <extrude>1</extrude>\n');
    189         fprintf(fid,'          <tessellate>1</tessellate>\n');
    190         fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    191             fprintf(fid,'              <coordinates>\n');
     175                kplace.styleurl  =sprintf('#BlackLineRandomPoly');
     176            end
     177
     178            kline=kml_linestring();
     179            kline.extrude   =1;
     180            kline.tessellate=1;
     181            kline.altmode   ='relativeToGround';
     182            kline.coords    =zeros(0,3);
     183
    192184            elast=0;
    193185            nlast=0;
     
    218210%  if first edge, write out first node
    219211                    if ~elast
    220                         [lat(end+1),long(end+1)]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
    221                         fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     212                        [lat,long]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
     213                        kline.coords(end+1,:)=[long lat alt];
    222214                    end
    223                     [lat(end+1),long(end+1)]=mapxy(md.x(edgeper(j,2)),md.y(edgeper(j,2)),'s');
    224                     fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     215                    [lat,long]=mapxy(md.x(edgeper(j,2)),md.y(edgeper(j,2)),'s');
     216                    kline.coords(end+1,:)=[long lat alt];
    225217                    elast=elemper(j);
    226218                    nlast=edgeper(j,2);
     
    309301%  write out first node of first side for half-edge to midpoint
    310302%                                disp(['segment j=' int2str(j) ' unshared half edge from node ' int2str(elemp(ielem,nlast)) ' (node ' int2str(nlast) ') on side ' int2str(slast) ' from element ' int2str(ielem) ' written.'])
    311                                 [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,nlast))),...
    312                                                                (md.y(elemp(ielem,nlast))),'s');
    313                                 fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     303                                [lat,long]=mapxy((md.x(elemp(ielem,nlast))),...
     304                                                 (md.y(elemp(ielem,nlast))),'s');
     305                                kline.coords(end+1,:)=[long lat alt];
    314306                            end
    315307                            nlast=0;
    316308                           
    317309%  write out midpoint of first side
    318                             [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,slast))...
    319                                                            +md.x(elemp(ielem,mod(slast,3)+1)))/2.,...
    320                                                            (md.y(elemp(ielem,slast))...
    321                                                            +md.y(elemp(ielem,mod(slast,3)+1)))/2.,'s');
    322                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     310                            [lat,long]=mapxy((md.x(elemp(ielem,slast))...
     311                                             +md.x(elemp(ielem,mod(slast,3)+1)))/2.,...
     312                                             (md.y(elemp(ielem,slast))...
     313                                             +md.y(elemp(ielem,mod(slast,3)+1)))/2.,'s');
     314                            kline.coords(end+1,:)=[long lat alt];
    323315                        end
    324316
     
    359351%  write out half-edge from current node to midpoint of unshared side
    360352%                            disp(['segment j=' int2str(j) ' unshared half edge from node ' int2str(elemp(ielem,nlast)) ' (node ' int2str(nlast) ') on side ' int2str(slast) ' from element ' int2str(ielem) ' written.'])
    361                             [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,nlast))...
    362                                                            +md.x(elemp(ielem,nnext)))/2.,...
    363                                                            (md.y(elemp(ielem,nlast))...
    364                                                            +md.y(elemp(ielem,nnext)))/2.,'s');
    365                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     353                            [lat,long]=mapxy((md.x(elemp(ielem,nlast))...
     354                                             +md.x(elemp(ielem,nnext)))/2.,...
     355                                             (md.y(elemp(ielem,nlast))...
     356                                             +md.y(elemp(ielem,nnext)))/2.,'s');
     357                            kline.coords(end+1,:)=[long lat alt];
    366358                            nlast=0;
    367359
     
    393385%  all different, so cut through centroid
    394386%                                disp(['element ielem=' int2str(ielem) ' centroid written.'])
    395                                 [lat(end+1),long(end+1)]=mapxy(sum(md.x(elemp(ielem,:)))/3.,...
    396                                                                sum(md.y(elemp(ielem,:)))/3.,'s');
    397                                 fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     387                                [lat,long]=mapxy(sum(md.x(elemp(ielem,:)))/3.,...
     388                                                 sum(md.y(elemp(ielem,:)))/3.,'s');
     389                                kline.coords(end+1,:)=[long lat alt];
    398390                            end
    399391%  one node is in current partition, so cut off other two nodes
     
    409401%  write out midpoint of opposite side
    410402%                        disp(['segment j=' int2str(j) ' internal edge from side ' int2str(slast) ' to side ' int2str(snext) ' from element ' int2str(ielem) ' written.'])
    411                         [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,snext))...
    412                                                        +md.x(elemp(ielem,mod(snext,3)+1)))/2.,...
    413                                                        (md.y(elemp(ielem,snext))...
    414                                                        +md.y(elemp(ielem,mod(snext,3)+1)))/2.,'s');
    415                         fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     403                        [lat,long]=mapxy((md.x(elemp(ielem,snext))...
     404                                         +md.x(elemp(ielem,mod(snext,3)+1)))/2.,...
     405                                         (md.y(elemp(ielem,snext))...
     406                                         +md.y(elemp(ielem,mod(snext,3)+1)))/2.,'s');
     407                        kline.coords(end+1,:)=[long lat alt];
    416408                        elast=ielem;
    417409                        nlast=0;
     
    442434                            end
    443435%                            disp(['segment j=' int2str(j) ' unshared half edge on side ' int2str(slast) ' to node ' int2str(elemp(elast,nnext)) ' (node ' int2str(nnext) ') from element ' int2str(elast) ' written.'])
    444                             [lat(end+1),long(end+1)]=mapxy(md.x(elemp(elast,nnext)),...
    445                                                            md.y(elemp(elast,nnext)),'s');
    446                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     436                            [lat,long]=mapxy(md.x(elemp(elast,nnext)),...
     437                                             md.y(elemp(elast,nnext)),'s');
     438                            kline.coords(end+1,:)=[long lat alt];
    447439                            break
    448440%  if not unshared, advance perimeter list and watch for end
     
    461453                end
    462454            end
    463 %            fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(iloop(i)),lat(iloop(i)),alt);
    464 
    465             fprintf(fid,'              </coordinates>\n');
    466         fprintf(fid,'        </LineString>\n');
    467 %            fprintf(fid,'            </LinearRing>\n');
    468 %            fprintf(fid,'          </outerBoundaryIs>\n');
    469 %            fprintf(fid,'        </Polygon>\n');
    470             fprintf(fid,'      </Placemark>\n');
     455
     456            kplace.geometry=kline;
     457            kfold.feature{1}(end+1)=kplace;
     458            clear kline kplace
    471459        end
    472460    end
    473     fprintf(fid,'    </Folder>\n');
    474 end
    475 
    476 end
    477 
     461end
     462
     463end
     464
  • issm/trunk/src/m/kml/kml_part_elems.m

    r6417 r6461  
    22%  create kml polygons for the partition elements.
    33%
    4 %  []=kml_part_elems(fid,md,params)
     4%  [kfold]=kml_part_elems(md,params)
    55%
    66%  where the required input is:
    7 %    fid           (char, file ID of .kml file)
    87%    md            (model, model class object)
    98%
     
    1918%    prtplt        (char, 'off'/'no' for partition segment plot)
    2019%
    21 function []=kml_part_elems(varargin)
     20%  and the required output is:
     21%    kfold         (kml_folder, folder of polygon placemarks)
     22%
     23function [kfold]=kml_part_elems(varargin)
    2224
    2325if ~nargin
     
    3032iarg=1;
    3133if (nargin >= 1)
    32     fid=varargin{1};
    33 end
    34 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    35     error('File ID ''%d'' must be open.',fid);
    36 end
    37 
    38 iarg=iarg+1;
    39 if (nargin >= 2)
    40     md=varargin{2};
     34    md=varargin{1};
    4135end
    4236if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    109103if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    110104    md.npart
    111     fprintf(fid,'    <Folder>\n');
    112     fprintf(fid,'      <name>Partition Elements</name>\n');
    113     fprintf(fid,'      <visibility>1</visibility>\n');
    114     fprintf(fid,'      <description>Partitions=%d, Nodes=%d</description>\n',...
     105    kfold=kml_folder();
     106    kfold.name      ='Partition Elements';
     107    kfold.visibility=1;
     108    kfold.descript  =sprintf('Partitions=%d, Nodes=%d\n',...
    115109        md.npart,md.numberofgrids);
     110    kfold.feature   ={repmat(kml_placemark(),0,0)};
    116111
    117 %  write each partition loop as a polygon
     112%  write each partition loop as a polygon placemark
    118113
    119114    disp(['Writing ' num2str(md.npart) ' partitions as KML polygons.']);
     
    144139        end
    145140        for i=1:length(iloop)-1
    146             fprintf(fid,'      <Placemark>\n');
     141            kplace=kml_placemark();
    147142            if (length(iloop)-1 > 1)
    148                 fprintf(fid,'        <name>Partition %d, Loop %d</name>\n',k,i);
     143                kplace.name      =sprintf('Partition %d, Loop %d',k,i);
    149144            else
    150                 fprintf(fid,'        <name>Partition %d</name>\n',k);
     145                kplace.name      =sprintf('Partition %d',k);
    151146            end
    152             fprintf(fid,'        <visibility>1</visibility>\n');
     147            kplace.visibility=1;
    153148            if exist('pdata','var')
    154                 fprintf(fid,'        <description>Partition data: %g</description>\n',pdata(k));
     149                kplace.descript  =sprintf('Partition data: %g',pdata(k));
    155150                imap = fix((pdata(k)-cmin)/(cmax-cmin)*size(cmap,1))+1;
    156151                if     (imap >= 1) && (imap <= size(cmap,1))
    157                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',imap);
     152                    kplace.styleurl  =sprintf('#MatlabColor%d',imap);
    158153                elseif (pdata(k) == cmax)
    159                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',size(cmap,1));
     154                    kplace.styleurl  =sprintf('#MatlabColor%d',size(cmap,1));
    160155                else
    161                     fprintf(fid,'        <styleUrl>#BlackLineEmptyPoly</styleUrl>\n');
     156                    kplace.styleurl  =sprintf('#BlackLineEmptyPoly');
    162157                end
    163158            else
    164                 fprintf(fid,'        <styleUrl>#BlackLineRandomPoly</styleUrl>\n');
     159                kplace.styleurl  =sprintf('#BlackLineRandomPoly');
    165160            end
    166             fprintf(fid,'        <Polygon>\n');
    167             fprintf(fid,'          <extrude>1</extrude>\n');
    168             fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    169             fprintf(fid,'          <outerBoundaryIs>\n');
    170             fprintf(fid,'            <LinearRing>\n');
    171             fprintf(fid,'              <coordinates>\n');
     161
     162            kpoly=kml_polygon();
     163            kpoly.extrude   =1;
     164            kpoly.altmode   ='relativeToGround';
     165
     166            kring=kml_linearring();
     167            kring.coords    =zeros(iloop(i+1)-iloop(i)+1,3);
     168
    172169            for j=iloop(i):iloop(i+1)-1
    173                 [lat(j),long(j)]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
    174                 fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(j),lat(j),alt);
     170                [lat,long]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
     171                kring.coords(j-iloop(i)+1,:)=[long lat alt];
    175172            end
    176             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(iloop(i)),lat(iloop(i)),alt);
     173            kring.coords(end,:)=kring.coords(1,:);
    177174
    178             fprintf(fid,'              </coordinates>\n');
    179             fprintf(fid,'            </LinearRing>\n');
    180             fprintf(fid,'          </outerBoundaryIs>\n');
    181             fprintf(fid,'        </Polygon>\n');
    182             fprintf(fid,'      </Placemark>\n');
     175            kpoly.outer=kring;
     176            kplace.geometry=kpoly;
     177            kfold.feature{1}(end+1)=kplace;
     178            clear kring kpoly kplace
    183179        end
    184180    end
    185     fprintf(fid,'    </Folder>\n');
    186181end
    187182
  • issm/trunk/src/m/kml/kml_part_flagedges.m

    r6417 r6461  
    22%  create kml linestrings for the flagged partition edges.
    33%
    4 %  []=kml_part_flagedges(fid,md,params)
     4%  [kfold]=kml_part_flagedges(md,params)
    55%
    66%  where the required input is:
    7 %    fid           (char, file ID of .kml file)
    87%    md            (model, model class object)
    98%
     
    1312%  and the optional input is:
    1413%    alt           (numeric, altitude for polygons, default 10000)
    15 %    prtplt        (char, 'off'/'no' for partition segment plot)
     14%    prtplt        (char, 'off'/'no' for partition edge plot)
    1615%
    17 function []=kml_part_flagedges(varargin)
     16%  and the required output is:
     17%    kfold         (kml_folder, folder of linestring placemarks)
     18%
     19function [kfold]=kml_part_flagedges(varargin)
    1820
    1921if ~nargin
     
    2628iarg=1;
    2729if (nargin >= 1)
    28     fid=varargin{1};
    29 end
    30 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    31     error('File ID ''%d'' must be open.',fid);
    32 end
    33 
    34 iarg=iarg+1;
    35 if (nargin >= 2)
    36     md=varargin{2};
     30    md=varargin{1};
    3731end
    3832if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    6660    md.npart
    6761    [xseg,yseg]=flagedges(md.elements,md.x,md.y,md.part);
    68     fprintf(fid,'    <Folder>\n');
    69     fprintf(fid,'      <name>Partition Segments</name>\n');
    70     fprintf(fid,'      <visibility>1</visibility>\n');
    71     fprintf(fid,'      <description>Partitions=%d, Segments=%d</description>\n',...
     62    kfold=kml_folder();
     63    kfold.name      ='Partition Segments';
     64    kfold.visibility=1;
     65    kfold.descript  =sprintf('Partitions=%d, Segments=%d',...
    7266        md.npart,size(xseg,1));
     67    kfold.feature   ={repmat(kml_placemark(),1,size(xseg,1))};
    7368
    74 %  write each segment as a linestring
     69%  write each segment as a linestring placemark
    7570
    7671    disp(['Writing ' num2str(size(xseg,1)) ' partition segments as KML linestrings.']);
    7772    for i=1:size(xseg,1)
    78         fprintf(fid,'      <Placemark>\n');
    79         fprintf(fid,'        <name>Segment %d</name>\n',i);
    80         fprintf(fid,'        <visibility>1</visibility>\n');
    81         fprintf(fid,'        <styleUrl>#RedLineRedPoly</styleUrl>\n');
    82         fprintf(fid,'        <LineString>\n');
    83         fprintf(fid,'          <extrude>1</extrude>\n');
    84         fprintf(fid,'          <tessellate>1</tessellate>\n');
    85         fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    86         fprintf(fid,'          <coordinates>\n');
     73        kplace=kml_placemark();
     74        kplace.name      =sprintf('Segment %d',i);
     75        kplace.visibility=1;
     76        kplace.styleurl  ='#RedLineRedPoly';
     77
     78        kline=kml_linestring();
     79        kline.extrude   =1;
     80        kline.tessellate=1;
     81        kline.altmode   ='relativeToGround';
     82        kline.coords    =zeros(2,3);
     83
    8784        for j=1:2
    88             [lat(j),long(j)]=mapxy(xseg(i,j),yseg(i,j),'s');
    89             fprintf(fid,'            %0.16g,%0.16g,%0.16g\n',long(j),lat(j),alt);
     85            [lat,long]=mapxy(xseg(i,j),yseg(i,j),'s');
     86            kline.coords(j,:)=[long lat alt];
    9087        end
    9188
    92         fprintf(fid,'          </coordinates>\n');
    93         fprintf(fid,'        </LineString>\n');
    94         fprintf(fid,'      </Placemark>\n');
     89        kplace.geometry=kline;
     90        kfold.feature{1}(i)=kplace;
     91        clear kline kplace
    9592    end
    96     fprintf(fid,'    </Folder>\n');
    9793end
    9894
  • issm/trunk/src/m/kml/kml_partitions.m

    r6417 r6461  
    22%  create kml polygons for the partitions.
    33%
    4 %  []=kml_partitions(fid,md,params)
     4%  [kfold]=kml_partitions(fid,md,params)
    55%
    66%  where the required input is:
     
    1919%    prtplt        (char, 'off'/'no' for partition segment plot)
    2020%
    21 function []=kml_partitions(varargin)
     21%  and the required output is:
     22%    kfold         (kml_folder, folder of polygon placemarks)
     23%
     24function [kfold]=kml_partitions(varargin)
    2225
    2326if ~nargin
     
    3033iarg=1;
    3134if (nargin >= 1)
    32     fid=varargin{1};
    33 end
    34 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    35     error('File ID ''%d'' must be open.',fid);
    36 end
    37 
    38 iarg=iarg+1;
    39 if (nargin >= 2)
    40     md=varargin{2};
     35    md=varargin{1};
    4136end
    4237if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    109104if (~exist('prtplt','var') || strncmpi(prtplt,'on' ,2) || strncmpi(prtplt,'y',1)) && ...
    110105    md.npart
    111     fprintf(fid,'    <Folder>\n');
    112     fprintf(fid,'      <name>Partitions</name>\n');
    113     fprintf(fid,'      <visibility>1</visibility>\n');
    114     fprintf(fid,'      <description>Partitions=%d, Nodes=%d</description>\n',...
     106    kfold=kml_folder();
     107    kfold.name      ='Partitions';
     108    kfold.visibility=1;
     109    kfold.descript  =sprintf('Partitions=%d, Nodes=%d',...
    115110        md.npart,md.numberofgrids);
    116 
    117 %  write each partition loop as linestrings
     111    kfold.feature   ={repmat(kml_placemark(),0,0)};
     112
     113%  write each partition loop as polygon placemark
    118114
    119115    disp(['Writing ' num2str(md.npart) ' partitions as KML polygons.']);
     
    160156
    161157        for i=1:length(iloop)-1
    162             fprintf(fid,'      <Placemark>\n');
     158            kplace=kml_placemark();
    163159            if (length(iloop)-1 > 1)
    164                 fprintf(fid,'        <name>Partition %d, Loop %d</name>\n',k,i);
     160                kplace.name      =sprintf('Partition %d, Loop %d',k,i);
    165161            else
    166                 fprintf(fid,'        <name>Partition %d</name>\n',k);
    167             end
    168             fprintf(fid,'        <visibility>1</visibility>\n');
     162                kplace.name      =sprintf('Partition %d',k);
     163            end
     164            kplace.visibility=1;
    169165            if exist('pdata','var')
    170                 fprintf(fid,'        <description>Partition data: %g</description>\n',pdata(k));
     166                kplace.descript  =sprintf('Partition data: %g',pdata(k));
    171167                imap = fix((pdata(k)-cmin)/(cmax-cmin)*size(cmap,1))+1;
    172168                if     (imap >= 1) && (imap <= size(cmap,1))
    173                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',imap);
     169                    kplace.styleurl  =sprintf('#MatlabColor%d',imap);
    174170                elseif (pdata(k) == cmax)
    175                     fprintf(fid,'        <styleUrl>#MatlabColor%d</styleUrl>\n',size(cmap,1));
     171                    kplace.styleurl  =sprintf('#MatlabColor%d',size(cmap,1));
    176172                else
    177                     fprintf(fid,'        <styleUrl>#BlackLineEmptyPoly</styleUrl>\n');
     173                    kplace.styleurl  =sprintf('#BlackLineEmptyPoly');
    178174                end
    179175            else
    180                 fprintf(fid,'        <styleUrl>#BlackLineRandomPoly</styleUrl>\n');
    181             end
    182             fprintf(fid,'        <Polygon>\n');
    183             fprintf(fid,'          <extrude>1</extrude>\n');
    184             fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    185             fprintf(fid,'          <outerBoundaryIs>\n');
    186             fprintf(fid,'            <LinearRing>\n');
    187             fprintf(fid,'              <coordinates>\n');
     176                kplace.styleurl  =sprintf('#BlackLineRandomPoly');
     177            end
     178
     179            kpoly=kml_polygon();
     180            kpoly.extrude   =1;
     181            kpoly.altmode   ='relativeToGround';
     182
     183            kring=kml_linearring();
     184            kring.coords    =zeros(0,3);
     185
    188186            elast=0;
    189187            nlast=0;
     
    214212%  if first edge, write out first node
    215213                    if ~elast
    216                         [lat(end+1),long(end+1)]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
    217                         fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     214                        [lat,long]=mapxy(md.x(edgeper(j,1)),md.y(edgeper(j,1)),'s');
     215                        kring.coords(end+1,:)=[long lat alt];
    218216                    end
    219                     [lat(end+1),long(end+1)]=mapxy(md.x(edgeper(j,2)),md.y(edgeper(j,2)),'s');
    220                     fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     217                    [lat,long]=mapxy(md.x(edgeper(j,2)),md.y(edgeper(j,2)),'s');
     218                    kring.coords(end+1,:)=[long lat alt];
    221219                    elast=elemper(j);
    222220                    nlast=edgeper(j,2);
     
    305303%  write out first node of first side for half-edge to midpoint
    306304%                                disp(['segment j=' int2str(j) ' unshared half edge from node ' int2str(elemp(ielem,nlast)) ' (node ' int2str(nlast) ') on side ' int2str(slast) ' from element ' int2str(ielem) ' written.'])
    307                                 [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,nlast))),...
    308                                                                (md.y(elemp(ielem,nlast))),'s');
    309                                 fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     305                                [lat,long]=mapxy((md.x(elemp(ielem,nlast))),...
     306                                                 (md.y(elemp(ielem,nlast))),'s');
     307                                kring.coords(end+1,:)=[long lat alt];
    310308                            end
    311309                            nlast=0;
    312310                           
    313311%  write out midpoint of first side
    314                             [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,slast))...
    315                                                            +md.x(elemp(ielem,mod(slast,3)+1)))/2.,...
    316                                                            (md.y(elemp(ielem,slast))...
    317                                                            +md.y(elemp(ielem,mod(slast,3)+1)))/2.,'s');
    318                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     312                            [lat,long]=mapxy((md.x(elemp(ielem,slast))...
     313                                             +md.x(elemp(ielem,mod(slast,3)+1)))/2.,...
     314                                             (md.y(elemp(ielem,slast))...
     315                                             +md.y(elemp(ielem,mod(slast,3)+1)))/2.,'s');
     316                            kring.coords(end+1,:)=[long lat alt];
    319317                        end
    320318
     
    355353%  write out half-edge from current node to midpoint of unshared side
    356354%                            disp(['segment j=' int2str(j) ' unshared half edge from node ' int2str(elemp(ielem,nlast)) ' (node ' int2str(nlast) ') on side ' int2str(slast) ' from element ' int2str(ielem) ' written.'])
    357                             [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,nlast))...
    358                                                            +md.x(elemp(ielem,nnext)))/2.,...
    359                                                            (md.y(elemp(ielem,nlast))...
    360                                                            +md.y(elemp(ielem,nnext)))/2.,'s');
    361                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     355                            [lat,long]=mapxy((md.x(elemp(ielem,nlast))...
     356                                             +md.x(elemp(ielem,nnext)))/2.,...
     357                                             (md.y(elemp(ielem,nlast))...
     358                                             +md.y(elemp(ielem,nnext)))/2.,'s');
     359                            kring.coords(end+1,:)=[long lat alt];
    362360                            nlast=0;
    363361
     
    389387%  all different, so cut through centroid
    390388%                                disp(['element ielem=' int2str(ielem) ' centroid written.'])
    391                                 [lat(end+1),long(end+1)]=mapxy(sum(md.x(elemp(ielem,:)))/3.,...
    392                                                                sum(md.y(elemp(ielem,:)))/3.,'s');
    393                                 fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     389                                [lat,long]=mapxy(sum(md.x(elemp(ielem,:)))/3.,...
     390                                                 sum(md.y(elemp(ielem,:)))/3.,'s');
     391                                kring.coords(end+1,:)=[long lat alt];
    394392                            end
    395393%  one node is in current partition, so cut off other two nodes
     
    405403%  write out midpoint of opposite side
    406404%                        disp(['segment j=' int2str(j) ' internal edge from side ' int2str(slast) ' to side ' int2str(snext) ' from element ' int2str(ielem) ' written.'])
    407                         [lat(end+1),long(end+1)]=mapxy((md.x(elemp(ielem,snext))...
    408                                                        +md.x(elemp(ielem,mod(snext,3)+1)))/2.,...
    409                                                        (md.y(elemp(ielem,snext))...
    410                                                        +md.y(elemp(ielem,mod(snext,3)+1)))/2.,'s');
    411                         fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     405                        [lat,long]=mapxy((md.x(elemp(ielem,snext))...
     406                                         +md.x(elemp(ielem,mod(snext,3)+1)))/2.,...
     407                                         (md.y(elemp(ielem,snext))...
     408                                         +md.y(elemp(ielem,mod(snext,3)+1)))/2.,'s');
     409                        kring.coords(end+1,:)=[long lat alt];
    412410                        elast=ielem;
    413411                        nlast=0;
     
    438436                            end
    439437%                            disp(['segment j=' int2str(j) ' unshared half edge on side ' int2str(slast) ' to node ' int2str(elemp(elast,nnext)) ' (node ' int2str(nnext) ') from element ' int2str(elast) ' written.'])
    440                             [lat(end+1),long(end+1)]=mapxy(md.x(elemp(elast,nnext)),...
    441                                                            md.y(elemp(elast,nnext)),'s');
    442                             fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(end),lat(end),alt);
     438                            [lat,long]=mapxy(md.x(elemp(elast,nnext)),...
     439                                             md.y(elemp(elast,nnext)),'s');
     440                            kring.coords(end+1,:)=[long lat alt];
    443441                            break
    444442%  if not unshared, advance perimeter list and watch for end
     
    457455                end
    458456            end
    459 %            fprintf(fid,'                %0.16g,%0.16g,%0.16g\n',long(iloop(1)),lat(iloop(1)),alt);
    460 
    461             fprintf(fid,'              </coordinates>\n');
    462             fprintf(fid,'            </LinearRing>\n');
    463             fprintf(fid,'          </outerBoundaryIs>\n');
    464             fprintf(fid,'        </Polygon>\n');
    465             fprintf(fid,'      </Placemark>\n');
     457
     458            kpoly.outer=kring;
     459            kplace.geometry=kpoly;
     460            kfold.feature{1}(end+1)=kplace;
     461            clear kring kpoly kplace
    466462        end
    467463    end
    468     fprintf(fid,'    </Folder>\n');
    469 end
    470 
    471 end
    472 
     464end
     465
     466end
     467
  • issm/trunk/src/m/kml/kml_unsh_edges.m

    r6417 r6461  
    22%  create kml linestrings for the unshared element edges.
    33%
    4 %  []=kml_unsh_edges(fid,md,params)
     4%  [kfold]=kml_unsh_edges(md,params)
    55%
    66%  where the required input is:
    7 %    fid           (char, file ID of .kml file)
    87%    md            (model, model class object)
    98%
     
    1312%  and the optional input is:
    1413%    alt           (numeric, altitude for polygons, default 10000)
    15 %    prtplt        (char, 'off'/'no' for partition segment plot)
     14%    prtplt        (char, 'off'/'no' for partition edge plot)
    1615%
    17 function []=kml_unsh_edges(varargin)
     16%  and the required output is:
     17%    kfold         (kml_folder, folder of linestring placemarks)
     18%
     19function [kfold]=kml_unsh_edges(varargin)
    1820
    1921if ~nargin
     
    2628iarg=1;
    2729if (nargin >= 1)
    28     fid=varargin{1};
    29 end
    30 if ~exist('fid','var') || isempty(fid) || (fid < 0)
    31     error('File ID ''%d'' must be open.',fid);
    32 end
    33 
    34 iarg=iarg+1;
    35 if (nargin >= 2)
    36     md=varargin{2};
     30    md=varargin{1};
    3731end
    3832if ~exist('md','var') || isempty(md) || ~isa(md,'model')
     
    7266        edgeuns(i,2)=md.elements(irow(i),mod(icol(i),size(md.elements,2))+1);
    7367    end
    74     fprintf(fid,'    <Folder>\n');
    75     fprintf(fid,'      <name>Unshared Edges</name>\n');
    76     fprintf(fid,'      <visibility>1</visibility>\n');
    77     fprintf(fid,'      <description>Partitions=%d, Edges=%d</description>\n',...
     68    kfold=kml_folder();
     69    kfold.name      ='Unshared Edges';
     70    kfold.visibility=1;
     71    kfold.descript  =sprintf('Partitions=%d, Edges=%d',...
    7872        md.npart,size(edgeuns,1));
     73    kfold.feature   ={repmat(kml_placemark(),1,size(edgeuns,1))};
    7974
    80 %  write each edge as a linestring
     75%  write each edge as a linestring placemark
    8176
    8277    disp(['Writing ' num2str(size(edgeuns,1)) ' unshared edges as KML linestrings.']);
    8378    for i=1:size(edgeuns,1)
    84         fprintf(fid,'      <Placemark>\n');
    85         fprintf(fid,'        <name>Edge %d</name>\n',i);
    86         fprintf(fid,'        <visibility>1</visibility>\n');
    87         fprintf(fid,'        <styleUrl>#RedLineRedPoly</styleUrl>\n');
    88         fprintf(fid,'        <LineString>\n');
    89         fprintf(fid,'          <extrude>1</extrude>\n');
    90         fprintf(fid,'          <tessellate>1</tessellate>\n');
    91         fprintf(fid,'          <altitudeMode>relativeToGround</altitudeMode>\n');
    92         fprintf(fid,'          <coordinates>\n');
     79        kplace=kml_placemark();
     80        kplace.name      =sprintf('Edge %d',i);
     81        kplace.visibility=1;
     82        kplace.styleurl  ='#RedLineRedPoly';
     83
     84        kline=kml_linestring();
     85        kline.extrude   =1;
     86        kline.tessellate=1;
     87        kline.altmode   ='relativeToGround';
     88        kline.coords    =zeros(2,3);
     89
    9390        for j=1:2
    94             [lat(j),long(j)]=mapxy(md.x(edgeuns(i,j)),md.y(edgeuns(i,j)),'s');
    95             fprintf(fid,'            %0.16g,%0.16g,%0.16g\n',long(j),lat(j),alt);
     91            [lat,long]=mapxy(md.x(edgeuns(i,j)),md.y(edgeuns(i,j)),'s');
     92            kline.coords(j,:)=[long lat alt];
    9693        end
    9794
    98         fprintf(fid,'          </coordinates>\n');
    99         fprintf(fid,'        </LineString>\n');
    100         fprintf(fid,'      </Placemark>\n');
     95        kplace.geometry=kline;
     96        kfold.feature{1}(i)=kplace;
     97        clear kline kplace
    10198    end
    102     fprintf(fid,'    </Folder>\n');
    10399end
    104100
Note: See TracChangeset for help on using the changeset viewer.