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

OutbackDirect.co.uk is a trading site of World of Power.co.uk Limited. Outback Direct is the official Outback Consumer Warranty, Parts and Accessory Partners for the UK. We currently hold in stock 1000’s of parts and accessories for current and older Outback barbecues. We endeavour to ensure rapid and secure product delivery the length and breadth of mainland United Kingdom, this factor coupled with our excellent customer service has led to the market position we currently enjoy.
outback barbecue
omega 300 gas barbecue
Omega 250 Gas Hooded BBQ
Blog
Blog
------------------------------------------------------------ Silver Sky Imports is a unique online marketplace that offers unique handicrafts from Tibet and Nepal. Launched in 2003, Silver Sky Imports is currently the largest supplier of handmade items from the Himalayas. We specialize in the largest variety of Tibetan Singing Bowls and Crystal Singing Bowls online and include individual sound samples, pictures and descriptions for each bowl. Some of our other products include Tibetan Prayer Flags, Tingshas, Bell and Dorje, Incense, Felted Wool Handbags, Wood Masks, Prayer Wheels, Gongs, Bronze Statues, and Tibetan Meditation Rugs. monks
Blog
------------------------------------------------------------ Airpush, a mobile ad network that is only two years old, has quickly grown to one with over 5,000 advertisers. One thing they've heard from that sea of advertisers over the past 12 months, and especially over the past six, is that real-time bidding (RTB) capabilities are now a must. To answer those needs, the company today unveiled AirDSP, a platform meant to easily connect advertisers to RTB exchanges. Read more: Mobile RTB
Blog
Blog
------------------------------------------------------------ Danish site about electronic cigarettes E Cigarette, Electronic Cigarette and E Cigarettes e cigaret
------------------------------------------------------------ DrugRisks.com drugrisk​ recall ​informat​ion​ drugrisk​ yaz​
------------------------------------------------------------