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 CenterFile Exchange에서 Geographic Plots에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by