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.
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
supply point 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.
,<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
(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
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.
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.
Google also supports a Google Maps API
It should also be possible to nest google maps within your browser page using either an html frames or css approach.
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.
- 18 Dec 2006