Thank you to GEB reader ‘DJ’ for suggesting this idea in the comments of our post on simulating lakes. It turns out that the algorithm for drawing contours given a regular array of altitude data is actually very simple. We used the algorithm known as ‘Marching Squares’ as described on Wikipedia. For this first attempt we are not going to bother with some of the extras, such as smoothing the final result, or dealing with saddle points.
The main difficulty is getting hold of altitude data. Google offers the Google Maps Elevation API, but it has significant restrictions, including usage limits and most important, rules about what you may do with the data, especially this line:
The Google Maps Elevation API may only be used in conjunction with displaying results on a Google map. It is prohibited to use Google Maps Elevation API data without displaying a Google map.”
If we understand that correctly as well as other restrictions regarding not storing the results, then we are not allowed to use the API to create KML files for use in Google Earth.
We had a look around for other elevation API’s but most of them have similar restrictions, i.e., you can only use them with the providers maps. There are a few that might be less restrictive, such as the ones provided by the USGS and Mapzen, but we will need to investigate them further to double check the permissions as well as how to access the data. There may be others out there. If any of our readers knows of a no-restrictions elevation API, please let us know in the comments.
For now, we have decided to run some tests with the Google Maps API and try to comply with the restrictions.
To use it, start by drawing a polygon in Google Earth, outlining the approximate area you are interested in. Save the polygon as a KML file and select it below. Choose an altitude (in metres) at which you want to draw a contour. Click the ‘Draw contour’ button.
It takes about a minute because of restrictions imposed by the Elevation API on the number of queries you are allowed to make in a given time. For this reason we have used a fairly coarse grid of 100 x 100 points.
KML polygon of the area of interest:
Altitude: m
The final result should be a black contour shown on the Google Map above. As an example, we tried the lake from our post on simulating lakes:
A contour outlining the proposed Batoka Gorge lake
About Timothy Whitehead
Timothy has been using Google Earth since 2004 when it was still called Keyhole before it was renamed Google Earth in 2005 and has been a huge fan ever since. He is a programmer working for Red Wing Aerobatx and lives in Cape Town, South Africa.
Does Google maps not use KML files? Are Google Maps and Google Earth different companies? I’m not sure I would either understand or even have considered that the language you posted would be a prohibition against using data across product lines in the same company.
On second reading – the disclaimer clearly states “‘a’ Google map” – google earth is “A” google map; map is not capitalized as a “proper noun” would be; so, refers to a generic map not a specific product’s map. “Google” is capitalized so refers to the company. Until seeing your hesitancy, it wouldn’t even occurred to me that “a Google map” didn’t refer to ANY map made by a Google product (especially when they used the same file type). It seems to me that even in a court of law (US), the “reasonable man” edict would allow assumption that it was referring to maps made by the same company.
If you can find ethical rational to agree – I (for one) would love to see you follow this line through to creating a Google Earth KML file (even if it needs a disclaimer splash screen pop-up parroting the warning) – and at least hear your thoughts on how “smoothing” and “saddle-points” would work.
You can tell I’m probably a bit of a nerd on this, I assure you it’s purely avocational.
Your last screen-print seems (at that altitude) to be exactly what I was referring to. I tested it from a polygon drawn in Google Earth (https://dl.dropboxusercontent.com/u/567495/Temp/elevationTest.kml) at 1600 meters to see what it would look like if they raised an existing dam up higher on the canyon wall. I thought that it hadn’t worked for quite a while but it just took long to calculate I guess. And it seems that you need to be able to guess where the lake will go pretty well or you get a bunch of disjointed lines. (recursive trial and error will be needed I guess).
It does show us that the idea is at least possible – thanks much.
[ps – I just followed the “terms of service” link that is generated on your API insert above and found that even Google considers the products the same – enough to have their link for the Google Maps go to the same page that their Google Earth terms of service uses.]
For grins I created a second polygon encompassing a greater area and repeated the test [https://dl.dropboxusercontent.com/u/567495/Temp/elevationTest2.kml] and the generator counted down to “2 queries remaining” and hung up. It’s now been 5 minutes and I guess that the polygon has overstretched Google’s allowances???
There may still be some bugs to iron out. I tried your polygon and it worked. The polygon size doesn’t matter as I use the min and max lat and long only and divide it up into a 100 x 100 grid. It is important to choose an altitude that is in the range of altitudes for the area or you won’t see any result.
I tried to download Google earth on my new computer which has Windows 10. It will not download and I get an error message 1603. Does anyone know how to work around this error. Thanks.
It could be that Google Earth is installed and it is just the icons that are missing. You could try just restoring the icons with instructions from
http://www.gearthblog.com/blog/archives/2011/06/cant_find_your_google_earth_icon.html.
An alternative solution that usually works in that situation is to use the offline installer found https://support.google.com/earth/answer/168344?hl=en
Hey Timothy! We only use open data. In the case of our elevation tiles and elevation API, it is from the USGS and NOAA. You are free to use the data however you wish.
More information on the tiles is here:
https://mapzen.com/blog/elevation/
along with examples on how to manipulate the data using our open source map renderer, Tangram:
https://github.com/tangrams/terrain-demos
Our Elevation API is documented here:
https://mapzen.com/documentation/elevation/elevation-service/
Let us know if you have any questions at hello@mapzen.com!