from qgis.core import * import qgis.utils from qgis.PyQt.QtCore import QVariant fields = QgsFields() fields.append(QgsField("ID", QVariant.Int)) fields.append(QgsField("size", QVariant.Double)) fields.append(QgsField("name", QVariant.String)) fields.append(QgsField("okoli", QVariant.Int)) writer= QgsVectorFileWriter("/Users/karst/Downloads/t1.shp","CP1250",fields,QgsWkbTypes.Point,QgsCoordinateReferenceSystem(),"ESRI Shapefile") o=iface.activeLayer().getFeatures() n=0 ob=[] for i in o: ob.append(i) for i in ob: obec = i.geometry() fet = QgsFeature() fet.setGeometry(obec.centroid()) fet.setAttributes([n,i["POCET_OBYV"],i["NAZ_OBEC"]]) n=n+1 writer.addFeature(fet) del writer