Create a polygon based on the location of points

67 views (last 30 days)
Jorge Luis
Jorge Luis on 15 Dec 2024 at 19:25
Answered: Naga on 23 Dec 2024 at 3:36
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 Comments
jinjin lee
jinjin lee on 16 Dec 2024 at 5:47
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 on 17 Dec 2024 at 16:41
Thank you :). Much appreciated. I had to follow a different approach though.

Sign in to comment.

Accepted Answer

Naga
Naga on 23 Dec 2024 at 3:36
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

More Answers (0)

Categories

Find more on Geographic Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!