Mar 25, 2010

Extract elevation data with Google Elevation Service

In the previous post: Extract elevation data from Google Earth, Google Earth COM API is used, it only works on Windows platform. Google Map now has Elevation Web Service, it is quite easy to do it with new API. The new service does not require a Maps API key. The basic form is

For output format, 

  • /json returns results in JavaScript Object Notation (JSON).
  • /xml returns results in XML, wrapped within a <ElevationResponse> node.

JSON is easy to parse, this is a sample query:

  "status": "OK",
  "results": [ {
    "location": {
      "lat": 39.7391536,
      "lng": -104.9847034
    "elevation": 1608.8402100
  } ]

ToExpression@StringCases[json, NumberString]


Here is the example output:


Path elevation example:


DEM + Path:


Grab the GoogleElevationService.nb for detail.

Update: answer the comments

You may have the trouble with the notebook. Sometimes ListPlot3D runs too slow and even crashes Mathematica. You can switch to ListPlotPoint3D.

ListPointPlot3D[dem[[All, {2, 1, 3}]], ColorFunction -> "Rainbow"]

Here is the example with 100 by 100 DEM.



Carlos said...

Thanks this is great. I really wanted to use this on a mac, and the NETLink[] is not available. Great tutorials.

Anonymous said...


Nicholas said...

I'll have to try this. Thanks!

rocksandrock said...
This comment has been removed by the author.
rocksandrock said...

This does not seem to work at all anymore - Several months ago I was able to change the lat long in order create a profile for a location, but coming back now and trying to pull the date (even using your template data) results in nothing but error messages.

Has Google somehow made this inoperable?

Please understand that I know very little of the programming jargon - I greatly value spacial data, but am not a wizard when it comes to programing (at all). I would LOVE for this to be made more transparent.


Anonymous said...

Still works for me, and sometimes listplot3d crashes mathematica, using the following line:
g1 = ListPointPlot3D[dem[[All, {2, 1, 3}]], ColorFunction -> "Rainbow",
BoxRatios -> {1, 1, 0.3}]

Ewen said...

Love your website, thank you so much.

I'm having trouble getting this nb to run. The listplot generated is this:

Haven't changed anything. I'm not up to diagnosing what's going on. Any ideas appreciated.

Mathematica 8.0.1 on Vista.


Anonymous said...

Does a similar code or package existe in R Cran? I would love it! it looks really amazing and actually useful... Thanks for any ideas

Markus Hammori said...

Great articel. I would like to use one of your pictures in a presentation. Would that be ok for you?

Iweb said...

Hi there, I seriously desire to declare that I came across your post and found it to be interesting.Thanks for sharing the nice information and this really helpful for us.

Harvest Business Business Listing