Clear Filters
Clear Filters

How to load multiple gpx or xlsx/.csv files and run them individually on openstreetmap?

4 views (last 30 days)
I have two .gpx or .xlsx/.csv files attached herewith and I want to load them and run them individually on openstreetmap. I would also like to show blinking at their initial and final destination. I tried out with the following codes:
name = 'openstreetmap'; % Using openstreetmap tool
url = 'https://a.tile.openstreetmap.org/${z}/${x}/${y}.png';
copyright = char(uint8(169));
attribution = copyright + "OpenStreetMap contributors";
addCustomBasemap(name,url,'Attribution',attribution)
data=readtable("Data1.csv")
data=readtable("Data2.csv")
% Route plotting
zoomLevel = 14; % Maximum upto 25
player = geoplayer(data.latitude(1),data.longitude(1),zoomLevel);
plotRoute(player,data.latitude,data.longitude);
% Movement of vehicle on the route
player.Basemap = 'openstreetmap';
plotRoute(player,data.latitude,data.longitude);
for i = 1:length(data.latitude)
plotPosition(player,data.latitude(i),data.longitude(i))
end
Thank you, indeed.

Answers (1)

Vatsal
Vatsal on 14 Mar 2024
Hi,
It appears that the current approach to loading multiple .gpx or .xlsx/.csv files for individual processing on 'OpenStreetMap' results in the "data" variable being overwritten upon reading "Data2.csv". Consequently, only the route for "Data2.csv" is plotted.
To ensure each file is loaded and processed individually, the code can be adjusted to manage each file separately.
Below is an example of how this adjustment can be made:
% Define the basemap
name = 'openstreetmap';
url = 'https://a.tile.openstreetmap.org/${z}/${x}/${y}.png';
copyright = char(uint8(169));
attribution = copyright + "OpenStreetMap contributors";
addCustomBasemap(name,url,'Attribution',attribution)
% Define the zoom level
zoomLevel = 14;
% List of data files
dataFiles = ["Data1.csv", "Data2.csv"];
% Loop over each data file
for k = 1:length(dataFiles)
% Read the data
data = readtable(dataFiles(k));
% Create a geo player
player = geoplayer(data.latitude(1),data.longitude(1),zoomLevel);
player.Basemap = 'openstreetmap';
% Plot the route
plotRoute(player,data.latitude,data.longitude);
% Plot the movement of vehicle on the route
for i = 1:length(data.latitude)
plotPosition(player,data.latitude(i),data.longitude(i))
end
end
I hope this helps!

Community Treasure Hunt

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

Start Hunting!