Code covered by the BSD License  

Highlights from

image thumbnail




Creates a 3-D google earth KMZ file from a matrix of [Time,Lat,Lon] and [Time,Depth/Altitude]

function pwr_kml_3d(Name,TLL,TDR)
%   Converts a track and time-depth record to a 3D google earth
%   path.  the input variable TDR defines the date range and resolution.
%   Name: a string containing the desired filename (without the '.kml'
%   extension)
%   TLL: a matrix containing [Time Latitude Longitude].  Time is in the
%   standard matlab serial format
%   TDR: a matrix containing [Time Depth].
%   A KMZ (compressed KML) files.
%   -Google earth has a limitation with respect to the amount of data
%   visible at any given time.  Files containing more than ~75,000 points
%   may cause problems when viewing the entire track.
%   -If the tracks do not appear 3D, be sure the "terrain" setting in
%   google earth is activated
%   Patrick Robinson
%   2012-05-26 V1.0

%create header and footer XML
header='<?xml version="1.0" encoding="UTF-8"?><kml xmlns="" xmlns:gx=""><Folder>	<StyleMap id="default"><Pair><key>normal</key><styleUrl>#default0</styleUrl></Pair><Pair><key>highlight</key><styleUrl>#hl</styleUrl></Pair></StyleMap><Style id="hl"><IconStyle><Icon></Icon></IconStyle><ListStyle></ListStyle></Style><Style id="default0"><IconStyle><Icon></Icon></IconStyle><ListStyle></ListStyle></Style><Placemark><styleUrl>#default</styleUrl><gx:Track><altitudeMode>absolute</altitudeMode>';

%Calculate a geographic position for each depth reading

%Create a single variable with location and depth data
TLLD=[TLL TDR(:,2)];

%Create XML text data for each time stamp and each position/depth pair
TimeData=[repmat('<when>',size(TLLD,1),1) datestr(TLLD(:,1),'yy-mm-dd') repmat('T',size(TLLD,1),1) datestr(TLL(:,1),'HH:MM:SS') repmat('Z</when>',size(TLLD,1),1)];
LocData=[repmat('<gx:coord>',size(TLLD,1),1) num2str(TLLD(:,3)) repmat(' ',size(TLLD,1),1) num2str(TLLD(:,2)) repmat(' ',size(TLLD,1),1) num2str(-TLLD(:,4)) repmat('</gx:coord>',size(TLLD,1),1)];

%Create file to deposit data and write headers
fid = fopen([Name '.kml'], 'wt');
fprintf(fid, '%s \n',header);
fprintf(fid, '%s \n', rot90(flipud(TimeData),-1));
fprintf(fid, '%s \n', rot90(flipud(LocData),-1));
fprintf(fid, '%s', footer);

%Convert file from KML to KMZ
zip(Name,[Name '.kml']);
copyfile([Name '.zip'],[Name '.kmz']);
delete([Name '.zip']);
delete([Name '.kml']);

Contact us