GPX and KML downloads added to Flight Historian

My Flight Historian has always used Great Circle Mapper for its maps. However, I’ve occasionally had the need to use other map formats, like GPX (used by many of my mapping projects) or KML (used by Google Earth).

A while ago I wrote some internal methods in Flight Historian’s code to let me generate GPX or KML files. However, they weren’t available for public use.

I’ve changed that with a small update today. Every map on Flight Historian now has download links immediately below it for GPX and KML versions of the map.

Creating Song Lyrics Graphs

A couple of months ago, I wrote myself a tool which could take a text file of song lyrics and generate an image showing how frequently each word appeared in the song (like a word cloud, where more frequent words were larger), and which words followed which words (unlike a word cloud, since it had arrows between the words).

After trying it on quite a few different songs, I came up with the idea of feeding it a very repetitive song, such as the road trip song 99 Bottles of Beer.

A directed graph of the lyrics of "99 Bottles of Beer," with words as nodes and edges between subsequent lyrics.

Yesterday, I decided to post this image to the Reddit r/dataisbeautiful community, and it received a lot of interest. I’ve had some people ask how I created an image like this, which this post will try to answer.

Directed Graphs

While I’ll try to keep from getting too technical, one thing we need to understand is that this song lyric image is a directed graph.

Simplified, a directed graph is a bunch of nodes (the circles, each with a unique word of the song) and edges (the arrows showing how the words are related).

For example, an edge (arrow) from “99” → “bottles” means that “99” comes just before “bottles” in the song lyrics.

I can create a directed graph with a (free!) tool like yEd Graph Editor, which lets me draw nodes (circles) and drag edges (arrows) between them.

The first two lines of the song – “99 bottles of beer on the wall / 99 bottles of beer” – in graph form

So with this alone, I could create an entire song lyrics graph, but it would take a very long time – there are thousands of words in all ninety-nine verses of the song, so I’d have to draw thousands of arrows.

Automatically Generating a yEd Graph

To save time, I want to be able to take a text file of song lyrics and automatically convert it into a yEd document.

yEd files are in a format called GraphML. Here’s a sample of a very simple graph, and the GraphML that describes it:

A simple graph, with the following nodes: 99, bottles, of, beer. Arrows join these nodes in that order.

Lines 1–6 tell us that this is the start of a GraphML document, and lines 17–18 end the document. What we care most about is the nodes (lines 8–11) and edges (lines 13–15).

You can see that each <node> has an id. Each <edge> has a source (where the arrow comes from) and target (where the arrow points to), and they use those same node ids. So, for example, <edge source="99" target="bottles"/> means “draw an arrow from the node with an id of 99 to the node with an id of bottles.”

Notice that each node can have multiple edges, so we only need to define each word as a node once – even though “bottles” is used hundreds of times throughout the song, we only need a single node with an id of bottles, and then we can refer to it with as many edges as we need.

Effectively, what I need to do is create a script which will loop through the lyrics text and create a <node> for each unique word. Then I need to go back through the lyrics and, looking at each pair of adjacent words, create an <edge> between them.

The resulting code is my song-lyrics-graph Python script. It’s built using the basic concept above, though it has some additional features too – plain vanilla GraphML doesn’t allow things like specifying the size of nodes, but yEd adds extensions to the GraphML document that let me do that.

As long as Python is installed on your computer and you’ve downloaded my script, you can drag and drop a .txt file of song lyrics onto the file, and it will generate a .graphml file with a directed graph of your song.

yEd Layouts

My script does generate all the nodes and edges, but it doesn’t position them in a pretty layout – the file it generates will just have all the nodes on top of each other.

Screenshot of yEd

Fortunately, yEd has a layout engine that will try to figure out a good arrangement of the nodes. Open the Layout menu, and you’ll see a large selection of layouts to choose from.

Screenshot of yEd's Layout menu

For most songs, I’ve found out that the Tree / Balloon layout seems to work best, though you can certainly experiment with the others.

When you select Layout / Tree / Balloon, a set

Screenshot of the yEd Balloon Layout settings menu. Root Node Policy: Weighted Center Root. Routing Style for Non-Tree Edges: Straight-Line. Preferred Child Wedge: 200. Preferred Root Wedge: 360. Minimal Edge Length: 10. Compactness Factor: 0.5. Place Children Interleaved and Straighten Chains is checked, all other checkboxes are unchecked.

Again, you can play around with the settings to try to make the graph look good, but these are the settings I usually use.

Click OK, and yEd will arrange your nodes as it sees fit.

From there, you can export your graph as a .png image by using the File / Export menu!

Converting GPS Data Between GPX and KML

Part of the GPS Mapping Tutorials series.

GPX (GPS Exchange format) and KML (Keyhole Markup Language) are both file types used to store GPS data. While many applications can use either file formats, Google products (Google Earth, Google My Maps) tend to prefer KML, so it’s often helpful to be able to convert between them.

(Note that both .kml and .kmz file extensions represent KML files; the latter is just a zipped version to reduce file size.)

This tutorial will teach you how to convert between GPX and KML (in both directions) using GPS Visualizer.

Continue reading “Converting GPS Data Between GPX and KML”

Extracting GPX Files From a Garmin Automotive GPS

Part of the GPS Mapping Tutorials series.

This tutorial will teach you how to record route data on a Garmin automotive GPS and extract it into a GPX file (which can then be used by mapping software).

I wrote this tutorial using a Garmin DriveSmart 50 LMT. However, I’ve had success using the same steps with other variations of the Garmin nüvi and DriveSmart series.

Continue reading “Extracting GPX Files From a Garmin Automotive GPS”

My Airport History: Wilkes-Barre/Scranton (AVP)

I flew into AVP for a work trip to Binghamton, New York, where flights directly into Binghamton were expensive enough to make the drive from northeastern Pennsylvania worthwhile.

The most unusual part of the airport was that (at least in 2011 when I visited) the taxiway didn’t extend all the way to the end of the runway – which meant we got to taxi down part of the runway itself, then make a U-turn to take off.

Aerial image of AVP runway 22 turnaround, showing taxi and takeoff path
Our taxi route along the red arrows, before our takeoff along the yellow arrow.

I remember that the airport gift shop had quite a lot of The Office merchandise, which made sense as that’s probably Scranton’s biggest pop culture claim to fame. I was excited to go to Scranton for a different reason, though: to drive down the hill known for the banana truck incident in the Harry Chapin song 30,000 Pounds of Bananas.

Photo of no trucks sign on the side of the road leading to the hill from the song.
Trucks are now prohibited from that route. My rental car’s brakes handled the hill just fine!

Travel Heatmap

Heatmap of the world, showing Paul’s time spent in various locations

For my 2010s Decade in Travel post, I manually created a heatmap showing the parts of the United States and world where I’d spent the most time traveling. Since I’ve been playing around with QGIS recently, I went ahead and used it to create a proper heatmap of my travels.

The hotter (more yellow) each area of the map is, the more nights I’ve spent there. The map clearly shows that the majority of my travel is within the United States, with a lot of travel to Kansas, Oklahoma, and Texas in particular. Other especially hot areas are Seattle and Orlando, both of which have had many work and personal trips.

Although the map data only goes through March 2020, it is up to date as of this post – due to COVID-19, I haven’t traveled since March.