Plot grided latitude and longitude as pixels on map

15 visualizaciones (últimos 30 días)
BN
BN el 16 de Feb. de 2020
Editada: Giuseppe Inghilterra el 16 de Feb. de 2020
I want to plot gridded latitude and longitude as pixels on the map, Latitude is 1 x 32 and longitude is 1 x 40 I don't know how to this I tried geoshow but it said latitude and longitude must have the same size.
Error using checklatlon (line 25)
Function GEOSHOW expected its first and second input arguments,
LAT and LON, to match in size.
Error in geovecshow (line 37)
checklatlon(lat, lon, 'GEOSHOW', 'LAT', 'LON', 1, 2);
Error in geoshow (line 278)
h = showFcn(varargin{:});
I attache latitude and longitude. latitude and longitude are taken from the NetCDF file for gridded precipitation data, but I just want to plot its pixels and I don't need precipitation data.
I want to plot them on this map:
Code to generate map:
% Produce the map
borders('Iran Islamic Republic of') % borders is a function from Matlab file exchange by Chad A Greene (https://www.mathworks.com/matlabcentral/fileexchange/50390-borders)
grid on
axis equal % I added this, important to maintain aspect ratio (@AD)
xlabel('Longitude')
ylabel('Latitude')
xtickangle(90)
I want to plot the pixels like this: (ignore the color bar and colors I just want pixels)
Thank you

Respuesta aceptada

Giuseppe Inghilterra
Giuseppe Inghilterra el 16 de Feb. de 2020
I obtain this result:
by running the following code:
load lati.mat
load loni.mat
[LONG, LAT] = meshgrid(loni,lati);
Z = rand(length(lati),length(loni));
figure
surface(LONG, LAT, Z)
colorbar
xlabel('Longitude')
ylabel('Latitude')
xticks(loni)
yticks(lati)
xtickangle(90)
grid on
ax = gca;
ax.XAxis.FontSize = 7;
ax.YAxis.FontSize = 7;
In my example I generate ramdomly Z matrix, instead you should have a matrix with data in function of latitude and longitude coordinates. From your plot I see that some "pixels" are blank. This means that you can fill Z matrix with NaN values, in this way you obtain easily blank pixels.
  2 comentarios
BN
BN el 16 de Feb. de 2020
Dear Giuseppe Inghilterra First of all I want to thank you.
So according to your answer, it is impossible to have just grids without any data. So this is a good I dead to define random data at least I can see pixels.
here is the figure using your method:
I achive it using this code:
borders('Iran Islamic Republic of') % from FEX
%grid on
axis equal % I added this, important to maintain aspect ratio
xlabel('Longitude')
ylabel('Latitude')
xtickangle(90)
hold on
%% plot gridded on map
[LONG, LAT] = meshgrid(loni,lati);
Z = rand(length(lati),length(loni));
figure
surface(LONG, LAT, Z)
colorbar
xlabel('Longitude')
ylabel('Latitude')
xticks(loni)
yticks(lati)
xtickangle(90)
grid on
ax = gca;
ax.XAxis.FontSize = 7;
ax.YAxis.FontSize = 7;
One main challenge is do you know how I can bring the boundary of the country on? or delete outside the boundary pixels?
Also, it would be awesome if it is possible to grids haven't any colors just be white. thank you I waiting for your reply.
Giuseppe Inghilterra
Giuseppe Inghilterra el 16 de Feb. de 2020
Editada: Giuseppe Inghilterra el 16 de Feb. de 2020
See the following code:
  1. I define a circumference in x,y coordinates;
  2. then I evaluate if LONG,LAT coordinates are inside the defined circumference through "inpolygon" matlab function and I set to zero these entries of Z matrix;
  3. then I take the current colormap cmap and redefine the first line with [1 1 1]. In this way I assign color white to "zero" value and then I update colormap;
load lati.mat
load loni.mat
t = 0:pi/10:2*pi; %(1)
x = 55 + 5*cos(t);
y = 30 + 5*sin(t);
[LONG, LAT] = meshgrid(loni,lati);
Z = rand(length(lati),length(loni));
Z(inpolygon(LONG,LAT,x,y)) = 0; %(2)
figure
surface(LONG, LAT, Z)
cmap = colormap; %(3)
cmap(1,:) = [1 1 1];
colormap(cmap)
colorbar
xlabel('Longitude')
ylabel('Latitude')
xticks(loni)
yticks(lati)
xtickangle(90)
grid on
ax = gca;
ax.XAxis.FontSize = 7;
ax.YAxis.FontSize = 7;
I obtain the following resul:
Now, instead of circumference, if you have (x,y) coordinates of your curve, you can obtain the same result.
If you assign to NaN values through inpolygon function Z matrix entries, you don't need to define a custom colormap.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Orange en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by