Changeset 24884


Ignore:
Timestamp:
05/22/20 09:29:34 (5 years ago)
Author:
Eric.Larour
Message:

CHG: added export routine to output shapefiles.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk-jpl/src/m/classes/mesh2d.m

    r24778 r24884  
    189189
    190190                end % }}}
     191                function export(self,varargin) % {{{
     192
     193                        options=pairoptions(varargin{:});
     194                        filename=getfieldvalue(options,'filename');
     195                        format=getfieldvalue(options,'format','shp');
     196                        geometry=getfieldvalue(options,'geometry','line');
     197                        index=getfieldvalue(options,'index',[]);
     198                        proj=getfieldvalue(options,'projection','');
     199
     200                        %prepare contours:
     201                        contours= struct([]);
     202                        if strcmpi(geometry,'point'),
     203                                for i=1:self.numberofvertices,
     204                                        contours(i).x = self.x(i);
     205                                        contours(i).y = self.y(i);
     206                                        contours(i).id = i;
     207                                        contours(i).Geometry = 'Point';
     208                                end
     209                        elseif strcmpi(geometry,'line'),
     210                                counter=1;
     211                                for i=1:self.numberofelements,
     212                                        el=self.elements(i,:);
     213                                        %first line:
     214                                        contours(counter).x = [self.x(el(1)) self.x(el(2))];
     215                                        contours(counter).y = [self.y(el(1)) self.y(el(2))];
     216                                        contours(counter).Geometry = 'Line';
     217
     218                                        %second line:
     219                                        contours(counter+1).x = [self.x(el(2)) self.x(el(3))];
     220                                        contours(counter+1).y = [self.y(el(2)) self.y(el(3))];
     221                                        contours(counter+1).Geometry = 'Line';
     222
     223                                        %third line:
     224                                        contours(counter+2).x = [self.x(el(3)) self.x(el(1))];
     225                                        contours(counter+2).y = [self.y(el(3)) self.y(el(1))];
     226                                        contours(counter+2).Geometry = 'Line';
     227                                       
     228                                        %increase counter:
     229                                        counter=counter+3;
     230                                end
     231                        elseif strcmpi(geometry,'polygon'),
     232                                if isempty(index),
     233                                        counter=1;
     234                                        for i=1:self.numberofelements,
     235                                                el=self.elements(i,:);
     236                                                contours(i).x=[self.x(el(1)) self.x(el(2)) self.x(el(3)) self.x(el(1))];
     237                                                contours(i).y=[self.y(el(1)) self.y(el(2)) self.y(el(3)) self.y(el(1))];
     238                                                contours(i).Geometry = 'Polygon';
     239                                                contours(i).Id = i;
     240                                        end
     241                                else
     242                                        counter=1;
     243                                        for i=1:length(index),
     244                                                el=self.elements(index(i),:);
     245                                                contours(i).x=[self.x(el(1)) self.x(el(2)) self.x(el(3)) self.x(el(1))];
     246                                                contours(i).y=[self.y(el(1)) self.y(el(2)) self.y(el(3)) self.y(el(1))];
     247                                                contours(i).id = index(i);
     248                                                contours(i).Geometry = 'Polygon';
     249                                        end
     250                                end
     251                        else
     252                                error(sprintf('mesh3dsurface ''export'' error message: geometry %s not supported yet (should be ''point'' or ''line''',geometry));
     253                        end
     254
     255                        %write file:
     256                        if strcmpi(format,'shp'),
     257                                shpwrite(contours,filename);
     258                        elseif strcmpi(format,'exp'),
     259                                expwrite(contours,filename);
     260                        else
     261                                error(sprintf('mesh3dsurface ''export'' error message: file format %s not supported yet',format));
     262                        end
     263
     264                        %write projection file:
     265                        if ~isempty(proj),
     266                                proj2shpprj(filename,proj);
     267                        end
     268                        %write style file:
     269                        applyqgisstyle(filename,'mesh');
     270
     271
     272                end % }}}
    191273        end
    192274end
Note: See TracChangeset for help on using the changeset viewer.