Geoshow and grid points with polygonal shape

12 次查看(过去 30 天)
Hi everyone,
I'm trying to represent on a geo grid (lat and lon) the value of my variable for each grid point and do a geoshow, but the grid points I'm using are generated within a polygonal shape.
If I use meshgrid using as boundaries min and max latitude and min and max longitude, the shape is not correctly followed when plotting. How can I generate the meshgrid using points that are not enclosed in a square or a rectangle? Or do I need to use another procedure?
Thank you very much for the answers!
Daniele

回答(1 个)

William Rose
William Rose 2024-3-28
@Daniele,
I recommend using meshgrid() to make the 2D mesh that covers and extends beyond the plygon of interest, the use reshape() to turn the grids into vectors, and inpolygon() to exclude points that fall outside the polygon of interest.
Example: Create a set of points with 0.1 degree spacing inside the hexagon with corners at [-75,41; -74,40; -74,39; -75,38; -76,39; -76,40]
[X,Y]=meshgrid([-76.2:0.1:-73.8], [37.8:0.1:41.2]);
fprintf('Size of X: %d x %d.\n',size(X))
Size of X: 35 x 25.
X=reshape(X,[],1); % reshape X to have 1 column
Y=reshape(Y,[],1); % reshape Y to have 1 column
fprintf('Size of X: %d x %d.\n',size(X))
Size of X: 875 x 1.
Define the polygon:
xv=[-75,-74,-74,-75,-76,-76]; % x vertices of polygon
yv=[41,40,39,38,39,40]; % y vertices of polygon
Find who is in and who is out:
in=inpolygon(X,Y,xv,yv);
Xin=X(in); Yin=Y(in); % points inside and on the polygon
Xout=X(~in); Yout=Y(~in); % points outside the polygon
Plot the in and out points in green and red
plot(Xin,Yin,'go');
hold on; axis equal
plot(Xout,Yout,'rx');
OK
  1 个评论
William Rose
William Rose 2024-3-28
@Daniele Musacchio, although my example above does not use geoshow, you can use my approach to generate a set of points. Then you can use geoshow to display the points, or compute a value at each point, and use geoshow() to display amap of hte value at the points in and on the polygon.

请先登录,再进行评论。

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by