is it possible to plot hexagonal grid in geoplot?

13 次查看(过去 30 天)
I want to plot hexagonal grid in geoplot. but i don't know how to do.
Please Let me know.
Thanks.
  2 个评论
KSSV
KSSV 2022-8-16
Any demo picture to show us? It woul dbe better to attach your data nd show us your expectations. If not geoplot, straight away it might be possible to draw.
Sierra
Sierra 2022-8-16
I attatched the circle coordinates and what i expected to do.
Thanks.

请先登录,再进行评论。

回答(2 个)

sai charan sampara
sai charan sampara 2023-9-29
Hello Sierra,
I understand that you are trying to plot hexagonal grids on top of your “geoplot”.
The following files from the file exchange might be useful to you. These functions plot hexagonal grids and can be added on top of your “geoplot” by using “hold” or any other method:
Thanks,
Charan.

Avni Agrawal
Avni Agrawal 2023-11-17
Hi,
I understand that you want to plot the hexagonal grid which are contained within the circle. Here is an example how you can do this in MATLAB:
% Given lat and lon for circumference of the circle
load circleforgrid.mat
lat = X; % replace with your data
lon = Y; % replace with your data
% Calculate the center and radius of the circle
circle_center = [mean(lat), mean(lon)];
circle_radius = max(sqrt((lat - circle_center(1)).^2 + (lon - circle_center(2)).^2));
% Define the size of the hexagons
hex_radius = circle_radius / 15; % Adjust this value as needed
% Define the offsets for the hexagonal grid
dy = 2 * hex_radius;
dx = sqrt(4) * hex_radius;
% Calculate the number of hexagons in x and y direction
nx = floor(circle_radius / dx);
ny = floor(circle_radius / dy);
% Create a figure
figure
geoplot(X, Y)
hold on
% Loop over the hexagonal grid
for ix = -nx:nx
for iy = -ny:ny
% Calculate the center of the hexagon
x_offset = 0;
if mod(iy,2) == 0
x_offset = dx/2;
end
center = circle_center + [iy*dy, (ix+x_offset)*dx];
% Calculate the vertices of the hexagon
theta = (0:5) * 2*pi/6; % angles at the vertices
lat = center(1) + hex_radius * cos(theta);
lon = center(2) + hex_radius * sin(theta);
% Skip if any vertex is outside the circle
if any(sqrt((lat - circle_center(1)).^2 + (lon - circle_center(2)).^2) > circle_radius)
continue
end
% Close the hexagon by repeating the first vertex at the end
lat = [lat lat(1)];
lon = [lon lon(1)];
% Plot the hexagon
geoplot(lat, lon, 'b-')
end
end
geobasemap('landcover') % set the basemap
hold off
Here is the explanation for the above code:
1. Data Setup: The code begins by defining the latitude and longitude for the circle's circumference and calculating its center and radius. The size of the hexagons is also defined.
2. Grid Calculation: The code calculates the offsets for a hexagonal grid and the number of hexagons in the x and y directions.
3. Hexagon Generation: Two nested loops iterate over the grid positions. For each position, the code calculates the center and vertices of a hexagon. If any vertex is outside the circle, that hexagon is skipped.
4. Plotting: Finally, each hexagon that fits entirely within the circle is plotted on a geographic plot with a 'landcover' basemap.
I hope this helps.

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by