Thursday, July 3, 2008

How to write KML like a rock star

Hi. This is Craig Johnston and Brian Hull of Sudjam, LLC, the company hosting and developing the new online presence for the band Nine Inch Nails. This guest blog entry will cover how we went about creating a Google Earth representation of downloads for NIN's latest album, the slip. We started out with about the first 1.4 million downloads logged (ironically just a subset of the total downloads), and wanted to end up with a dramatic representation of the data set, suitable for the exacting stylistic demands of NIN. Something along these lines:
We first needed to generate lat/longs, which we did by running the IP addresses logged for each download through the GeoIP® database. The process yielded a high precision set of locations, yet too many to represent as a single data set in Google Earth (we tried). We solved this by grouping the data into histogram-like bins, which we accomplished simply by dropping the precision of the lat/longs when we retrieved them. This took us down to a more acceptable ~40,000 Placemarks, each with a total number of downloads. The next step was to represent the data in a dramatic fashion... or in Google Earth terms, extruding a polygon into space in proportion to the total downloads. We accomplished this easily enough, but then also wanted the download totals for each column to be clickable. We used a solution we found in Jason Birch's blog which involved embedding a point with the polygon section of the Placemark and wrapping them in a MultiGeometry tag, which ended up looking like this:
   <description>17875 downloads.</description>
To avoid the icon clutter, we substituted a 1x1-pixel transparent PNG icon placed in the center of the polygon's base. Finally, we added in a watermark logo and some instructional text using <ScreenOverlay>, and it was complete. The final result is available for download from the NIN website. Fans of the band can also follow its upcoming tour directly in Google Earth -- their performance page lets you subscribe to tour updates as a KML file, with all the tour stops in sequence and time-tagged. Because the tour data is implemented behind a <NetworkLink>, it's always up-to-date, even when users save it to their My Places in Google Earth. We had a lot of fun doing these visualizations, and are grateful to have a client like Trent Reznor who understands and appreciates a cool little side project such as this enough to not only promote it but to put his name behind it. And thanks to Topspin Media for providing the original idea.