This is an example script on how to get data (loacations with altitude, colored image) from GoogleEarth into
a matlab surface.
Use this function as a script so comment the first line!
The code was tested with Matlab 2010a an GoogleEarth 6 (actual version) so download it or try your actual
GE-version: http://www.google.com/intl/en/earth/index.html
Further help for GoogleEarthAPI you find under:
http://web.archive.org/web/20090301030557/http://earth.google.com/comapi/index.html
You need additional MCFE-files before script will run without errors:
http://www.mathworks.com/matlabcentral/fileexchange/5256-pos2dist
http://www.mathworks.com/matlabcentral/fileexchange/28357-jmouseemu-mouse-emulator-v2-2
http://www.mathworks.com/matlabcentral/fileexchange/28603
http://www.mathworks.com/matlabcentral/fileexchange/14584-clipboardimage
ATTENTION: There is a heavy workaround to get an colored image from GE in line 70 (jmouseemu). Here it is
necessery to set the mousepointer in the actual GE-picture, so the x and y pixels must be in it! The
problem is, that it will not work in debug mode.
Depending of internetconnection speed you must play a little with the pause-times to get all needed data.
Programmed by Sven Koerner: koerner(underline)sven(add)gmx.de
Date: 2011/07/27
Sven Koerner (2019). Heightprofile from GoogleEarth to 3D-Surface (https://www.mathworks.com/matlabcentral/fileexchange/32357-heightprofile-from-googleearth-to-3d-surface), MATLAB Central File Exchange. Retrieved .
1.8.0.0 | Changed the link to the GoogleEarthAPI. |
|
1.7.0.0 | new title |
|
1.3.0.0 | added help pdf |
Inspired by: pos2dist, clipboardimage, jMouseEmu: Mouse Emulator (v2.3), inputEmu: Keyboard & Mouse Emulator (v1.0.1)
Inspired: How to drape Landsat images over Bedmap2 topography
Create scripts with code, output, and formatted text in a single executable document.
Sven Koerner (view profile)
Google Earth 5.2: http://www.oldversion.com.de/windows/google-earth-5-2-1-1588
Nancy Diaz-Elsayed (view profile)
Any recommendations on a reputable place to download Google Earth 5.2? The COM API doesn't support later versions, and the old versions on the Google Earth website only go as far back as 6.2 unfortunately.
Giuseppe (view profile)
Need to download google Earth?
Matt H (view profile)
Works great for me. I'm using Google Earth 5.2. I had to change the keyboard shortcut to copy the image to use CTRL+ALT+C...
inputemu({'key_down','\CTRL';
'key_down','\ALT';
'key_normal','c';
'key_up','\CTRL';
'key_up','\ALT'});
Sven Koerner (view profile)
Hi Pål,
I guess that is a limitation from google. I also tried to request a lot of values, however after a short time the anwser will last longer. So if you like to request more value, try to build in the pause-function of matlab, where you wait a second or two between the requested values. Normally it is not neccessary to reopen GE.
Otherwise you cqan try reopen GE from within Matlab:
ge_app.Quit;
ge_app.delete;
Pål (view profile)
Hi Sven,
I am having a problem when trying to loop the code over several locations without manually closing GE in between and when increasing the spatial resolution of the "meshgrid" (to f.ex. meshgrid(-1:(1/100):1, -1:(1/100):1). I'm not running the "get colored image" part of the code as I only need the X Y Z coordinates. For the first approx. 10 000 altitude values everything is quick and nice (0.001 s. pr fetched value), but after that it slows down to about 1.1 s. per fetched value. Clearing all Matlab variables dont help.
Have you experienced this kind of problems or have any suggestions for solutions? Could it be an alternative to close GE from within Matlab? If so, have you got any idea how to do this?
Zeneida (view profile)
Thanks Sven
Thats the information that I nedeed.
Regards
Zeneida
Sven Koerner (view profile)
Hey Zeneida,
here is the API-Documentation:
http://web.archive.org/web/20090227094449/http://earth.google.com/comapi/interfaceIApplicationGE.html#9e1c8da5b36e8687fe718f2267224103
In SetCameraParams means the 6 the speed of changing the view, where 6 is teleport.
The azimuth reference is here:
http://web.archive.org/web/20090301151734/http://earth.google.com/comapi/interfaceICameraInfoGE.html
Regards
Sven
Zeneida (view profile)
@Sven Körner: Thanks, I've other question, the azimut value should be changed?? and what represent the number 6 in this line: camPos.FocusPointAltitudeMode, camPos.Range,
camPos.Tilt, camPos.Azimuth, 6)??
Sven Koerner (view profile)
Hi Zeneida,
go to your GE-Application and run it. Zoom to your region and modify the parameter for latidude and longitude as shown in the GE-Picture in the middle at the bottom in decimalgrad:
e.g. for Ecuador:
camPos.FocusPointLatitude = -1.831239;
camPos.FocusPointLongitude = -78.183406;
Regards
Sven
Zeneida (view profile)
@Sven Körner: I was reviewing the scrip, now I understood first lines, I just have doubt with the Azimut, I not sure abourt this value, and I want to know what means the number six at the end of the following line:
camPos.FocusPointAltitudeMode, camPos.Range,
camPos.Tilt, camPos.Azimuth, 6);
Thanks
Zeneida (view profile)
Hi Sven,
Is the first time that I'll use your script.Could you explain me the following lines, in order to I can use this in my region (Ecuador). What are the data that I should put here.
% teleport to location
camPos.FocusPointLatitude = 51.10719595658241;
camPos.FocusPointLongitude = 13.638689585783112;
camPos.FocusPointAltitude = 0.0;
camPos.FocusPointAltitudeMode = 'AbsoluteAltitudeGE';
camPos.Range = 11780.53549488341;
camPos.Tilt = 0;
camPos.Azimuth = 7; % 0 < Speed <5 --> Speed> 5: Teleport
ge_app.SetCameraParams(camPos.FocusPointLatitude, camPos.FocusPointLongitude, camPos.FocusPointAltitude, camPos.FocusPointAltitudeMode, camPos.Range,
camPos.Tilt, camPos.Azimuth, 6);
Thanks
Matt (view profile)
Hi Sven,
Thanks for your help. Now I know how to use your code now.
I need to run the code 2 times. The first time is that I need to use ctrl+alt+c and ctrl+shift+c to copy the map. (the first time will display a error on matlab window). After I run the code again, it is works.
Matt (view profile)
@Sven Körner:Yea, same problem...waiting for fix it .......many thanks.....
Roberta (view profile)
@gong I have the same problem... my computer just accept keycombination "Ctrl+Alt+C".. I changed the command.. but it didnt work as well.. Did u try anything else??
GONG (view profile)
@Sven Körner:Thank you for so patient. In my GE,I must press the keycombination "Ctrl+Alt+C" to take a snaphot of colored GE-image. The keycombination "Alt+C" doesn't work.
Sven Koerner (view profile)
@GONG. When you run GoogleEarth normally - can you take a snaphot of colored GE-image with keycombination "ALT-C"? (Open GE, go anywhere, then press "ALT-C", then open a paint-program (e.g.) irfanview abd press crtl-V. Is there the image inside?
GONG (view profile)
@Sven Körner: Thank you very much! But it could not solve the problem. The imdata is empty with char type. The problem is the same as before while I set the pause in line 74.
Sven Koerner (view profile)
@GONG: set breakpoint in line 78. What is the type of imdata in Matlab-Workspace? If imdata is empty then modify the position of mousepointer in jmouseemu (line 72) and/ or set the pause in line 74 a littlbe bit longer. The given position must be anywhere in the google-earth picture on your monitor.
GONG (view profile)
??? Error using ==> cq
First input must be a uint8 array.
Error in ==> rgb2ind at 91
[map,X] = cq(RGB,m);
Error in ==> ge_test1 at 78
[X2, map2] = rgb2ind(imdata, 256); % not more than 256 because of uint8 is necessary