This class-based MATLAB toolbox allows you to create many different plots in Google Earth, by automatically creating the required xml-based KML files without user interaction. Also allows to save as KMZ packages, including any model & images necessary for the plot.
拉斐尔·奥利维拉(2021)。KML toolbox(https://github.com/theolivenbaum/kml-toolbox), GitHub. 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.
Hi Rafael
Thanks for this toolbox - working well so far. Is it possible to add colors to the text in the kml.text function? It would be great if it can be done based on levels.
Thanks in advance
Andy
Hi, I can't find kml.install to install the toolbox
I would like to export a windrose plot or polar plot to google earth, can someone help me?
hi, I want to animate a trajectory but it doesn't work.
it works with model animation but no with just trajectory annimation (latitude, longitude , altitude).
can some one help me .thank you.
hi, when i run the RunTest,m file appears the next mistake:
No appropriate method, property, or field 'createFolder' for class 'kml'.
Error in RunTests (line 7)
f = k.createFolder('kml.plot');
any solution?
Sebastian
Rafael,
Forked your KML toolbox github repository athttps://github.com/gedeschaines/kml-toolbox/tree/masterto provide updates to test/RunTests.m, test/RunTestsRadians.m, test/bitsplice.m for compatibility with Matlab R2018b, and to include A320.dae to address issues raised by @Warwick and @Tracy below.
failed when I tried RunTests.m
Error using bitcmp
ASSUMEDTYPE must be an integer type name.
Error in bitslice (line 7)
b = bitand(b,bitcmp(0,numbits));
Error in RunTests (line 113)
img = bitslice(dimg,ee(i,1),ee(i,2));
Awesome!
Downloaded and tried to run the various tests, however a file that is used in all I've tried is not in the zip archive. 'A320.dae'
Also, reading other comments, I'm also wondering how to add a color bar (tuan 31 Mar 2017) and if specific color levels for contours like 'LevelList' in Matlabs contourf function.
I have this problem:
This will add the KML toolbox to your MATLAB path, at the current location
If you prefer to have it located somewhere else, first copy the whole folder
to the place you want, and then run kml.install from there!
Toolbox Path: D:\Descargas\rafael-aero-kml-toolbox-37e5b7a\rafael-aero-kml-toolbox-37e5b7a
Continue [Y]/N? Y
Adding toolbox folder to the MATLAB path...
(In some systems, this might require administrative rights, sorry for that)
Installing the toolbox help...
Error using builddocsearchdb (line 30)
Could not write search database.
Error in kml.install (line 310)
builddocsearchdb(fullfile(p,'html'))
Any suggestion? Thanks
Awesome had everything I needed.
Hi all
(1) Is there anyone know how to plot an animation for spatial contourmap?
(2) And how to add colorbar that corresponds to the plot has been shown by using k.contourf?
Thank you
If anyone needs to export complex 3D geometry, be it a surface (xyz grid) or a patch (faces and vertices), textured or not, please try mesh2kml and leave feedback.
http://au.mathworks.com/matlabcentral/fileexchange/62156-mesh2kml
If anyone needs to export complex 3D geometry, be it a surface (xyz grid) or a patch (faces and vertices), textured or not, please try mesh2kml and leave feedback.
http://au.mathworks.com/matlabcentral/fileexchange/62156-export-a-mesh--surface-or-patch--as-googleearth-kml-and-collada-dae-files
I wonder if the plot function has the options for plot symbols and colors, such as
kml.plot(x,y,'b+'), something that is already included in Matlab's plot function.
Thanks.
Hi,
Is there any function to plot and export filled color contour map? Thank you.
RunTests.m errors because BITCMP no longer accepts an integer second argument…
I've just started using this toolbox, and it is working great. It is very easy to pick up and use.
I ran into one problem. Whenever I used k.run, GoogleEarth tells me it can't find the file at z:\filename. The filename is correct, but the path is incorrect. I found a solution. I work in a company where we are required to have our files on network drives. In Matlab you use: [p,fn,ext] = fileparts(filename);. On our networked system this returns an empty variable for the path p = ''. I don't know if this is a Matlab problem or a problem with how my company set up it's network drives. To solve this in kml.m I added the line p = pwd; to force the correct path.
line 138
if this.zip
[p,fn,ext] = fileparts(filename);
p = pwd;
kmzFilename = fullfile(p,[fn '.kmz']);
zip(kmzFilename,vertcat({filename},this.includeFiles(:)).');
delete(filename);
movefile([kmzFilename '.zip'],kmzFilename);
this.filename = kmzFilename;
else
this.filename = filename;
end
Since I don't know if this is a general Matlab problem or a problem specific to my company, I don't know if this should be patched in your distributed version.
Thanks for the toolbox.
This is an excellent toolbox that enables a wide variety of KML plots.
Regarding Sylvie's comment of 31 Jul. 2014 and Rafael's replies to Tomasz in July of 2013...
It appears that you can get uniform color axes by passing a vector to numberOfLevels in contourf, if you insert a kludge.
At line 147 of contourf.m, you have:
levels = unique([C(:).l]);
I then pass the numberoflevels vector to levels once more.
levels = arg.numberOfLevels;
This seems to work. One probably should put some code in to test for a vector when implementing this kludge.
Hello!
I have a question concerning the layers in google earth. As i have very many layers and lot of data, showing them all at when opening the file almost crashes my computer. I want that when i open my xml file, all the layers would be deselected. How can i do that?
I started using this recently - so far so good except possibly for the following:. 2. It also reports " is expected to be an attribute, not an element." 3. The save to .kml (vs. kmz) feature may require a third boolean argument that is not documented in the help.
1. Google earth identifies a mis-spelling of
kmltoolbox v2.71
Google Earth
7.1.2.2041
Build Date
10/7/2013
Build Time
12:28:36 pm
I try this toolbox,it's useful toolbox.
but I have a problem!! I'd like to load my images or models directly from internet, how can I do this?
I found your toolbox and it is just a great tool to have. I do have a few questions about the plotting abilities:
-Is there a way for the contour/contourf plots to keep the colorscale/contour levels entered as input. I am planning on making movies and comparing footprints and I need the color scale/contour levels to stay the same from one plot to the other and right now even when I specify the color scale, if for instance the maximum value in the data to plot is less than the maximum in the color scale, the end results will be scaled to the maximum value from the dataset.
With contourf, you can force the contour level values by using caxis for instance.
- How can I get a colorbar that correspond to what has been plotted. I found ge_colorbar, but it seems like the even with the same color scale as input for both ge_colorscale and k.contourf, it is not quite the same contours being plotted.
Hi, very good work thanks! Using the transfer function its easy display plots on google earth. To set the coordinates, one can change line 80 in the transfer.m file.
Example:
(default:[west,east,south,north] = deal(xlim(1),xlim(2),ylim(1),ylim(2));)
[west,east,south,north] = deal(98.804192,100.834833,38.663767,39.876606);
works fine!
Hi All,
I am trying to keep a folder hierarchy using the create folder function and gradually filling it up with plots at different times without overwriting the old plots.
Seems that whenever kml(‘name’) is called, the main folder and its contents is overwritten with only the plots created at that instance available in the hierarchy..
Any quick thoughts? ... (merging old and new kmz files maybe?)
My data set is 1 hour average matrix and the concentrations are not constant. If I use a static number of levels it fails saying the interpolation requires two sample points in each dimension.
It seems like I will need to change the range based on the minimum and maximum values in each 1-hour data.
Any suggestions from anyone?
How are you doing the atmospheric back trajectories? Could you please put down a quick info? Thanks!
BTW worked out how to get a colourbar xml tags to the kml file referencing the standalone image
1. plot colour bar in standard matlab figure
2. save colour bar axis as a standalone image
3. write
Hi this tool is great, I'm plotting atmospheric back trajectories with it.
One question though, is there any way within the toolkit to export a colourbar into google earth and display it in space, to the side of the globe?
Or if there is no such functionality could anybody point me in the direction of some resource that might tell me how?
Thanks, Eoghan
Got the labels, thanks!
Is there a way to label the contours with the levels (z)?
Hi Rafael, I'm using the overlay but I do not understand the format of coordinates west east south north. I have an image jpeg with the coordinates of the corners lat lon, I what way I can put them in the function. I tried to do this:
kml.overlay(kml_UPLlon,kml_LWLlon, kml_UPRlon,kml_LWRlon , kml_LWLlat,kml_LWRlat, kml_UPLlat,kml_UPRlat, bitmap_name,bitmap_name);
but It doesn't works. The error is:
Error using kml/overlay
No Static method 'overlay' in
class 'kml'.
Error in Alice_thresholds
(line 105)
kml.overlay(kml_UPLlon,kml_LWLlon,
kml_UPRlon,kml_LWRlon ,
kml_LWLlat,kml_LWRlat,
kml_UPLlat,kml_UPRlat,
bitmap_name,bitmap_name);
Can you helpme?
Thank you in advance
Giancanio
Incredibly good implementation of MATLAB control to GoogleEarth via creation of KMZ files. I installed the package, and had plots up in Google Earth within 5 minutes!
Hi, I tried to install this tool. However, it didn't work.
I typed kml.install in the directory kmltoobox v2.6 containing @kml, @kmlAnimation, etc. However, it said,
>> kml.install
Error: File: kml.m Line: 1 Column: 10
A class definition must be in an "@" directory.
Who can help me about this.. Thank you !
Hi Tomas,
you can force the contourf to always plot contours in the same way by passing in argument 'numberOfLevels' an array of values for the contours, something like:
k.contourf(..., 'numberOfLevels', [5 10 15 20])
I am using the KML Toolbox to present temperature distribution using contourf. Since the temperature range changes over time, consecutive plots are not consistent, because the colormap stretch to min and max value. Is it possible to fix the minimum and maximum values, so that the colormap is always within the same range?
我发现了一个bug覆盖功能。如果我尝试to add an overlay image with a path in the filename, it embeds the state path in the kml file, thus when I load the kmz file into Google Earth, it goes looking for the file at the stated path. It does not use the file embedded with the kmz file.
For example, if I do the following,
k.overlay(west,east,south,north,'file','C:\temp\myImage.png');
Google Earth will grab the image "C:\temp\myImage.png", not the one embedded with the kmz file. I suggest you remove the path from the filename that is used in the kml file.
Other than that, it is a great toolbox.
Hi Rafael,
in the file
function target = plot(this,long,lat,varargin)
I found an issue in the chech of the lat and long input value (line 14 and 15).
函数处理包括直接的检查r the input value &&~isempty(lat). This must be &&~isempty(a).
This lines should be:
p.addRequired('lat', @(a)isnumeric(a) && isvector(a) &&~isempty(a));
p.addRequired('long',@(a)isnumeric(a) && isvector(a) &&~isempty(a) && numel(a)==nlat);
@Ryan: thanks for reporting the error, you can fix it by changing that line to:
if iscell(arg.iconColor) && nc==nlat
I'll submit a fixed version of the toolbox.
@Alfredo: I've changed the save function, now it should be possible to save to other folders as well - thanks for the tip. And to avoid those lines, just make sure you end every plot command with a ;
Hi Rafael,
I really like this tool box, I have been using it quite a bit.
I wanted to report a possible error:
When using k.scatter3(lon,lat,z, ...
'iconColor','FFFF0000','iconScale',.2);
I get an error when plotting exactly 8 points
Cell contents reference from a non-cell array object.
Error in kml/scatter3 (line 131)
iconstyle.appendChild(this.textNode('color',arg.iconColor{i}));
——似乎发生在scatter3函数because nc==nlat returns true, and it should probably be false.
if nc==nlat
iconstyle.appendChild(this.textNode('color',arg.iconColor{i}));
else
iconstyle.appendChild(this.textNode('color',arg.iconColor));
end
Thanks again for the toolbox
It would be cool that the k.save function supported the path in the filename. i.e.:
k.save('path\filename.kml')
Now it ignores the path and saves the kml file in the current folder.
Thank you
Also, how can I avoid the display of the following lines in the Command Window? Thanks
ans =
type: 'Placemark'
id: [1x47 char]
It would be cool that the k.save function supported the path in the filename. i.e.:
k.save('path\filename.kml')
Now it ignores the path and saves the kml file in the current folder.
Thank you
Just a quick comment, I'm doing some stuff that requires accurate lat and longs have gone through and changed
num2str(north) to num2str(north,8) to avoid loosing position accuracy
Works great
Hi Rafael,
Thanks for making this great tool. I had a minor issue with the klm.transfer function not lining up properly. I discovered that this was because my plotting script used "axis equal". This resulted in the axes not filling the whole figure window during the image capture so the image limits were not quite right. perhaps you could add "axis normal" in the code somewhere so that it will always behave as expected.
Sorry Tomas, but the toolbox needs a MATLAB version that supports classes, which are definitely not available at R2007b...
Matlab version 2007b:
>>kml.install
??? No appropriate method or public field install for class kml.
When I try:
>>kmldoc %KML toolbox appear but its not functional.
and for those interested in the animation feature, here is a little example of using it:
k = kml(“testAnimation”);
k.useRadians;
N = numel(longitude);
yaw = yaw - pi; %This is to correct the mis-orientation in the A320 model, you can ignore this for other models - or fix the model file
modelA320 = k.model(longitude(1),latitude(1),altitude(1),yaw(1),gamma(1),roll(1),'model','A320.dae','scale',10);
anim = k.newAnimation('Flight');
for i = 2:N
dT = time(i) - time(i-1);
anim.updateLocation(modelA320,dT,longitude(i),latitude(i),altitude(i));
anim.updateOrientation(modelA320,dT,yaw(i)-pi,gamma(i),roll(i));
anim.flyToLookAt(dT, longitude(i), latitude(i),1e4)
end
anim.flyToLookAt(10, mean(longitude),mean(latitude),1e5);
k.run;
Hi John,
I've answered you by email, but in any case, the fix is to replace the num2str(id) with num2str(i). Anyway, I've submitted a fixed version of the toolbox, that also includes some other bug fixes.
Rafael,
I get the following error when I run the quiver function example snippet:
k = kml('my kml file');
% Create a sample quiver plot in the kml file
[x,y] = meshgrid(-5:.2:5,-2:.15:2);
z = x .* exp(-x.^2 - y.^2) + y.*sin(x);
[px,py] = gradient(z,.2,.15);
k.quiver(5*x,10*y,8*px,8*py)
% Save the kml and open it in Google Earth
k.save;
??? Undefined function or variable 'id'.
Error in ==> kml.quiver at 61
target(i) = f.plot(long2,lat2, 'altitude',arg.altitude,...
Any thoughts?
Thanks a lot for the contourf function! Just fyi, the [~, ixMA] at line 137 gives errors on old (i.e. 2009) versions. Another question... are you implementing a way to specify the contour values rather than the number of contours?
Cheers!
This is a perfect toolbox.
++Ahmet
Hi Seb Biass, I've finally added contourf to the toolbox :)
If you find any bugs on it, let me know!
@Stephan - I've almost finished screen overlay support, I'll update it as soon as I've time to finish and test it.
Would it be possible to include screen overlays?
That is really nice, thank you! Any chance for a contourf type function?
Hi Zeneida,
You can do it using the option 'numberOfLevels', as in:
k = kml;
[x,y,z] = peaks;
k.contour(x,y,z, 'numberOfLevels', 20);
k.run;
Hello,
There is a way do more contours, I need that more contour lines in the map, but I don't know is it can be. In the contour.m from matlab I can specify the number of lines, but here?????
Thank you
谢谢你的小费……我已经包括了updated version, together with a change removing the ~ from the function outputs. Now it should work with some older MATLAB versions too!
Very nice and useful! I made one very small edit to kml.m to get it to work on the Mac platform. Not sure if Linux has a common tool like start or open that is independent of distro.
function run(this)
this.save;
if (ispc)
system(['start "kmltoolbox" "' this.filename '"']);
elseif (ismac)
system(['open' ' "' this.filename '"']);
elseif (isunix)
disp('The KML file has been saved, open it in Google Earth');
end
end
This is a great program ... it has provided a great way to visualize my measurement results spatially.
hey this looks great! Why not combine the two versions into the best matlab version? I am building at multilanguage version of the googleearth toolbox and would welcome motivated matlab development and extension.
http://code.google.com/p/googleearthtoolbox/source/browse/#git%2Fmatlab
Hi Travis. I've used the same name, but they're all encapsulated inside the kml class... So, to call them, you need to create an instance of the kml class, for example:
mykml = kml('Sample plot');
And then use this object "mykml" to plot, as in:
mykml.plot(1:10, sin(1:10));
or
mykml.scatter(rand(100,1),rand(100,1));
I am wondering why you built functions with the same name as MatLab built-in functions (e.g. plot.m, plot3.m, text.m)? This seems pretty counter-productive. Can you correct me on this?
的面向对象版本谷歌地球olbox. Wonderful! Thank you so much for sharing...