More on maps, KML and polygons
Still working on the maps. It all got a bit more complicated. I hadn't appreciated that the polygons drawn round counties might include islands, and therefore actually more than one polygon is needed to draw the whole county. The problem here is that I'd been merrily deleting every other line, but some of the lines weren't just coordinates - they also contained some tags specifying that "this isn't part of the main polygon, it's a sub-polygon".
Here's the section of the KML file that relates to Devon, with the "create the polygon" line highlighted.
This is one (very) long line of coordinate pairs. To make all this work (I didn't go into this level of detail in my first post) I've been breaking this out into one coordinate pair per line, using Textwrangler to replace all the spaces on that line with line breaks. Which gets you to this...
Then I had been using sed to delete alternate lines, not worrying if the opening and closing tags (line 7, for example) got deleted - I'd just put them back in afterwards.
BUT OH NO! Hiding somewhere in there is this sort of thing. Note that this appears on line 61,985 - that gives you an idea of how many individual points are required to accurately draw the coast of Devon (62,178 or thereabouts).
My smoothing process had deleted this line, so some points got joined up directly to other points that shouldn't be. This is the result:
You can see where the problem points are. Roughly speaking, they're top left and bottom left of Devon. These are, in fact, Lundy Heritage Coast (top left) and The Great Mew Stone (bottom left).
Once I'd worked this out the solution was pretty simple, if tortuous. Go through and find each section, smooth it individually, then join them back together again, preserving all the required tags. Devon code now looks like this. I've put the comments in to keep track of things - these will be in my final [glorious!!] file.
Devon on the map now looks like this:
If you're thinking "this doesn't really relate to the original point of this exercise"... you're right. This xkcd comic applies here...