Jul 9, 2009

Extract elevation data from Google Earth

In Google Earth COM API, there is a function: GetPointOnTerrainFromScreenCoords

Given an screen_x and screen_y, it returns IPointOnTerrainGE object, which gives out the {Latitude, Longitude, Altitude}

Screen coordinates range from (-1, –1) to (+1, +1)

(-1, -1) - bottom left hand corner of the screen. (0,0) - center of the screen. (1, 1) - top right hand corner of the screen.

Let’s use this function in Mathematica to extract elevation data.

First, zoom Google Earth into a testing place


Then in Mathematica:

ge = CreateCOMObject["GoogleEarth.ApplicationGE"];

getAltitude[x_, y_] :=
   pv = ge@GetPointOnTerrainFromScreenCoords[x, y]; {pv@Longitude, pv@Latitude, pv@Altitude}];

(* extract 50 by 50 grids around the center of the screen *)
dem = Table[
   getAltitude[x, y], {x, -0.5, 0.5, 0.02}, {y, -0.5, 0.5, 0.02}];



Next situation: Given a list of {Latitude, Longitude}, how can we get the corresponding elevations for each location?

The tip is to use the camera control to move the center of screen to the given  {Latitude, Longitude}.

cam = ge@GetCamera[1];

getAltitudebyLatLon[{lat_, Lon_}] :=
Module[{pv}, cam@FocusPointLongitude = Lon;
  cam@FocusPointLatitude = lat; cam@Range = 8000; ge@SetCamera[cam, 5];
  pv = ge@GetPointOnTerrainFromScreenCoords[0, 0]; pv@Altitude]

cam@Range is the control of “eye alt”, it is in meters.

It comes very handy for extracting the cross-profile.



leha said...

This is extremely interesting, thank you a lot.
Would you like to give a more detailed introduction in accessing the Google Earth altitude data in Mathematica and visualizing surface 3D relief and 2D relief?
I am new to MathLink and know nothing about COM programming.

bali said...

It look like you got a way to collect elevation data from Google maps which is really interesting for game devlopper because google maps look like much more precise than the free SRTM maps available on the website: dds.cr.usgs.gov.
By chance could you explain more in details? Is it possible to obtaint a grayscale elevation image tiff or bmp to be use in 3d software? Thanks for nay tutorial.

Carlos said...

Does this work on Mathematica 7? Is it the same?
I get this message...

LinkOpen::linke: "\!\(\*
StyleBox[\"\\\"Could not find MathLink executable.\\\"\", \"MT\"]\) "

Thanks, hope I can fix it soon.

Anonymous said...

Google has new Google Maps Elevation Web Services it is much better.

roy said...

is there any handy software without using this programming greek,to just take input of a required area or place abd generate the DEM etc using google earth??plz help

Anonymous said...

Programming greek?


If you do not understand the concept, or how the output is formatted, let´s not resolve to silly puns which only belittle your own lack of knowledge.

Ask for an explanation. I, as I am sure many others here would be, am willing to give a response to a focused, and polite question.

There are a wide variety of easier to access resources if you feel you cannot communicate with the professionals who put they´re (professional, yet probably unpaid) input into these forums.


Anonymous said...

Apologies for the they´re/their typo.

Please don´t hold it against me. (I blame emotional typing).

Wilfred Waters said...

are there any other ways to extract the data than using Mathematica? I have no experience with this program. I have plenty of experience with GIS programs as ArcGIS, however. Anyone with any hints, I'd appreciate it. WIl

Iweb said...

Hey there, You have done an incredible job. I will definitely digg it and in my view recommend to my friends. I’m confident they will be benefited from this site.

Google Maps Data Extraction