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

http://maps.google.com/maps/api/elevation/outputFormat?parameters

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:
json=Import["http://maps.google.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&sensor=false"]

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


ToExpression@StringCases[json, NumberString]


{39.7392,-104.985,1608.84}


Here is the example output:



GoogleEvelvationService0



Path elevation example:



GoogleEvelvationService



DEM + Path:



GoogleEvelvationService2


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.



GoogleElevationService