how to plot multiple data sets on a single geoplot?

17 views (last 30 days)
I have lat and long points of multiple vehicles running a similar path, I want to run a function that plots all of these individually using geoplot. Right now im catting the lat and long points together to create a single long list of points and plotting that, the result is ok but what I really want is to plot each of the data sets individually and have them be a different color. How do I plot these individually without using concat? Below is the part of my function that just deals with plotting this map. Thanks!
P = uigetdir('C:\');
S = dir(fullfile(P,'*.csv'));
S = natsortfiles(S);
N = numel(S);
C = cell(N,1);
C1 = cell(N,1);
file_info = dir(fullfile(P, '*.csv'));
full_file_names = fullfile(P, {file_info.name});
n_files = numel(file_info);
all_data = cell(1,n_files);
for ii = 1:n_files
all_data{ii} = readtable(full_file_names{ii});
end
all_data{:}
I = cat(1, all_data{:});
finallat = I(:,6);
finallong = I(:,7);
finallat1 = finallat ./10000000;
finallong1 = finallong ./10000000;
Lat2 = table2array(finallat1);
Long2 = table2array(finallong1);
LatLong = [Lat2, Long2];
[M2, ~, ~] = rmoutliers(LatLong, 1);
Lat1 = M2(:,1);
Long1 = M2(:,2);
TrackLat = [32.62709772, 32.62016989, 32.6202918700000, 32.6272036500000, 32.6273095900000, 32.6204138600000, 32.6205358400000, 32.6274155200000, ...
32.6275214500000, 32.6206578200000, 32.6207798100000, 32.6276273800000, 32.6277333100000, 32.6209017900000, 32.6210237700000, 32.6278392400000, ...
32.6279451700000, 32.6211457500000, 32.6212677300000, 32.6280510900000, 32.6281570200000, 32.6213897100000, 32.6215116900000, 32.6282629500000, ...
32.6283688700000, 32.6216336700000, 32.6217556500000, 32.6284748000000, 32.6285807200000, 32.6218776200000, 32.6219996000000, 32.6286866500000];
TrackLong = [-117.156731500000, -117.152719800000, -117.152434100000, -117.156436400000, -117.156141400000, -117.152148300000, -117.151862600000, ...
-117.155846300000, -117.155551200000, -117.151576800000, -117.151291000000, -117.155256100000, -117.154961100000, -117.151005300000, -117.150719500000, ...
-117.154666000000, -117.154370900000, -117.150433800000, -117.150148000000, -117.154075800000, -117.153780800000, -117.149862200000, -117.149576500000, ...
-117.153485700000, -117.153190600000, -117.149290700000, -117.149005000000, -117.152895500000, -117.152600400000, -117.148719200000, -117.148433400000, -117.152305300000];
land = readgeotable("tl_2019_us_coastline.shp");
gx = geoaxes;
geoplot(gx,land)
geoplot(gx,Lat1, Long1, "LineWidth", 1);
hold on
geoplot(gx, TrackLat, TrackLong)
gx.TitleHorizontalAlignment = "center";
gx.Title.String = "All Mapped Surveys";
gx.Title.FontWeight = 'normal';
gx.Title.FontSize = 14;
legend ('Vehicle Position', 'Mission Plan')

Accepted Answer

Arjun
Arjun on 9 Dec 2024
Edited: Arjun on 9 Dec 2024
I understand that you're looking to plot the latitude and longitude points for each vehicle individually using 'geoplot', and you want each path to be displayed in a different color.
To plot each vehicle's path individually with distinct colors, you will want to make a few tweaks to your code. First, use a loop to go through each CSV file that contains the path data for the vehicles. Inside the loop, assign a unique color to each path by using a colormap like 'lines', which provides a variety of distinct colors. Apply these colors using the Color property when plotting each path. Also, set a 'DisplayName' for each plot, such as "Vehicle 1," "Vehicle 2," etc., so that each path is labeled in the legend. This approach will help you easily distinguish between the different paths on your plot.
Kindly refer to the code below for better understanding:
P = uigetdir('C:\');
S = dir(fullfile(P, '*.csv'));
S = natsortfiles(S);
N = numel(S);
file_info = dir(fullfile(P, '*.csv'));
full_file_names = fullfile(P, {file_info.name});
n_files = numel(file_info);
land = readgeotable("tl_2019_us_coastline.shp");
gx = geoaxes;
geoplot(gx, land)
hold on
% Define a color map for different vehicle paths
colors = lines(n_files);
% Loop through each file and plot individually
for ii = 1:n_files
% Read table from the current CSV file
data = readtable(full_file_names{ii});
% Extract latitude and longitude columns
finallat = data{:, 6};
finallong = data{:, 7};
finallat1 = finallat ./ 10000000;
finallong1 = finallong ./ 10000000;
LatLong = [finallat1, finallong1];
[M2, ~, ~] = rmoutliers(LatLong, 1);
Lat1 = M2(:, 1);
Long1 = M2(:, 2);
% Plot the path for the current vehicle with a unique color
geoplot(gx, Lat1, Long1, 'LineWidth', 1, 'Color', colors(ii, :), 'DisplayName', ['Vehicle ' num2str(ii)]);
end
TrackLat = [32.62709772, 32.62016989, 32.6202918700000, 32.6272036500000, 32.6273095900000, 32.6204138600000, 32.6205358400000, 32.6274155200000, ...
32.6275214500000, 32.6206578200000, 32.6207798100000, 32.6276273800000, 32.6277333100000, 32.6209017900000, 32.6210237700000, 32.6278392400000, ...
32.6279451700000, 32.6211457500000, 32.6212677300000, 32.6280510900000, 32.6281570200000, 32.6213897100000, 32.6215116900000, 32.6282629500000, ...
32.6283688700000, 32.6216336700000, 32.6217556500000, 32.6284748000000, 32.6285807200000, 32.6218776200000, 32.6219996000000, 32.6286866500000];
TrackLong = [-117.156731500000, -117.152719800000, -117.152434100000, -117.156436400000, -117.156141400000, -117.152148300000, -117.151862600000, ...
-117.155846300000, -117.155551200000, -117.151576800000, -117.151291000000, -117.155256100000, -117.154961100000, -117.151005300000, -117.150719500000, ...
-117.154666000000, -117.154370900000, -117.150433800000, -117.150148000000, -117.154075800000, -117.153780800000, -117.149862200000, -117.149576500000, ...
-117.153485700000, -117.153190600000, -117.149290700000, -117.149005000000, -117.152895500000, -117.152600400000, -117.148719200000, -117.148433400000, -117.152305300000];
geoplot(gx, TrackLat, TrackLong, 'k', 'LineWidth', 1.5, 'DisplayName', 'Mission Plan');
% Set the title and legend for the plot
gx.TitleHorizontalAlignment = "center";
gx.Title.String = "All Mapped Surveys";
gx.Title.FontWeight = 'normal';
gx.Title.FontSize = 14;
% Add a legend to the plot
legend('show', 'Location', 'best');
hold off
Kindly refer to the documentation of 'lines' and 'geoplot' for better understanding:
I hope this will help!

More Answers (0)

Categories

Find more on Aerodynamics in Help Center and File Exchange

Tags

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!