Sunday, April 6, 2014

How to Create Alabama County KML Files for Google Earth

For the purposes of my genealogy, I want to be able to highlight certain counties in eastern Alabama in Google Earth. Google Earth has county boundaries and names but there is no option to color the area covering specific counties. And, if you zoom out far enough, the county lines and labels disappear. There is data available on line to generate such county coverings but what I found needs to be processed first. First, go to the “Alabama Counties - Google Fusion Tables” web page.

(Click on the images to enlarge them.)

Click on the blue “Filter” button near the upper left-hand corner of the table.


Choose the “County Name” option. In this example, I am interested in Cherokee County.


Under the “File” menu, choose “Download”.


Alas, the “KML” options are grayed-out so we will have to choose the “Filtered Rows” content and the “CSV” format. Click on the blue “Download” button.


This will cause a “csv” (“comma-separated values”) file to be downloaded, named "Alabama Counties-filtered.csv” or some variation of that. Use your preferred text editor to open the file. When I opened it in Vim, it looked like this:


[EDIT:  Make sure there are no spaces between the comma-separated values and that there are spaces or carriage returns separating data pairs or triples. Otherwise, Google Earth has trouble.  Why?  I don't know.] I now follow the instructions found on the dagik.org web site: Delete all text at the top and bottom, except the (longitude, latitude) data. Add the following lines to the top of the file:

 

 and then add the following lines to the bottom of the file:

 

The result should look like the following.


You can massage the data so that it’s in two nice, neat columns, but it isn’t necessary for it to work in Google Earth.

NOTE: The order of the latitude and longitude points is reversed from what you are probably used to! If you look carefully at each comma-separated ordered pair, you note that the first coordinate is the longitude and the second coordinate is the latitude. This is due to the fact that Google Earth uses them that way, which is just the opposite of what I’ve ever done with any other software. Now write the result to a new file with a “.kml” file name extension.


Drag this new KML file to the Google Earth map window and drop it there. You should see the county area highlighted.


If you zoom in a little bit you can see the outline is not perfect, but it’s pretty close. Certainly it is useful for my purposes.

No comments:

Post a Comment