Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to convert a shapefile into the simple Well Known Text (WKT) format in the example below (from http://en.wikipedia.org/wiki/Well-known_text).

MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)),
((20 35, 45 20, 30 5, 10 10, 10 30, 20 35),
(30 20, 20 25, 20 15, 30 20)))

I know that I use QGIS to save the shapefile as a CSV, and I can use ogr2ogr to do any numer of conversions. In fact ogr2ogr -f CSV out.wkt source.shp -lco GEOMETRY=AS_WKT gets me as close as I've come so far, but not quite there. Any suggestions?

p.s. As noted by Mapperz, this thread is very similar to this one. That thread, while it provided the ogr2ogr approach that I noted above, did not solve this particular challenge. The ogr2ogr output I'm getting looks like this (I've truncated the lines). Apparently, I just haven't figured out how to get ogr2ogr to use multipolygon.

"POLYGON ((-120.630531650950061 50.838562484449184, . . .
"POLYGON ((-123.206067372148397 51.038984074378327, . . .
share|improve this question
What is the problem with the ogr2ogr output? –  til_b Mar 19 '13 at 15:22
@til_b: addressed in edit. –  Gregory Mar 19 '13 at 15:40
Is your shape MULTIPOLYGON? –  Jürgen Zornig Mar 19 '13 at 16:04
@JürgenZornig: How can I tell? It would make sense for it to be a multipolygon, but I'd like to verify that. –  Gregory Mar 19 '13 at 17:34

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
That does make sense and I'll have a chance to try it shortly. –  Gregory Mar 19 '13 at 16:09
Okay, in QGIS, I used Vector/Geometry Tools/Single parts to multipart. I saved the output as a new shapefile, but when I loaded that file into QGIS it appears blank and the attribute table is completely empty (perhaps void would be a better description, as there are no headers, either). –  Gregory Mar 19 '13 at 17:30
Did you @pyrogerg select any unique field when the tool requested that? That means the tool "groups" all features that have the same value in that field. If you don't have any field that you want to unique you can just create one with Field calculator. You can access that from the attribute table. Make sure that the layer is in edit mode (pen icon). Then select the Field Calculator and "calculate" for example value 1 to every row of a new field. –  LauriK Mar 20 '13 at 6:48
+1 I took the liberty of further clarifying your edit by explicitly mentioning that the output will include the attributes. –  whuber Mar 20 '13 at 17:48

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.