Wednesday, September 02, 2009

ShapeFile to KML

Quick, easy and free way to get from shapefile to KML – use Shp2KML. Shp2Kml works well but fails when the shapefile has a projection that is different from lat/lon or UTM.

image

In this case use FWTool’s Ogr2Ogr.

ogr2ogr -t_srs EPSG:4326 -f KML outPutFileName.kml inPutFileName.shp

More information about using ogr2ogr:

To get all the attributes in the shape file use OgrInfo:
ogrinfo ParkNRides.shp -al -fid 0
the above command outputs all the fields associated with the shape with ID 0. This will give us a list of attributes in the shapefile.

Next use the following command to output the fields with the KML file:

ogr2ogr –SELECT “field1 field2 field3” -t_srs EPSG:4326 -f KML outPutFileName.kml inPutFileName.shp

No comments: