Skip to topic | Skip to bottom
Main.Csv2Kmlr1.2 - 19 Dec 2006 - 14:59 - JeremyCothrantopic end

Start of topic | Skip to actions
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 test1.csv test1.kml

Usage: perl <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 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="">ogle earth blog</a><SEP>2006-11-01T00:00:00<SEP>ffffffff<SEP>1.0<SEP><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.

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.

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

I Attachment Action Size Date Who Comment manage 4.4 K 19 Dec 2006 - 17:02 JeremyCothran NA
csv2kml.ini manage 0.4 K 19 Dec 2006 - 14:58 JeremyCothran NA
test1.csv manage 1.9 K 19 Dec 2006 - 14:58 JeremyCothran NA
test1.kml manage 4.1 K 19 Dec 2006 - 14:58 JeremyCothran NA
csv2kml.exe manage 390.7 K 19 Dec 2006 - 17:02 JeremyCothran NA
csv2kml_ge.jpg manage 212.0 K 19 Dec 2006 - 15:06 JeremyCothran na
csv2kml_maps.jpg manage 187.9 K 19 Dec 2006 - 15:07 JeremyCothran na

You are here: Main > Csv2Kml

to top

Copyright © 1999-2018 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding DMCC? Send feedback