Monday, October 10, 2011
Hexmogrifying Google Earth
I've been a fan of Alexis' world hex mapping project for a while - even back before I had heard of the OSR Blogosphere. I love maps, and putting one into hex form immediately screams 'adventure' to me.
I wanted to try out hexing the real world myself, and though Texas would be a great place to start. I love the geography of my home state. You've got deserts and swamps and mountains and hills and nice and comfy broadleaf forests and painfully tall swaths of pine and islands and plains and marshes and canyons and playa lakes and - geez - lots of wonderful, different places that confuse the hell out of some foreign types who land at Austin and are surprised they don't see cacti and cowboys.
So, I sat down to do it. Several times. What a frikkin pain in the ass! The world is not designed to be mapped out in hex - just like it's not designed to be mapped out on a flat piece of paper either. Finding maps, lining everything up, trying to keep the boundaries of each hex happy with every other - geez. It's definitely a labor of love.
Being a programmer, I have a habit of noticing repetitive tasks. If I have to do something more than three times, I have a great urge to automate it so I don't ever have to do it again. Let's call it Engineer's ADHD. I've made a career of being assigned a job, getting bored with it, automating it, finding something else that is repetitive and boring and automating that too, until everything at the company anyone could possibly ask me to do is automated and I can finally have a nice nap. Efficiency and laziness are just different sides of the same coin.
The task of hexing the world lends itself to automation, so I started thinking about how to do it. How could you standardly assign hexes to regions? Latitude and Longitude, while wonderful for navigating the Seven Seas, is horrible for the human brain. The hashmarks they form on the globe do not make squares of equal area - or squares at all, for that matter, so utilizing them out of the box to hang a hex map on was out of the question. I had to break out the big guns. I had to break out geometry and calculus.
I've carried around math books with various bizarre formula in them most of my life. I'm not a fan of math. Actually, I hate it. That's why I love programming. All I have to do is understand it - once - and tell the computer to do it. POOF. I never have to do it again. Yeah, horrible and lazy, I know - but that's me.
This math challenge was beyond my dusty books, so I did some internet research. Math geeks are wonderful. They make some awesome web pages. The page that helped me out most was this one here - with the jaunty title of 'Calculate distance, bearing and more between Latitude/Longitude points.' That gave me all the math I needed to be able to mathematically calculate the vertices of any sized hex and translate them into latitude and longitude coordinates. With that data, I was set.
Then I was off to Google Earth. I love that program, and have gotten lost in far away countries through it more often than I'd like to admit. Our good friends at Google also offer lots of ways to manipulate Google Earth, from advanced APIs, to the simplicity of the KML file. Simplicity is what I was after.
The KML file is kind of like an HTML file, buy for maps. While you can do all kinds of things with it - like draw embed 3d building into Google Earth, I just wanted to use it to draw lines. With the latitude and longitude points generated with my ill-gotten formulae, I could draw hexes! Woot!
See this little bit of the Texas coast for yourself - with 6 mile hexes:
Right now, the KML hex file creation system is manual in the fact that I have to seed it with an area and do a lot of copy-pasting within the KML file itself. But with a bit of time, I could have a system that could overlay whatever area you want with whatever size hexes you needed. Of course, the curvature of the earth still makes things wonky at large scales (I, um, think - maybe,) but since the hex 'grid' is tied to latitude and longitude - hexing out out anything near the poles - even Antarctica, would not be a problem.
I could even add a system of graphic overlays with KML for each hex to show - oh - the post-apocalyptic differences between present day and the 'future' - turned on and off an the click of a mouse button. The possibilities with Google Earth are nigh-limitless. I sure as heck don't have a long enough lifespan to do all the things I can think about doing with it right now.
Of course, I much prefer the look of hand crafted hex maps, like those over at the Tao of D&D. But I am a lazy-ass, ADHD prone software engineer, so looks like Texas won't be all pretty, but it sure as hell will have some hexes drawn on top of it. :)