Created the following utility which can be used to convert a CSV (Comma Separated Value) file into a KML file for use with Google Earth. See
here for the rest of my development blog regarding other topics.
Description
The above google earth image was produced from this
kml file which was produced by passing this sample
input csv file into this
perl script using the following command.
perl csv2kml.pl test1.csv test1.kml
Usage: perl csv2kml.pl <filename_in> <filename_out>
Column order is expected to be: name,description,timestamp,color,scale_or_line_width,point coordinates,line coordinates,polygon coordinates
Only supply point
OR line
OR polygon coordinates for each row
Coordinates are space separated triples of: x y z
The input csv file can be used to create points, lines and polygons of various colors and scale with timestamps(see the
input csv file for further notes on this). Color and scale can be used as part of a visual legend to indicate georeferenced data qualities or quantities. With Google Earth version 4 and greater, timestamp information can be used to provide time animations of data using the time controls.
Below is an example of a point, line and polygon
my point #1,point #1 description,2006-11-15T14:00:00,ffffbebe,0.5,-81 32 0
my line #1,line #1 description,2006-11-16T14:00:00,ffbeffbe,3,,-81 32 0 -81 32.2 0
my polygon #1,polygon #1 description,2006-11-17T14:00:00,7fbebeff,,,,-81 32 0 -81 32.2 0 -81.1 32.1 0 -81.1 32 0 -81 32 0
The perl script requires the initialization file
csv2kml.ini available in the same directory as the csv2kml.pl file to configure default parameters. The default parameters can be changed by the user as needed. Below is a listing of the parameters.
csv2kml.ini
#$field_separator,$comment_string,$coordinate_separator,$folder_name,$folder_desc,$default_timestamp,$default_color,$default_scale,$icon_href,$default_line_width
,<SEP>#<SEP>\s+<SEP>My Folder Name<SEP>My Folder Description <a href="http://ogleearth.com">ogle earth blog</a><SEP>2006-11-01T00:00:00<SEP>ffffffff<SEP>1.0<SEP>http://carocoops.org/gearth/images/white_circle_icon.png<SEP>3
Windows version (.exe)
The perl script has also been converted to a Windows
executable using
perl2exe (see other notes on perl2exe
here) so this can be run as a simple .exe without having perl installed. The command is called the same except using the .exe version
from a windows command prompt (Start->Run->type 'cmd')
csv2kml.exe test1.csv test1.kml
Google Maps
KML files can be referenced from Google maps (see examples
here), but some KML functionality may be missing - usually works ok for a small number of points, but not as well for a large number of points, lines or polygons. To reference a kml file from google maps, pass the http reference to the kml file as the 'q=' argument like below which will produce the below map.
http://maps.google.com/maps?q=http://nautilus.baruch.sc.edu/twiki_dmcc/pub/Main/Csv2Kml/test1.kml
The above map is the same as the google earth version, except for the point icons do not seem to support color shading or scaling at this time.
Further notes
Google also supports a
Google Maps API which better allows you to display and control a google map using Javascript. You have to signup for a developer key which is used with the API first.
It should also be possible to nest google maps within your browser page using either an html frames or css approach.
http://www.w3.org/TR/html4/present/frames.html
http://www.webreference.com/html/tutorial24/7.html
http://www.econym.demon.co.uk/googlemaps/test/showkml2.htm
http://underscorebleach.net/jotsheet/2004/12/frames-with-css-layout
KMZ files
You can compress/zip a kml file using winzip or some other zipping tool and rename the zipped file with a .kmz extension. Google earth is able to open .kmz files directly and .kmz compression is preferred for large kml files.
--
JeremyCothran - 18 Dec 2006
to top