shp snippets

How to Convert SHP to KML with GDAL

Tagged shp, kml, gdal  Languages bash

After reading Google's advice on the matter we add the following to ~/.bash_profile (see GDAL ReadMe.rtf for details):

export PATH=/Library/Frameworks/GDAL.framework/Programs:$PATH

We can now convert SHP file to KML:

ogr2ogr -f “KML" -where “qs_adm0_a3=’FIN’" ~/Downloads/xxx.kml ~/Downloads/qs_adm1_region/qs_adm1_region.shp

ogr2ogr -f “KML" -where “qs_adm0=’Finland’" ~/Downloads/xxx.kml ~/Downloads/qs_adm1_region/qs_adm1_region.shp

ogr2ogr -f “KML" -where “qs_adm0=’Finland’ and qs_level=’adm1_region’" ~/Downloads/xxx.kml ~/Downloads/qs_adm1_region/qs_adm1_region.shp

ogr2ogr -f “KML" ~/Downloads/all.kml ~/Downloads/qs_adm1_region/qs_adm1_region.shp

Notice the "where" query. It pulls out data from the XML file where the SimpleData tag matches your query:

<SimpleData name="qs_adm0_a3">BEL</SimpleData>

Render the data with with Python, TileMill, or QuantumGis