The eagle-eyed amongst you may have noticed something interesting in the previous blog post: I chose to highlight some countries in particular (the UK and the US) and I chose to call this list
avoids in the source code (line 19).
Whilst the previous script did indeed easily display where the antipode of any point was (thus helping me to find that Tasmania would be a great bet) it did have one huge flaw if it was to be used to avoid places: it would only tell you how to avoid a point. The script was not helpful at all at telling you how to avoid an area, such as a country: I therefore set out to write version 2 of my script.
My chosen method was to expand the coastlines of a list of countries by set distances. By successively increasing the coastlines I would create an area on the far side of the Earth that was further away than the expanded coastline (or indeed outside this "exclusion zone"). I could then increase the distance until there was nowhere left on the surface of the Earth that was that far away from the coastlines. The technical term for such an operation is to buffer an object and Shapely has a function to do just that.
Unfortunately, the Shapely function has no knowledge that it is being used to describe areas on the surface of the Earth: it is just a library that describes shapes. Consequently, the buffer function expands objects by whatever unit the object is described in, in this case: degrees. This poses a major problem: the length of a degree changes depending on where you are in the world and which direction you would like to go. Additionally, it has no knowledge of the anti-meridian and the problem that it poses. What I needed was a function that took in an area defined in degrees and buffered it by a single distance: the resultant object would be buffered by a varying amount in units of degrees but by a constant amount in units of kilometres. For this script to work I wrote two functions:
buffer_point(): uses Vincenty's (direct) formula (as found in
calc_loc_from_loc_and_bearing_and_dist()) to buffer a single point by going a set distance away from the point for a range of angles across the whole compass. By connecting these points together an ellipse-like area is found around a single point.
buffer_point()to buffer each point in each (external and internal) edge of a polygon and then finds the union of all of the ellipse-like areas (and the original polygon) so as to find the buffered polygon.
Once these two functions were written (and extra logic was added to deal with areas overlapping the anti-meridian) it was relatively easy to buffer the coastlines of the UK and the US and find out where in the world to go if you wanted to avoid them. Below is the script that I wrote that uses these two functions (I found that simplifying the polygons whenever I could drastically reduced runtime).
The image produced by this script is shown below.
A couple of things strike me when I look at this image:
- You can only get roughly 14,000 km away from both the UK and the US even though the half-circumference of Earth is roughly 20,000 km.
- The Kerguelen Islands are your best bet (you'll have to ask the French very nicely if you want to visit).
- Alaska looses significance the further away you get (to be expected) but somewhere between 10,000 km and 12,000 km it becomes irrelevant. Note the straight green (4,000 km) line that cuts across South Korea - that is the Alaskan coastline. Similarly, the straight blue (6,000 km) line that cuts across China is the Alaskan coastline too. You can follow that straight line as it steps through Asia, however, it becomes smaller and smaller as the coastlines from the south east of England and Hawaii expand - the Alaskan coastline finally becomes encompassed by the other coastlines somewhere in the Indian Ocean.
- Whilst the previous blog post showed Tasmania as being between the UK and the US it would, in fact, be a bad choice because it is far too close to Hawaii on the other side (it only survives roughly 8,500 km).