How to convert shape file to kml file using GDAL utilities

I will show you in this article how you could convert shapefile (.shp) to KML file for use in Google Earth or Google Maps.  Many government entities release some portion of their GIS data for public use.  But many of them doesn’t provide them in .kml format.  Google Earth and Google Maps only works with .kml file.  There are many applications available for doing conversion, such as  Google Earth Proshp2kmlKML2KMLArc2Earth, and many others.   I used Geospatial Data Abstraction Library(GDAL) utilities, OGR , which is very simple command line utility to convert wide  variety of file types, including CSVPostGRES/PostGIS databases, and a variety of other formats.

You can download various boundary shape files like State, County, Congressional District, Zipcode from US Census website here..  It is free, reliable and accurate source available from US Census.

Let’s have the fun begin.

  • Download the .shp file that you need to convert to .kml file from US Census website.
  • Download and install GDAL utility from here.  I used gisinteranals sdk created by Tamas Szekeres which is listed under Windows section.  You can pick the latest release version from section “GDAL and MapServer latest release versions”.  Unzip the folder and run SDKShell.bat file which will open command prompt where we will type command to convert .shp file to .kml file.
  • Here is how you could convert zipcode boundary shape file to kml file.

ogr2ogr -f “KML” “c:kmlzipcode.kml” “c:shapefilezipcode.shp”

Little odd here is that output file comes first.  You can use -where clause to output only portion of shape file content to .kml.

That’s it.  It is so simple.  If this post really helps you, please click the Google +1 button to show it really helps you save your time.

Posted in Microsoft Technology Tagged with: ,
One comment on “How to convert shape file to kml file using GDAL utilities
  1. Eric Owens says:

    Hello,

    I am looking for all U.S. zip code data with corresponding polygon boundary data. At the U.S. Census site, they have multiple KML files that contain data like this:

    tract_01

    kml_1

    <![CDATA[Attributes
    NAME
    310

    GEOID
    01051031000
    ]]>

    This is great but I need to be able to map this data to a zip code. I would appreciate any help you could offer on this.

    Thanks

    Eric

1 Pings/Trackbacks for "How to convert shape file to kml file using GDAL utilities"
  1. […] :  I have posted article here about where to download shape file and how you could convert it to kml […]

Ads