text2kml.py

Synopsis

Convert easy-to-create text files into kml (keyhole markup language) files suitable for input to Google Maps/Earth.

Usage

text2kml.py inputFile.txt

Side effects: The extension on the input file is stripped, "kml" is added as a new extension, and the kml is written to this new file name.

Input file format

A field has the form {{{name: value }}}

There is one global field (title) which goes at the top, and describes the overall title of the kml file. It is optional.

Following that, separated by some number of blank lines, are fields describing the point to place, such as

{{{name: My House desc: Where I lived growing up coords: <google URL or (long, lat) pair> }}}

name is required and is the title of the point. desc is optional and describes the point, and is visible if the user clicks on the mark on the map.

coords Can be a raw long,lat pair such as -97.735038,30.282325, however, this can be tricky to find. An alternative is to use google maps to zoom in and center on the point to mark. The google url can be copied and pasted into coords, and the script will parse this URL to get the long,lat pair automatically. Note that in the google URL, the coordinates are presented in the reverse order as in ll=lat,long. Thus, both of these {{{coords: -97.73769,30.287138

coords: http://maps.google.com/maps?f=q&hl=en&q=austin&ie=UTF8&z=19&ll=30.287138,-97.73769&spn=0.000964,0.002248&t=k&om=1}}}

If the first character of a line is #, the line is treated as a comment and ignored.

Examples

A minimal file: {{{name: Math/Physics building (RLM) cords: -97.736196,30.288896

name: PCL (Library) cords: -97.738468,30.282468 }}}

A file using more features: {{{title: UT Buildings name: Math/Physics building (RLM) cords: http://maps.google.com/maps?f=q&hl=en&q=austin&ie=UTF8&z=19&ll=30.288896,-97.736196&spn=0.000963,0.002248&t=k&om=1 desc: many classes here, for many different subjects.

name: PCL (Library) cords: http://maps.google.com/maps?f=q&hl=en&q=austin&ie=UTF8&z=19&ll=30.282468,-97.738468&spn=0.000964,0.002248&t=k&om=1 desc: many nights here... }}}

Usage on Google

Give the kml file to Google Earth, or just enter a URL to the file into Google Maps. It'll load it, center on the area and put marks down at the right spots. However, google caches it really hard. If you use apache and put this .htaccess file there, you can retrieve URL filename####.kml, and it'll transparently redirect to filename.kml and the cache is bypassed. The only thing you have to do is update the number each time you update the file. {{{RewriteEngine On RewriteRule ([-_a-zA-z]+)[0-9]+.kml $1.kml }}}

Bugs

There could be support for having multiple "folders" (as specified by the title field).

Credits

Richard Darst, 2006-2007. GPLv2+

text2kml.py (last edited 2008-03-10 01:38:17 by localhost)