File Exchange

image thumbnail

read_kml

version 2.0.0.0 (5.98 KB) by Amy Farris
Reads a Google Earth .kml file into Matlab

43 Downloads

Updated 31 Mar 2016

View Version History

View License

Opens a Google Earth kml file and reads the coordinates (x,y,z) into Matlab.

Cite As

Amy Farris (2021). read_kml (https://www.mathworks.com/matlabcentral/fileexchange/13026-read_kml), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (9)

Marc Compere

works like a champ on Google Earth exported path .kml file. thank you

Fried Rice

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

diogo costa

Jon

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!

Kyle Spencer

Would this still work if you converted your google earth pro in to UTM coordinates?

Joao

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

Erdal Bizkevelci

Evan Artis

Testing it out.

Malcolm Wood

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.

MATLAB Release Compatibility
Created with R2006b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!