Changeset 24779
- Timestamp:
- 05/04/20 10:03:33 (5 years ago)
- Location:
- issm/trunk-jpl/src/m
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/basin.m
r24761 r24779 7 7 properties (SetAccess=public) 8 8 boundaries = {}; 9 epsg = 3426;10 9 name = ''; 11 10 continent = ''; 11 proj = epsg2proj(4326); 12 12 end 13 13 methods (Static) … … 31 31 self.name=getfieldvalue(options,'name',''); 32 32 self.continent=getfieldvalue(options,'continent',''); 33 self.epsg=getfieldvalue(options,'epsg',3426); 33 34 %figure out projection string: 35 if exist(options,'epsg'), 36 if exist(options,'proj'), 37 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 38 end 39 epsg=getfieldvalue(options,'epsg'); 40 %convert into proj4: 41 proj=epsg2proj(epsg); 42 elseif exist(options,'proj'), 43 if exist(options,'epsg'), 44 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 45 end 46 proj=getfieldvalue(options,'proj'); 47 else 48 proj= '+proj=longlat +datum=WGS84 +no_defs'; 49 end 50 self.proj=proj; 34 51 end 35 52 end % }}} … … 37 54 self.name=''; 38 55 self.continent=''; 39 self. epsg=3426;56 self.proj='+proj=longlat +datum=WGS84 +no_defs '; %EPSG 4326 40 57 self.boundaries={}; 41 58 … … 45 62 fielddisplay(self,'continent','continent name'); 46 63 fielddisplay(self,'name','basin name'); 47 fielddisplay(self,' epsg','epsg projection number for the entire basin');64 fielddisplay(self,'proj','basin projection string (follows PROJ.4 standard)'); 48 65 fielddisplay(self,'boundaries','list of boundary objects'); 49 66 for i=1:length(self.boundaries), … … 87 104 %add option: 88 105 for i=1:length(self.boundaries), 89 self.boundaries{i}.plot(' epsg',self.epsg,varargin{:});106 self.boundaries{i}.plot('proj',self.proj,varargin{:}); 90 107 end 91 108 … … 109 126 boundary=self.boundaries{i}; 110 127 contour=boundary.edges(); 111 [contour.x,contour.y]=gdaltransform(contour.x,contour.y, sprintf('EPSG:%i',boundary.epsg),sprintf('EPSG:%i',self.epsg));128 [contour.x,contour.y]=gdaltransform(contour.x,contour.y,boundary.proj,self.proj); 112 129 x=[x;contour.x]; 113 130 y=[y;contour.y]; … … 122 139 out.nods=length(x); 123 140 end % }}} 141 function checkconsistency(self,varargin) % {{{ 142 143 %recover options 144 options=pairoptions(varargin{:}); 145 146 %figure out if two boundaries are identical: 147 for i=1:length(self.boundaries), 148 namei=self.boundaries{i}.shpfilename; 149 for j=i+1:length(self.boundaries), 150 namej=self.boundaries{j}.shpfilename; 151 if strcmpi(namei,namej), 152 error(['Basin ' self.name ' has two identical boundaries named ' namei ]); 153 end 154 end 155 end 156 157 %go through boundaries and check their consistency: 158 for i=1:length(self.boundaries), 159 boundary=self.boundaries{i}; 160 boundary.checkconsistency(); 161 end 162 end % }}} 124 163 function contourplot(self,varargin) % {{{ 125 164 contour=self.contour(); … … 134 173 inshapefile=getfieldvalue(options,'shapefile'); 135 174 outputshapefile=getfieldvalue(options,'outputshapefile',''); 136 epsgshapefile=getfieldvalue(options,'epsgshapefile'); 175 176 if (exist(options,'epsgshapefile') & exist(options,'projshapefile')), 177 error('Basin shapefilecrop error message: cannot specify epsgshapefile and projshapefile at the same time'); 178 end 179 if exist(options,'epsgshapefile'), 180 projshapefile=epsg2proj(getfieldvalue(options,'epsgshapefile')); 181 elseif exist(options,'projshapefile'), 182 projshapefile=getfieldvalue(options,'projshapefile'); 183 else 184 error('Basin shapefilecrop error message: epsgshapefile or projshapefile should be specified'); 185 end 186 137 187 138 188 %create list of contours that have critical length > threshold: (in lat,long) … … 150 200 151 201 %project onto reference frame: 152 if self.epsg~=epsgshapefile, 153 for i=1:length(contours), 154 h=contours(i); 155 [h.x,h.y]=gdaltransform(h.x,h.y,sprintf('EPSG:%i',epsgshapefile),sprintf('EPSG:%i',self.epsg)); 156 contours(i).x=h.x; 157 contours(i).y=h.y; 158 end 202 for i=1:length(contours), 203 h=contours(i); 204 [h.x,h.y]=gdaltransform(h.x,h.y,projshapefile,self.proj); 205 contours(i).x=h.x; 206 contours(i).y=h.y; 159 207 end 160 208 -
issm/trunk-jpl/src/m/classes/boundary.m
r24765 r24779 9 9 shpfilename = ''; 10 10 orientation = 'normal'; %other value is 'reverse' 11 epsg = 4326; %EPSG number, default value is WGS 84 Lat,Long reference frame. 11 proj = epsg2proj(4326); %Proj4.0 projection string. , default is WGS 84 (corresponds to epsg 4326) 12 12 13 end 13 14 methods (Static) … … 30 31 self.shpfilename=getfieldvalue(options,'shpfilename',''); 31 32 self.orientation=getfieldvalue(options,'orientation','normal'); 32 self.epsg=getfieldvalue(options,'epsg',4326); 33 34 %figure out projection string: 35 if exist(options,'epsg'), 36 if exist(options,'proj'), 37 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 38 end 39 epsg=getfieldvalue(options,'epsg'); 40 %convert into proj4: 41 proj=epsg2proj(epsg); 42 elseif exist(options,'proj'), 43 if exist(options,'epsg'), 44 error(['Error in constructor for boundary ' self.shppath '.Cannot supply epsg and proj at the same time!']); 45 end 46 proj=getfieldvalue(options,'proj'); 47 else 48 proj= '+proj=longlat +datum=WGS84 +no_defs'; 49 end 50 self.proj=proj; 33 51 end 34 52 end % }}} … … 37 55 self.shpfilename=''; 38 56 self.orientation='normal'; 39 self. epsg=4326;57 self.proj='+proj=longlat +datum=WGS84 +no_defs '; %EPSG 4326 40 58 end % }}} 41 59 function disp(self) % {{{ … … 45 63 fielddisplay(self,'shpfilename','shape file name'); 46 64 fielddisplay(self,'orientation','orientation (default is ''normal'', can be ''reverse'')'); 47 fielddisplay(self,' epsg','EPSG number defining projection for the shape file');65 fielddisplay(self,'proj','shape file projection string (follows PROJ.4 standard)'); 48 66 49 67 end % }}} … … 77 95 markersize=getfieldvalue(options,'markersize',1); 78 96 unitmultiplier=getfieldvalue(options,'unit',1); 79 epsg=getfieldvalue(options,'epsg',4326);80 97 radius=getfieldvalue(options,'radius',6371012); 81 98 aboveground=getfieldvalue(options,'aboveground',1000); … … 84 101 label=getfieldvalue(options,'label','on'); 85 102 103 if (exist(options,'epsg') & exist(options,'proj')), 104 error('Boundary plot error message: cannot specify epsg and proj at the same time for plot projection'); 105 end 106 if exist(options,'epsg'), 107 proj=epsg2proj(getfieldvalue(options,'epsg')); 108 elseif exist(options,'proj'), 109 proj=getfieldvalue(options,'proj'); 110 else 111 proj=epsg2proj(4326); 112 end 113 86 114 %read domain: 87 115 [path,name,ext]=fileparts(self.shpfilename); … … 92 120 93 121 %convert boundary to another reference frame: {{{ 94 95 122 for i=1:length(domain), 96 123 try, 97 [x,y] = gdaltransform(domain(i).x,domain(i).y,s printf('EPSG:%i',self.epsg),sprintf('EPSG:%i',epsg));124 [x,y] = gdaltransform(domain(i).x,domain(i).y,self.proj,proj); 98 125 catch me 99 126 disp(me.message()); … … 125 152 %}}} 126 153 end % }}} 154 function checkconsistency(self,varargin) % {{{ 155 %recover options 156 options=pairoptions(varargin{:}); 157 tolerance=getfieldvalue(options,'tolerance',1e-5); 158 159 %recover edges: 160 edges=self.edges(); 161 162 if strcmpi(edges.Geometry,'Point'), 163 return; 164 else 165 %check we don't have two identical vertices: 166 x=edges.x; y=edges.y; 167 distance=sqrt( (x(1:end-1)-x(2:end)).^2+(y(1:end-1)-y(2:end)).^2); 168 dmax=max(distance); 169 isidentical=find(distance<dmax*tolerance); 170 if ~isempty(isidentical), 171 error(['boundary ' shpfilename ' has two vertices extremely close to one another']); 172 end 173 end 174 end % }}} 127 175 function plot3d(self,varargin) % {{{ 128 176 %recover options … … 136 184 markersize=getfieldvalue(options,'markersize',1); 137 185 unitmultiplier=getfieldvalue(options,'unit',1); 138 epsg=getfieldvalue(options,'epsg',4326);139 186 radius=getfieldvalue(options,'radius',6371012); 140 187 aboveground=getfieldvalue(options,'aboveground',1000); … … 150 197 domain=shpread([self.shppath '/' name '.' ext]); 151 198 152 if epsg==4326, 153 %convert boundary to lat,long: {{{ 154 155 for i=1:length(domain), 156 try, 157 [lat,long] = gdaltransform(domain(i).x,domain(i).y,sprintf('EPSG:%i',self.epsg),'EPSG:4326'); 158 catch me 159 disp(me.message()); 160 self.disp(); 161 end 162 domain(i).x=long; domain(i).y=lat; 163 end 164 165 for i=1:length(domain), 166 167 %make sure lat,long are what they are supposed to be: 168 %if any(domain(i).x>90 | domain(i).x<-90), 169 % long=domain(i).x; lat=domain(i).y; 170 %else 171 % long=domain(i).y; lat=domain(i).x; 172 %end 173 174 %project on x,y,z reference frame. 175 [x,y,z]=AboveGround(domain(i).x,domain(i).y,radius,aboveground); 176 [xt,yt,zt]=AboveGround(domain(i).x+offset,domain(i).y+offset,radius,300000); 177 hold on; 178 if length(x)==1, 179 p=plot3(x,y,z,'k*'); 180 set(p,'MarkerSize',markersize); 181 if strcmpi(label,'on'), 182 t=text(xt,yt,zt,self.shpfilename,'FontSize',fontsize); 183 end 184 else 185 p=plot3(x,y,z,'k-'); 186 mid=floor(length(xt)/2); 187 if strcmpi(label,'on'), 188 text(xt(mid),yt(mid),zt(mid),self.shpfilename,'FontSize',fontsize); 189 end 190 end 191 set(p,'Color',color); 192 set(p,'LineWidth',linewidth); 193 194 end 195 %}}} 196 else 197 %convert boundary to another reference frame: {{{ 198 199 for i=1:length(domain), 200 try, 201 [x,y] = gdaltransform(domain(i).x,domain(i).y,sprintf('EPSG:%i',self.epsg),sprintf('EPSG:%i',epsg)); 202 catch me 203 disp(me.message()); 204 self.disp(); 205 end 206 domain(i).x=x; domain(i).y=y; 207 end 208 209 for i=1:length(domain), 210 hold on; 211 if length(x)==1, 212 p=plot(x,y,'k*'); 213 set(p,'MarkerSize',markersize); 214 if strcmpi(label,'on'), 215 t=text(x,y,self.shpfilename,'FontSize',fontsize); 216 end 217 else 218 p=plot(x,y,'k-'); 219 if strcmpi(label,'on'), 220 text(sum(x)/length(x),sum(y)/length(y),self.shpfilename,'FontSize',fontsize); 221 end 222 end 223 set(p,'Color',color); 224 set(p,'LineWidth',linewidth); 225 end 226 %}}} 227 end 199 for i=1:length(domain), 200 try, 201 [lat,long] = gdaltransform(domain(i).x,domain(i).y,self.proj,'EPSG:4326'); 202 catch me 203 disp(me.message()); 204 self.disp(); 205 end 206 domain(i).x=long; domain(i).y=lat; 207 end 208 209 for i=1:length(domain), 210 211 %project on x,y,z reference frame. 212 [x,y,z]=AboveGround(domain(i).x,domain(i).y,radius,aboveground); 213 [xt,yt,zt]=AboveGround(domain(i).x+offset,domain(i).y+offset,radius,300000); 214 hold on; 215 if length(x)==1, 216 p=plot3(x,y,z,'k*'); 217 set(p,'MarkerSize',markersize); 218 if strcmpi(label,'on'), 219 t=text(xt,yt,zt,self.shpfilename,'FontSize',fontsize); 220 end 221 else 222 p=plot3(x,y,z,'k-'); 223 mid=floor(length(xt)/2); 224 if strcmpi(label,'on'), 225 text(xt(mid),yt(mid),zt(mid),self.shpfilename,'FontSize',fontsize); 226 end 227 end 228 set(p,'Color',color); 229 set(p,'LineWidth',linewidth); 230 231 end 232 228 233 end % }}} 229 234 end -
issm/trunk-jpl/src/m/classes/sealevelmodel.m
r24728 r24779 23 23 transitions = {}; 24 24 eltransitions = {}; 25 planet = ''; 25 26 %}}} 26 27 end … … 39 40 40 41 %recover the earth model: 41 slm.earth = getfieldvalue(options,'earth'); 42 slm.earth = getfieldvalue(options,'earth',0); 43 44 %set planet type: 45 slm.planet=getfieldvalue(options,'planet','earth'); 46 42 47 end 43 48 end … … 91 96 slm.range = {}; 92 97 slm.transitions = {}; 93 slm.eltransitions = {}; 98 slm.eltransitions = {}; 99 slm.planet = 'earth'; 94 100 end 95 101 %}}} … … 153 159 options=pairoptions(varargin{:}); 154 160 force=getfieldvalue(options,'force',0); 161 162 %initialize, to avoid issues of having more transitions than meshes. 163 self.transitions={}; self.eltransitions={}; 155 164 156 165 %for elements: … … 161 170 for i=1:length(self.icecaps), 162 171 mdi=self.icecaps{i}; 163 mdi=TwoDToThreeD(mdi );172 mdi=TwoDToThreeD(mdi,self.planet); 164 173 165 174 %for elements: … … 182 191 end 183 192 plotmodel(self.earth,'data',flags,'coastline','on'); 193 194 end % }}} 195 function checkbasinconsistency(self) % {{{ 196 for i=1:length(self.basins), 197 self.basins{i}.checkconsistency(); 198 end 184 199 185 200 end % }}} … … 300 315 models=self.icecaps; 301 316 for i=1:length(models), 302 models{i}=TwoDToThreeD(models{i} );317 models{i}=TwoDToThreeD(models{i},self.planet); 303 318 end 304 319 … … 350 365 function transfer(self,string) % {{{ 351 366 %Recover field size in one icecap: 352 eval(['n= length(self.icecaps{1}.' string ');']);367 eval(['n=size(self.icecaps{1}.' string ',1);']); 353 368 if n==self.icecaps{1}.mesh.numberofvertices, 354 369 eval(['self.earth.' string '=zeros(self.earth.mesh.numberofvertices,1);']); … … 356 371 eval(['self.earth.' string '(self.transitions{' num2str(i) '})=self.icecaps{' num2str(i) '}.' string ';']); 357 372 end 373 elseif n==(self.icecaps{1}.mesh.numberofvertices+1), 374 %dealing with a transient dataset. 375 %check that all timetags are similar between all icecaps: %{{{ 376 for i=1:length(self.icecaps), 377 eval(['capfieldi= self.icecaps{' num2str(i) '}.' string ';']); 378 for j=(i+1):length(self.icecaps), 379 eval(['capfieldj= self.icecaps{' num2str(j) '}.' string ';']); 380 if ~isequal(capfieldi(end,:),capfieldj(end,:)), 381 error(['Time stamps for ' string ' field is different between icecaps ' num2str(i) ' and ' num2str(j)]); 382 end 383 end 384 end 385 eval(['capfield1= self.icecaps{1}.' string ';']); 386 times=capfield1(end,:); 387 nsteps=length(times); 388 %}}} 389 %initialize: %{{{ 390 eval(['field=zeros(self.earth.mesh.numberofvertices+1,' num2str(nsteps) ');']); 391 eval(['field(end,:)=times;']); %transfer the times only, not the values 392 %}}} 393 %transfer all time fields: {{{ 394 for i=1:length(self.icecaps), 395 eval(['capfieldi= self.icecaps{' num2str(i) '}.' string ';']); 396 for j=1:nsteps, 397 eval(['field(self.transitions{' num2str(i) '},' num2str(j) ')=capfieldi(1:end-1,' num2str(j) ');']); %transfer only the values, not the time. 398 end 399 end 400 eval(['self.earth.' string '=field;']); %do not forget to plug the field variable into its final location 401 %}}} 358 402 elseif n==self.icecaps{1} .mesh.numberofelements, 359 403 eval(['self.earth.' string '=zeros(self.earth.mesh.numberofelements,1);']); -
issm/trunk-jpl/src/m/mesh/TwoDToThreeD.m
r24155 r24779 1 function md=TwoDToThreeD(md )1 function md=TwoDToThreeD(md,planet) 2 2 3 3 %reproject model into lat,long if necessary: 4 if md.mesh.epsg~=4326,5 [md.mesh.x,md.mesh.y]=gdaltransform(md.mesh.x,md.mesh.y, sprintf('EPSG:%i',md.mesh.epsg),sprintf('EPSG:4326'));4 if ~strcmpi(md.mesh.proj,epsg2proj(4326)), 5 [md.mesh.x,md.mesh.y]=gdaltransform(md.mesh.x,md.mesh.y,md.mesh.proj,'EPSG:4326'); 6 6 end 7 7 8 8 %Make a 3dsurface mesh out of this: 9 R= 6.371012*10^6;9 R=planetradius(planet); 10 10 11 11 %we assume x and y hold the long,lat values: … … 14 14 mask=md.mask; 15 15 16 %Assume spherical body: 16 17 x = R .* cosd(lat) .* cosd(long); 17 18 y = R .* cosd(lat) .* sind(long); -
issm/trunk-jpl/src/m/mesh/meshintersect3d.m
r24766 r24779 66 66 end 67 67 68 if(~isempty(find(indices==0))) error('issue with transition vector having one empty slot'); end; 69 68 70 69 71 % if length(s)>1,
Note:
See TracChangeset
for help on using the changeset viewer.