When creating the heatmap for yesterdays post we discovered some things that we think are worth sharing.
Every point on Earth’s surface can be located with a latitude and longitude. In decimal format these range from -90° to 90° latitude and -180° to 180° longitude. We needed to draw a polygon that goes across the antimeridian (the line at -180° / 180° longitude). We did think ahead and included in our code appropriate conversion to ensure that the coordinates stayed within the correct range. We were surprised to discover that Google Earth drew the polygons wrapped all the way around the globe.
Left: What we wanted. Right: What we got.
After some experimentation in Google Earth, saving what we drew to KML and inspecting the contents we found that Google Earth does handle coordinates less than -180° or greater than 180° longitude. If you want your rectangle to go over the antimeridian rather than all the way around the world, then simply keep the longitudes all positive or all negative and use numbers larger than 180 for some of the points. So, if for example, your rectangle goes from 170° to 190°, then Google Earth will draw it across the antimeridian.
We also found that if you draw a large filled polygon that does wrap around the globe, it is not allowed to cross all lines of longitude.
Achieving this effect with a single filled polygon is not possible. The above screen shot is actually two separate polygons.
It is also impossible to draw a filled polygon that includes the North Pole in its enclosed area. This is actually a direct consequence of how Google Earth draws ‘straight lines’, which we previously discussed in this post. As we noted in that post, unfilled polygons behave quite differently and can wrap around the globe as well as encircle the North Pole. They, however, have a different restriction: the line between any two points always takes the shortest section of a great circle, so to wrap around the globe you need at least one point on the far side of the globe.
The rules for unfilled polygons are different.
There is a ridge in the ocean floor data along the antimeridian.
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.