def init_state(self):
     dirname = os.path.dirname(__file__)
     layer = QgsProject.instance().mapLayersByName('copy_energy_plant')[0]
     if layer.featureCount() < NUMB_ENERGY_PLANT:
         filename = os.path.join(dirname,
                                 'dataset/global_power_plant_database.csv')
         layer.startEditing()
         with open(filename, 'r') as file:
             reader = csv.reader(file)
             for i, row in enumerate(reader):
                 if i > 0 and row[7] == "Nuclear":
                     pr = layer.dataProvider()
                     # insert in attribute table
                     poly = QgsFeature(layer.fields())
                     poly.setAttribute("Country", row[0])
                     poly.setAttribute("count_long", row[1])
                     poly.setAttribute("name", row[2])
                     poly.setAttribute("qppd_idnr", row[3])
                     poly.setAttribute("cap_mw", row[4])
                     poly.setAttribute("latitude", row[5])
                     poly.setAttribute("longitude", row[6])
                     poly.setAttribute("Radiation", random.randint(1, 200))
                     poly.setGeometry(
                         QgsGeometry.fromPointXY(
                             QgsPointXY(float(row[6]), float(row[5]))))
                     pr.addFeatures([poly])
             layer.updateExtents()
             layer.commitChanges()
             layer.reload()
Exemplo n.º 2
0
 def geometry(self):
     if self.geom.type() == QgsWkbTypes.PointGeometry:
         x = float(self.xedit.text())
         y = float(self.yedit.text())
         return QgsGeometry.fromPointXY(QgsPoint(x, y))