write multiple tracks to kml from a data structure

4 views (last 30 days)
Hi,
I have created a data structure of storm track data from a .csv file with a loop in matlab. So I now have a row for each storm and associated lat and long coords. I've used kmlwrite to generate the tracks no problem.
However, I woudl like to create a .kml of points (one set per row, see below) where the decsription for each point is the ISOTime (I converted to strings as the first error was that ISOTiem was not the correct data type).
I can't figure out how to do this as the only Mathworks examples I can find plot only one series of points (e.g. city locations), not multiple sets (rows) of points.
thanks in advance
  1 Comment
david malins
david malins on 6 Oct 2022
Hi again,
Is it actually possible to plot what I'm trying? All examples I've seen through matlab examples plot one set of lat, long with 'Name' or 'Description', but above I was hoping to write to kml all storm tracks (each row above is one track with lat, long point pairs and a 'Name' or 'Description' for each pair of points)
kmlwrite(save_file,s,"Color",colors,"Description", s.IsoTime)
is returning the error
Error using kmlwrite
The parameter/value inputs must be pairs.
I guess this is my lack of understanding of the geographic data structure. coudl someone expleain where I'm going wrong please?

Sign in to comment.

Answers (1)

Piyush Dubey
Piyush Dubey on 6 Sep 2023
In my understanding you are trying to create a data structure using storm track data from a ‘.csv’ file in MATLAB. ‘kmlwrite’ is being used to generate the tracks but the issue arises when you want to create a ‘.kml’ file for all the points. Another error that arises is, “The parameter/value inputs must be pairs”.
Please know that while writing geographical data in ‘.kml’ files the ‘kmlwrite’ or ‘kmlwriteline’ function expects a pair of latitude and longitude where each of these should be of the data type int’ or ‘double’.
Please refer to the code snippet below where a sample structure is created and using for loops the data is being written to ‘.kml’ file:
stormData = struct('Latitude',[], 'Longitude',[],'ISOTime',[]);
stormData.Latitude = [10.345 234.34 343.232];
stormData.Longitude = [10.345 234.34 343.232];
stormData.ISOTime =['2018-06-25 11:23:37.712', '2019-06-25 11:23:37.712', '2020-06-25 11:23:37.712'];
% Loop through each storm track in the stormData structure array
for i = 1:numel(stormData)
% Extract the latitude and longitude coordinates for the current storm track
lat = stormData.Latitude(i);
lon = stormData.Longitude(i);
isoTime = stormData.ISOTime(i);
kmlwriteline('track.kml', lat, lon, ...
'Description', isoTime, 'Name', 'Track Log');
end
The above written code demonstrates the use of ‘kmlwriteline’ function. Please refer to the following MathWorks documentation links for more information onkmlwrite’ and ‘kmlwriteline’ functions:
Hope this helps.

Categories

Find more on Data Import and Analysis in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!