How to convert a shapefile to WKT?

Well Known Text is not meant for saving layers like shape files that consists of many objects. WKT defines how to represent geometry of one object. That geometry could be single or multi part. Multi part geometries mean that geometry of one object consists of many parts. For example Hawaiian Islands could be represented as one object but it consists of many geometries.

Shape file is a collection of these kinds of objects. Objects usually have also some attribute information that is also part of a shape file.

Your ogr2ogr approach converts these objects to csv format with WKT geometry (and text representations of the attributes). If you really want to combine all the geometries to one MULTIPOLYGON you have to first convert all the objects to one multi geometry. You can do that in QGIS. Select from Vector menu Geometry Tools and then Singleparts to Multiparts. Then you can convert that to wkt with ogr2ogr.

Hopefully this makes sense.


I wrote a QGIS plugin that saves immediately the active layer to a .wkt file.

The name of the plugin is "WktExport". You can search for it in the default QGIS plugin panel.

BTW, the link to the plugin page is this:

https://plugins.qgis.org/plugins/wktexport/

"WktExport" plugin for QGIS creates a folder, named "WktExport" where the original SHP is, and insert in the folder a .wkt file containing the elements in WKT ascii format of all objects of SHP (but also KML, or other original file format).

The name of the .wkt has inside the date and time of saving, so saving it many times, you will have many versions of the same file.

This could be useful to create animations of a carthographic working progress or to document the current status of a file.

Please, send a message to the list qgis-developer, especially if you find wktexport useful.