You are looking for a way to have the type of geometry in the string and after multiple searches, finally found a clean method in the documents:
geomTypeString=qgis.core.QgsWKBTypes.displayString(int(layer.wkbType()))
which will give "Point", "LineString", "Polygon", "MultiPoint" .... and he "knows" all types of geometry in Qgis.
For my purpose, I still had problems with "Point25D" and other weird types, so I added this to limit them to flat (Point, Line, Poly)
geomFlatTypeString=qgis.core.QgsWKBTypes.displayString(int( qgis.core.QgsWKBTypes.flatType(int(in_layer.wkbType()))))
For information, the goal was a method that duplicates a memory layer for any type, here is the complete code:
def copyLayer(in_layer,condition=None): #condition=function to test features and return True or False______ if condition==None: def condition(f): return True typeGeom=qgis.core.QgsWKBTypes.displayString(int( qgis.core.QgsWKBTypes.flatType(int(in_layer.wkbType())))) crsId=in_layer.crs().authid() out_layer=QgsVectorLayer(typeGeom+"?crs="+crsId, in_layer.name()+"_copie", "memory") fields=in_layer.dataProvider().fields().toList() out_layer.dataProvider().addAttributes(fields) out_layer.updateFields() features=[f for f in in_layer.getFeatures() if condition(f)] out_layer.dataProvider().addFeatures(features) return out_layer
source share