Scripting a super-fast points plotter for Google Earth
Article posted 23/02/2014
I work a lot with spreadsheet tables of points in the landscape. Each point has a latitude and a longitude, in decimal degrees. If I want to check where particular points are on the map, I could import the whole table into a GIS program and then select the points of interest. But that's way too slow! Here's a much faster way, using Google Earth as the quick-and-dirty mapper.
First I select the table cells of interest, as shown below, and copy them to the clipboard with
Next, I launch my 'points_plotter' shell script with the keyboard shortcut
Super+p and Hey presto!, Google Earth opens with the points plotted as shown:
The 'points_plotter' script looks like this:
It uses just three commands. The xclip utility first grabs the clipboard contents and sends the list of latitudes and longitudes to an AWK command (see my last Linux Rain article for another use of the very handy xclip).
AWK then builds a KML file for Google Earth to read, and sends it to my desktop. KML files aren't hard to work with after you get familiar with their syntax; for an introduction to the basics see this article. In this case the finished KML looks like this:
The last command, xdg-open, looks for the default program for opening KML files, which on my computer is Google Earth, and feeds it with the KML file on my desktop. I could launch Google Earth directly with a command, but xdg-open is easier because it doesn't require me to know the correct command name or location of the Google Earth program on my computer.
Note that the AWK command prints longitude first, then latitude, as Google Earth requires. If your table has longitude first, then latitude, the relevant bit of the AWK command would be
Another tweak might be changing the icon used for this quick-and-dirty plotting. There's a big selection of icons here. Just click on the icon you want, copy its URL and paste the URL between the <href> and </href> tags in the script above.
Other tweaks to the 'points_plotter' script are possible, like copying from the table a unique ID for each point as well as its latitude and longitude, and having that ID appear next to the icon in Google Earth, or in a balloon that pops up when you click on the icon. You could even convert to decimal degrees 'on the fly' from a table that has latitude and longitude in degree-minutes-seconds format.
These tweaks will depend on how your points table is organised, but they're easily done. Just repeat the shell scripter's mantra: Where there's a shell, there's a way...