I have this :

poly1 = ogr.CreateGeometryFromWkt(polygons)

and error :

Traceback (most recent call last):
  File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\code.py", line 90, in runcode
    exec(code, self.locals)
  File "<input>", line 1, in <module>
  File "C:\PROGRA~1\QGIS3~1.6\apps\Python37\lib\site-packages\osgeo\ogr.py", line 5666, in CreateGeometryFromWkt
    return _ogr.CreateGeometryFromWkt(*args, **kwargs)
TypeError: not a string
  • 3
    Could you clarify the issue further by editing the question. You say you have tried OG.CreateGeometryFromWkt (name_layer) and you have some WKT looking image (code is better) as a result. If your input was a shapefile then something has obviously worked. So what were you expecting? You also say you want to do an intersection on two shapefile layers, but that doesn't seem relevant to your code.
    – nmtoken
    Commented Sep 26, 2019 at 16:24

1 Answer 1


ConvertGeometryFromWkt creates a geometry from a WKT file. Your title suggests you are trying to create a WKT file - ie. the reverse operation.

The error makes sense in this context. WKT is a string (ie. text), and "polygons" isn't.

If you are trying to convert a shapefile into a WKT file, then the ogr2ogr command line utility is probably a better way of doing this. ogr2ogr is installed with the rest of GDAL/OGR - usually installed with QGis.

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