def exit_dialog(self, points, crs): self.dialog.close() layer = QgsVectorLayer('LineString', self.name_tracado, "memory") pr = layer.dataProvider() print points anterior = QgsPoint(points[0]) fets = [] for p in points[1:]: fet = QgsFeature(layer.pendingFields()) fet.setGeometry(QgsGeometry.fromPolyline([anterior, QgsPoint(p)])) fets.append(fet) anterior = QgsPoint(p) pr.addFeatures(fets) self.crs = crs layer.setCrs(QgsCoordinateReferenceSystem(int(crs), 0)) layer.updateExtents() QgsMapLayerRegistry.instance().addMapLayer(layer)
def plotar(self): vl = QgsVectorLayer("Point", "temporary_points", "memory") pr = vl.dataProvider() # Enter editing mode vl.startEditing() # add fields pr.addAttributes([ QgsField("estaca", QVariant.String), QgsField("descrição", QVariant.String), QgsField("north", QVariant.String), QgsField("este", QVariant.String), QgsField("cota", QVariant.String), QgsField("azimite", QVariant.String) ]) fets = [] for r in range(self.tableWidget.rowCount()): ident = self.tableWidget.item(r, 0).text() if ident in ["", None]: break fet = QgsFeature(vl.pendingFields()) n = 0.0 e = 0.0 try: es = self.tableWidget.item(r, 0).text() d = self.tableWidget.item(r, 1).text() n = float(self.tableWidget.item(r, 3).text()) e = float(self.tableWidget.item(r, 4).text()) c = float(self.tableWidget.item(r, 5).text()) a = self.tableWidget.item(r, 6).text() except: break fet.setGeometry(QgsGeometry.fromPoint(QgsPoint(e, n))) fet.setAttributes([es, d, n, e, c, a]) fets.append(fet) pr.addFeatures(fets) vl.commitChanges() QgsMapLayerRegistry.instance().addMapLayer(vl)