I changed the code to create a convexhull for selected features from this question (Convexhull for selected features and performing buffer for the resultant convexhull using python) to adapt it to QGIS3, but something does not work. Where is the problem?
layer = iface.activeLayer() feat = layer.selectedFeatures() geom = feat.geometry() convexhull = geom.convexHull() CRS = layer.crs().postgisSrid() URI = "Polygon?crs=epsg:"+str(CRS)+"&field=id:integer""&index=yes" mem_layer = QgsVectorLayer(URI,"convexhull","memory") mem_layer.startEditing() feat2 = QgsFeature() feat2.setGeometry(convexhull) feat2.setAttributes() mem_layer.addFeature(feat2, True) mem_layer.commitChanges() QgsProject.instance().addMapLayers([mem_layer]) iface.mapCanvas().refresh()
EDIT: To be more clear, using this code this is what I get. It's a convexhull for just one feature.
And this is what I want. It's for all selected features. I reached this using Minimum bounding geometry from processing toolbox.