Create a polygon based on the location of points

7 ビュー (過去 30 日間)
Jorge Luis
Jorge Luis 2024 年 12 月 15 日
回答済み: Naga 2024 年 12 月 23 日
Hi, I would like to create a polygon based on the location of all the volcanoes contained inside the boundaries of South America. This polygon will be created automatically considering a radius of 15km for each volcano and then extract the envelop of the georeferenced polygon (that contains all the surrounded volcanos) like the highlighted are in the following image:
The code to obtain the plot of the South America continent and the location of volcanoes is the following: load volcanic.mat
% loading the volcanic data which is attached to this message
% Step 1: Create a map of South America
figure;
ax = worldmap('South America'); % Create a map focused on South America
setm(ax, 'FFaceColor', [0.9 0.9 0.9]); % Set background color
title('Volcano Locations in South America');
% Step 2: Add a basemap
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(ax, land, 'FaceColor', [0.5 0.7 0.5]); % Display land areas
% Step 3: Define volcano locations (example coordinates)
volcanoLat = volcanic.lat; % Latitudes of volcanoes volcano
Lon = volcanic.lon; % Longitudes of volcanoes
% Step 4: Plot volcanoes
geoshow(volcanoLat, volcanoLon, 'DisplayType', 'point', ...
'Marker', 'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r', ...
'MarkerSize', 6);
%textm(volcanoLat, volcanoLon, {'Volcano1', 'Volcano2', 'Volcano3', 'Volcano4', 'Volcano5'}, ...
% 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
% Optional: Add grid and refine details
gridm on; mlabel on; % Show latitude labels
plabel on; % Show longitude labels
I would appreciate the help.
  2 件のコメント
jinjin lee
jinjin lee 2024 年 12 月 16 日
figure;
ax = worldmap('South America'); % Create a map focused on South America
setm(ax, 'FFaceColor', [0.9 0.9 0.9]); % Set background color
title('Volcano Locations in South America');
% Step 2: Add a basemap
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(ax, land, 'FaceColor', [0.5 0.7 0.5]); % Display land areas
% Step 3: Define volcano locations (example coordinates)
volcanoLat = volcanic.lat; % Latitudes of volcanoes
volcanoLon = volcanic.lon; % Longitudes of volcanoes
% Step 4: Plot volcanoes
geoshow(volcanoLat, volcanoLon, 'DisplayType', 'point', ...
'Marker', 'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r', ...
'MarkerSize', 6);
bufwidth = 0.1;
[latb, lonb] = bufferm(volcanoLat, volcanoLon, bufwidth);
geoshow(latb, lonb, 'DisplayType', 'polygon', ...
'FaceColor', 'yellow')
Jorge Luis
Jorge Luis 2024 年 12 月 17 日
Thank you :). Much appreciated. I had to follow a different approach though.

サインインしてコメントする。

採用された回答

Naga
Naga 2024 年 12 月 23 日
Hi Jorge,
The 'convhull' function calculates the smallest convex polygon that can enclose all given points (volcanoes). The convex hull is plotted as a polygon on the map, providing a visual envelope around the volcanoes.
% Load volcanic data
load volcanic.mat
% Create a map of South America
figure;
ax = worldmap('South America');
setm(ax, 'FFaceColor', [0.9 0.9 0.9]);
title('Volcano Locations and Convex Hull in South America');
% Add basemap
land = shaperead('landareas', 'UseGeoCoords', true);
geoshow(ax, land, 'FaceColor', [0.5 0.7 0.5]);
% Define and plot volcano locations
volcanoLat = volcanic.lat;
volcanoLon = volcanic.lon;
geoshow(volcanoLat, volcanoLon, 'DisplayType', 'point', ...
'Marker', 'o', 'MarkerEdgeColor', 'r', 'MarkerFaceColor', 'r', ...
'MarkerSize', 6);
% Compute and plot the convex hull
k = convhull(volcanoLon, volcanoLat);
geoshow(volcanoLat(k), volcanoLon(k), 'DisplayType', 'polygon', ...
'FaceColor', 'cyan', 'FaceAlpha', 0.3, 'EdgeColor', 'b', 'LineWidth', 1.5);
% Add grid and labels
gridm on; mlabel on; plabel on;
This method provides a clean and straightforward way to visualize the area encompassing all volcanoes without using buffer zones. It highlights the outermost boundary formed by the volcano locations themselves.
For more information on 'convhull' refer to below documentation: https://www.mathworks.com/help/releases/R2023a/matlab/ref/convhull.html

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGeographic Plots についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by