Jul 14 2006
Converting Shapefiles (and more) to KML
A while back I wrote about converting KML files into a shapefile for use with GIS apps other than GoogleEarth. I got a ton of emails and site traffic from people looking to go the opposite direction; getting their GIS data into KML.
There are, of course, a couple of utilities already implemented: ArcMap-based extensions including KML Home Companion and Arc2Earth, a nice MapWindow app called Shape2Earth, and the open source WMS Geoserver all support KML output.
Not to be left behind, GDAL/OGR now supports KML output. Oddly enough it does not yet read KML. But hand it any OGR-readable vector dataset and it can be converted into KML. It currently doesn’t offer as much control over the output as the above options but is quicker to implement, works with a wide variety of input formats and can be easily scripted.
This functionality is in CVS only at the moment but should be included in the next release. If you can’t wait and don’t feel like compiling from cvs source, try the 1.0.5 version of FWTools (for Windows and Linux).
The conversion process is pretty straightforward. For example, the following will convert a shapefile (sbpoints.shp) to KML (mypoints.kml).
ogr2ogr -f KML mypoints.kml sbpoints.shp sbpoints
The KML format flys in the face of the GIS mantra stating that content should be seperate from styling. Since styling information is purposefully absent from most standard vector formats, it makes for pretty bland KML output. The attributes just get dumped out into one big text block and there is no classification or styling control.

But in terms of getting your data into Google Earth quickly (esp. point data), the OGR method looks promising.
Thanks Perry,
Your solutions are being very useful to me and I believe that others people are using it too.
Great blog.
PostgreSQL/PostGIS users can export a basic Geometry from database using AsKML() function introduced at 1.2.1 version. Although is not a full KML document, it saves a lot of work on export process.
I should probably chime in and let folks know that the FME product (free eval at http://www.safe.com) can do a very good job of going from Shape (or most any spatial format) into KML. See more details about it at http://www.safe.com/google/earth/index.php and some examples made by one customer at http://earth.nanaimo.ca/ (check the data tab).
Dale
i have recently begun using FWTools (GDAL and ogr2ogr) a lot more for this type of operation, but wanted to share these tools as i still use them quite frequently.
http://zonums.com/kml2shp.html to go from KML to SHP
http://zonums.com/shp2kml.html to go from SHP to KML
as the last post on this thread was over a year ago - i’m sure you all either already know about these or have a better solution by now. the rest of the site is filled with somewhat-GIS related goodness however.
Cheers to Mr. Zonums and to Perry* –j03
I second using the MapWindow plugin, Shape2Earth. I’ve used it successfully many times before.
Now there’s GeoCommons Finder: http://finder.geocommons.com, an online service that accepts geodata in multiple formats, or tables in CSV format and will export in KML among others.
Excellent help, thanks greatly Perry- with this simple, straightforward help I was able to map out all the registered quarries in NSW in google earth, and zoom in to check their status- thanks again!
The Zonums tools shp2kml and kml2shp were incredible tools. Unfortunately they have a license that expires and requires downloading the latest version from Zonums.com; now these tools won’t download.