1 | function plot_googlemaps(md,data,options,plotlines,plotcols,i)
|
---|
2 | %PLOT_GOOGLEMAPS - superimpose Google maps to a given field
|
---|
3 | %
|
---|
4 | % Usage:
|
---|
5 | % plot_googlemaps(md,data,options,plotlines,plotcols,i)
|
---|
6 | %
|
---|
7 | % See also: PLOTMODEL
|
---|
8 |
|
---|
9 | %process mesh and data
|
---|
10 | [x y z elements is2d isplanet]=processmesh(md,[],options);
|
---|
11 | [data datatype]=processdata(md,data,options);
|
---|
12 |
|
---|
13 | %check is2d
|
---|
14 | if ~is2d,
|
---|
15 | error('buildgridded error message: gridded not supported for 3d meshes, project on a layer');
|
---|
16 | end
|
---|
17 |
|
---|
18 | if ~any(isnan(md.radaroverlay.x(:))) & ~any(isnan(md.radaroverlay.y(:))) & ~any(isnan(md.radaroverlay.pwr(:))) ...
|
---|
19 | & size(md.radaroverlay.pwr,3)==3 & size(md.radaroverlay.x,2)==size(md.radaroverlay.pwr,2),
|
---|
20 | disp('plot_googlemaps info: the RGB image held by the model is being used');
|
---|
21 | else
|
---|
22 | disp('Extracting image from Google maps...');
|
---|
23 |
|
---|
24 | %Get xlim and ylim (used to extract radar image)
|
---|
25 | xlim=getfieldvalue(options,'xlim',[min(x) max(x)])/getfieldvalue(options,'unit',1);
|
---|
26 | ylim=getfieldvalue(options,'ylim',[min(y) max(y)])/getfieldvalue(options,'unit',1);
|
---|
27 | if md.mesh.epsg==3413, %UPS Greenland
|
---|
28 | [latlist lonlist]= xy2ll(...
|
---|
29 | [linspace(xlim(1),xlim(2),100) linspace(xlim(2),xlim(2),100) linspace(xlim(2),xlim(1),100) linspace(xlim(1),xlim(1),100)],...
|
---|
30 | [linspace(ylim(1),ylim(1),100) linspace(ylim(1),ylim(2),100) linspace(ylim(2),ylim(2),100) linspace(ylim(2),ylim(1),100)],...
|
---|
31 | +1,45,70);
|
---|
32 | elseif md.mesh.epsg==3031, %UPS Antarctica
|
---|
33 | [latlist lonlist]= xy2ll(...
|
---|
34 | [linspace(xlim(1),xlim(2),100) linspace(xlim(2),xlim(2),100) linspace(xlim(2),xlim(1),100) linspace(xlim(1),xlim(1),100)],...
|
---|
35 | [linspace(ylim(1),ylim(1),100) linspace(ylim(1),ylim(2),100) linspace(ylim(2),ylim(2),100) linspace(ylim(2),ylim(1),100)],...
|
---|
36 | -1,0,71);
|
---|
37 | elseif md.mesh.epsg==26906, %UTM 6V Columbia Glacier Alaska
|
---|
38 | [latlist lonlist]= utm2ll(...
|
---|
39 | [linspace(xlim(1),xlim(2),100) linspace(xlim(2),xlim(2),100) linspace(xlim(2),xlim(1),100) linspace(xlim(1),xlim(1),100)],...
|
---|
40 | [linspace(ylim(1),ylim(1),100) linspace(ylim(1),ylim(2),100) linspace(ylim(2),ylim(2),100) linspace(ylim(2),ylim(1),100)],...
|
---|
41 | 6);
|
---|
42 | elseif numel(md.mesh.lat)==numel(md.mesh.x),
|
---|
43 | latlist = md.mesh.lat; %That might work?
|
---|
44 | lonlist = md.mesh.long;
|
---|
45 | else
|
---|
46 | error('EPSG code not supported yet, and no lat long found in md.mesh');
|
---|
47 | end
|
---|
48 |
|
---|
49 | %Image corners in lat/long
|
---|
50 | ullat = max(latlist); ullon = min(lonlist);
|
---|
51 | lrlat = min(latlist); lrlon = max(lonlist);
|
---|
52 |
|
---|
53 | md=googlemaps(md,ullat,ullon,lrlat,lrlon,options);
|
---|
54 | end
|
---|
55 |
|
---|
56 | %Process image from model
|
---|
57 | final = double(md.radaroverlay.pwr)/double(max(md.radaroverlay.pwr(:))); %rescale between 0 and 1
|
---|
58 |
|
---|
59 | %Get some options
|
---|
60 | transparency = getfieldvalue(options,'transparency',.3);
|
---|
61 |
|
---|
62 | %Prepare grid
|
---|
63 | if size(md.radaroverlay.x,1)==1 | size(md.radaroverlay.x,2)==1,
|
---|
64 | x_m = md.radaroverlay.x;
|
---|
65 | y_m = md.radaroverlay.y;
|
---|
66 | data_grid=InterpFromMeshToGrid(elements,x/getfieldvalue(options,'unit',1),y/getfieldvalue(options,'unit',1),data,x_m,y_m,NaN);
|
---|
67 | else
|
---|
68 | X = md.radaroverlay.x;
|
---|
69 | Y = md.radaroverlay.y;
|
---|
70 | data_grid=InterpFromMeshToMesh2d(md.mesh.elements,md.mesh.x,md.mesh.y,data,X(:),Y(:),'default',NaN); data_grid=reshape(data_grid,size(X));
|
---|
71 | x_m=X(1,:); y_m=Y(:,1);
|
---|
72 | end
|
---|
73 | data_nan=isnan(data_grid);
|
---|
74 | if exist(options,'caxis'),
|
---|
75 | caxis_opt=getfieldvalue(options,'caxis');
|
---|
76 | data_grid(find(data_grid<caxis_opt(1)))=caxis_opt(1);
|
---|
77 | data_grid(find(data_grid>caxis_opt(2)))=caxis_opt(2);
|
---|
78 | data_min=caxis_opt(1);
|
---|
79 | data_max=caxis_opt(2);
|
---|
80 | else
|
---|
81 | data_min=min(data_grid(:));
|
---|
82 | data_max=max(data_grid(:));
|
---|
83 | end
|
---|
84 | colorm = getcolormap(options);
|
---|
85 | image_rgb = ind2rgb(uint16((data_grid - data_min)*(length(colorm)/(data_max-data_min))),colorm);
|
---|
86 |
|
---|
87 | if exist(options,'shaded'),
|
---|
88 | a = -45;
|
---|
89 | scut = 0.2;
|
---|
90 | c = 1;
|
---|
91 | % computes lighting from elevation gradient
|
---|
92 | [fx,fy] = gradient(data_grid,x_m,y_m);
|
---|
93 | fxy = -fx*sind(a) - fy*cosd(a);
|
---|
94 | clear fx fy % free some memory...
|
---|
95 | fxy(isnan(fxy)) = 0;
|
---|
96 |
|
---|
97 | % computes maximum absolute gradient (median-style), normalizes, saturates and duplicates in 3-D matrix
|
---|
98 | r = repmat(max(min(fxy/nmedian(abs(fxy),1 - scut/100),1),-1),[1,1,3]);
|
---|
99 |
|
---|
100 | % applies contrast using exponent
|
---|
101 | rp = (1 - abs(r)).^c;
|
---|
102 | image_rgb = image_rgb.*rp;
|
---|
103 |
|
---|
104 | % lighter for positive gradient
|
---|
105 | k = find(r > 0);
|
---|
106 | image_rgb(k) = image_rgb(k) + (1 - rp(k));
|
---|
107 | end
|
---|
108 |
|
---|
109 | alpha=ones(size(data_grid));
|
---|
110 | alpha(find(~data_nan))=transparency;
|
---|
111 | alpha=repmat(alpha,[1 1 3]);
|
---|
112 |
|
---|
113 | final=alpha.*final+(1-alpha).*image_rgb;
|
---|
114 |
|
---|
115 | %Select plot area
|
---|
116 | subplotmodel(plotlines,plotcols,i,options);
|
---|
117 |
|
---|
118 | h=imagesc(x_m*getfieldvalue(options,'unit',1),y_m*getfieldvalue(options,'unit',1),final);
|
---|
119 |
|
---|
120 | %last step: mesh gridded?
|
---|
121 | if exist(options,'edgecolor'),
|
---|
122 | A=elements(:,1); B=elements(:,2); C=elements(:,3);
|
---|
123 | patch('Faces',[A B C],'Vertices', [x y z],'FaceVertexCData',data_grid(1)*ones(size(x)),'FaceColor','none','EdgeColor',getfieldvalue(options,'edgecolor'));
|
---|
124 | end
|
---|
125 |
|
---|
126 | %Apply options
|
---|
127 | if ~isnan(data_min),
|
---|
128 | options=changefieldvalue(options,'caxis',[data_min data_max]); % force caxis so that the colorbar is ready
|
---|
129 | end
|
---|
130 | options=addfielddefault(options,'axis','xy equal off'); % default axis
|
---|
131 | applyoptions(md,data,options);
|
---|
132 | end
|
---|