I'm creating a memory layer in QGis python and I need to match the geometry of the memory layer that I am building to the geometry of another layer.

After some investigation it seems to me that, as per QGIS 2.2 Documentation and the QGIS 2.2 API Documentation, the URI defining the geometry type approximately matches the QGis::WkbType member enumeration text.

I know I can easily query the WKBType of my input layer with


However, this returns an integer whereas the constructor requires text. Is there a simple built-in pyQGIS way to turn these constants into text or do I need to build a hacky little reverse mapping function for it?


QGis.WkbType is a sip wrapped enum class which doesn't have a reverse mapping function like it would if it were a native python enum.

So the answer i guess would be either to wrap the class in another class with the desired python enum attributes or to write a hacky little lookup function.

Rather than all the drama of writing a wrapping class - here's a stand alone dictionary and reverse map:

my_WkbType = { 'WKBUnknown': 0, 'WKBPoint':1, 'WKBLineString':2, 'WKBPolygon':3, 'WKBMultiPoint':4, 'WKBMultiLineString':5, 'WKBMultiPolygon':6, 'WKBNoGeometry':7, 'WKBPoint25D':8, 'WKBLineString25D':9, 'WKBPolygon25D':10, 'WKBMultiPoint25D':11, 'WKBMultiLineString25D':12, 'WKBMultiPolygon25D':13 }

my_rev_WkbType = {v:k for k, v in my_WkbType.items()}

To test it you can try:


Or in the context of the question:

  • qgis 3 has the following function: QgsWkbTypes.geometryDisplayString(int) – Mr Purple Jun 8 '19 at 5:04

this post is quite old, just stumbled upon it. To get a text representation to all available WkbTypes, i ended up using this:

dict([(v, k) for k, v in QgsWkbTypes.__dict__.items() if isinstance(v, int)])
  • Nice: much less hacky. Any chance of adding the line which would return the text for a memory layer based on the input layer as in my answer. If so I'll change to your answer as accepted. – Mr Purple Oct 28 '18 at 0:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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