-
Notifications
You must be signed in to change notification settings - Fork 0
/
flightpaths_geoplot_person.m
152 lines (114 loc) · 5 KB
/
flightpaths_geoplot_person.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
% Specify the base folder where your GPX files are located
baseFolder = 'C:\Users\nfischer\Documents\MATLAB\Flightpaths';
% Specify the subfolder name
subfolder = 'gpx';
% Construct the full path to the subfolder
subfolderPath = fullfile(baseFolder, subfolder);
% Get the flight numbers from text file
% The Flight Numbers in the Text file MUST have three digits, but it
% doesn't matter if it is something like F345 or FLT345.
inputFile = 'Steve.txt';
% Extract flight numbers
flightNumbers = extractFlightNumbers(inputFile);
disp(flightNumbers);
% List the GPX files in the subfolder
gpxFiles = dir(subfolderPath);
gpxFiles = gpxFiles(~[gpxFiles.isdir]); % Remove directories from the list
% Filter files based on the flightNumbers
selectedFiles = [];
pattern = '(?<!\d)(\d{3})(?!\d)';
for i = 1:length(gpxFiles)
fileName = gpxFiles(i).name;
% Check if the file name contains any flight number
if any(ismember(flightNumbers, str2double(regexp(fileName, pattern, 'match'))))
selectedFiles = [selectedFiles; gpxFiles(i)];
end
end
disp(selectedFiles)
% Assuming selectedFiles is a struct array with a field 'name'
% flightNumbers is an array with three-digit numbers
% Extract the three-digit numbers from the 'name' field of selectedFiles
extractedNumbersCell = cellfun(@(x) str2double(regexp(x, '\d+', 'match')), {selectedFiles.name}, 'UniformOutput', false);
% Concatenate the non-empty arrays into a single array
extractedNumbers = cell2mat(extractedNumbersCell(~cellfun(@isempty, extractedNumbersCell)));
% Identify flightNumbers without a corresponding entry in extractedNumbers
missingNumbers = setdiff(flightNumbers, extractedNumbers);
% Define the colormap
cmap = hot;
% Get rid of some rows to eliminate dark colors in front of dark ocean
cmap_mod = cmap(55:256, :);
% nice background basemap
basemapUSGS1 = "basemapUSGS";
url = "https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}";
addCustomBasemap(basemapUSGS1,url)
basemap1 = "usgsimagery";
mbtilesFilename1 = "usgsimagery.mbtiles";
addCustomBasemap(basemap1,mbtilesFilename1)
% Create a figure for plotting
figure;
% Plot GPX paths with random colors, handling lines that cross the date line
for i = 1:length(selectedFiles)
gpxFilePath = fullfile(subfolderPath, selectedFiles(i).name);
gpxData = gpxread(gpxFilePath);
% Filter GPX data based on the value in the array
if ~isempty(gpxData)
% Generate a random index for the flight color
randomIndex = randperm(size(cmap_mod, 1), 1);
% Use the randomly selected color for the flight
flightColor = cmap_mod(randomIndex, :);
disp(flightColor)
fprintf('Flight %d of %d\n', i, length(selectedFiles));
% Initialize arrays to store segment data
latSegments = {};
lonSegments = {};
% Initialize the first segment
latSegments{1} = [];
lonSegments{1} = [];
for j = 2:length(gpxData.Longitude)
% Check if the difference in longitude crosses the date line
if abs(gpxData.Longitude(j) - gpxData.Longitude(j - 1)) > 180
% Start a new segment if the path crosses the date line
latSegments{end + 1} = [];
lonSegments{end + 1} = [];
end
% Add data to the current segment
latSegments{end} = [latSegments{end}, gpxData.Latitude(j)];
lonSegments{end} = [lonSegments{end}, gpxData.Longitude(j)];
end
% Plot each segment using geoplot with a randomly selected color
for j = 1:length(latSegments)
% get rid of dateline issue
if lonSegments{j} > 50
lonSegments{j} = lonSegments{j} -360;
end
% % Adjust the longitude limits to center the plot at 150°
% % lonLimits = [centerLongitude - 180, centerLongitude + 180];
% lonLimits = [-150, 0];
% latLimits = [-75, 75];
% geolimits([min(latSegments{j}) max(latSegments{j})], lonLimits);
% Plot the segment with the random color
geoplot(latSegments{j}, lonSegments{j}, 'Color', flightColor, 'LineWidth', 1);
hold on;
end
end
end
% Set the basemap to the desired type (e.g., 'satellite')
geobasemap(basemapUSGS1);
% Adjust the longitude limits to center the plot at 150°
% lonLimits = [centerLongitude - 180, centerLongitude + 180];
lonLimits = [-150, 0];
latLimits = [-75, 75];
geolimits(latLimits, lonLimits);
% Customize map appearance as needed
% Extract the name of the text file without the extension
[~, fileName, ~] = fileparts(inputFile);
title(['Flights for ' fileName]);
%title('FIFI-LS Flights');
% Save the figure as an image
% filename = 'output_map.png'; % Change the filename as needed
% saveas(gcf, filename, 'png');
% Close the figure
% close(gcf);
% Display flight numbers for which no struct name was found
disp('Flight numbers for which no flight data was found:');
disp(missingNumbers);