Opens a Google Earth kml file and reads the coordinates (x,y,z) into Matlab.
Amy Farris (2021). read_kml (https://www.mathworks.com/matlabcentral/fileexchange/13026-read_kml), MATLAB Central File Exchange. Retrieved .
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
works like a champ on Google Earth exported path .kml file. thank you
Add the last 3 lines / final "else" statement from the code snippet below, just in case that neither the first or last cell is empty.
--> Otherwise "Undefined function or variable 'D'.".
% sometimes first and/or last element in C is empty, this causes problems
len = size(C,2);
if isempty(C{1}) && isempty(C{end})
D = C(2:len-1);
elseif isempty(C{1}) && ~isempty(C{end})
D = C(2:end);
elseif isempty(C{end}) && ~isempty(C{1})
D = C(1:len-1);
else
D = C;
end
I had to adjust it to my kml file that only contained lat/long (no z coordinate) and I optimized the final step a bit, but it gets the job done!
Would this still work if you converted your google earth pro in to UTM coordinates?
Great, but kml document breaks coordinates if there are more than 1000 points.
So in this function you just pick the first 1000 points.
Maybe with another if, you can check if there are a second block of coordinate.
thanks
Testing it out.
Nice function. I think you could make it much more robust to mis-placed spaces by using "xmlread" and then the W3C XML-handling classes, e.g.:
>> doc = xmlread(fileName);
>> c = doc.getElementsByTagName('coordinates').item(0);
>> coord_str = c.getChildNodes().item(0).getData();
etc.