is it possible to plot hexagonal grid in geoplot?

13 visualizaciones (últimos 30 días)
Sierra
Sierra el 15 de Ag. de 2022
Comentada: Dyuman Joshi el 17 de Nov. de 2023
I want to plot hexagonal grid in geoplot. but i don't know how to do.
Please Let me know.
Thanks.
  2 comentarios
KSSV
KSSV el 16 de Ag. de 2022
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 el 16 de Ag. de 2022
I attatched the circle coordinates and what i expected to do.
Thanks.

Iniciar sesión para comentar.

Respuestas (2)

sai charan sampara
sai charan sampara el 29 de Sept. de 2023
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 el 17 de Nov. de 2023
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.
  1 comentario
Dyuman Joshi
Dyuman Joshi el 17 de Nov. de 2023
The geoplot is quite blurred compared to what OP has given as a reference.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by