In my previous post I described how to export a vector layer from GRASS GIS as kml file. The key was to use the dsco parameter to define the columns that should be used for the Name and Description fields in your kml file.
In QGIS you use the ‘save as’ option in QGIS. You can get this using the context menu (right click mouse on the layer) or the menu ‘Layer | Save as..’. In the menu that opens, there are two fields under the header ‘OGR creation options’; ‘Data source’ and ‘Layer’.
In the ‘Data source’ field, you can define which columns you want to use to fill the Name and Description fields in your kml file. You do this by defining the NameField and the DescriptionField. For example, NameField=PNVname and DescriptionField=PNVcode.
Note in the example above that each option should be entered on a new line.
Like in the v.out.ogr function in GRASS GIS, the ‘save as’ function in QGIS offers an interface to the underlying OGR library; and more specifically to the ogr2ogr function. The dsco parameter (OGR creation options) are format specific, here is a more detailed explanation when exporting to KML format. For other formats, see here.
One potential problem I just noticed is that all fields in the attribute table of the original vector layer are exported to the kml layer as ExtendedData. QGIS ignores this data when you open the attribute table of the kml file. But you can see the extended data is there when opening the kml file in a text editor or Google earth. If you do not need this information to be included in your kml file, better remove it as it adds to the size of your kml file. You can delete the extended data using the following grep statement on the command line:
grep -Ev ‘<SimpleData|ExtendedData>|SchemaData’ doc.kml >> doc2.kml
Here, grep returns all lines in doc.kml to the new file doc2.kml, except those lines containing the text ‘<SimpleData’, ‘ExtendedData>’ or ‘SchemaData’, which are all lines defining the extended data.
Edit: The OGR function ogr2ogr does offer the option to define which columns/ fields from the input layer should be included in the new layer. See also this question on the GIS stack exchange site.

Pingback: Exporting point file as kml in GRASS GIS | Ecostudies