Ejemplo n.º 1
0
    def __create_backup_file(self, orig_layer):

        file_name = self.backup_path + QDir.separator() + self.layer_id
        error = QgsVectorFileWriter.writeAsVectorFormat(orig_layer, file_name, "utf-8", None, "ESRI Shapefile",
                                                        False, None, list(), list(), True)
        if error == QgsVectorFileWriter.NoError:
            QgsMessageLog.logMessage(self.plugin.tr('Backup created.'), self.plugin.tr('Vertex Tools'),
                                    QgsMessageLog.INFO)
Ejemplo n.º 2
0
    def __restore_geometries(self):

        src_file_name = self.backup_path + QDir.separator() + self.layer_id + '.shp'
        if not QFile.exists(src_file_name):
            self.report_message.emit(self.layer_id, 'no backup file')
            self.completed = True
            return

        self.report_message.emit(self.layer_id, 'preparing ...')

        orig_layer = QgsMapLayerRegistry.instance().mapLayer(self.layer_id)
        # create a copy of the layer just for editing
        layer = QgsVectorLayer(orig_layer.source(), orig_layer.name(), orig_layer.providerType())
        layer.startEditing()
        src_layer = QgsVectorLayer(src_file_name, layer.name(), 'ogr')
        total_features = src_layer.featureCount()

        QgsMessageLog.logMessage(self.plugin.tr('Features to be restored in layer <{0}>: {1}').
                                 format(orig_layer.name(), total_features), self.plugin.tr('Vertex Tools'),
                                 QgsMessageLog.INFO)
        if total_features == 0:
            self.report_message.emit(self.layer_id, 'no features to restore')

        count = 0
        for feature in src_layer.getFeatures():
            with QMutexLocker(self.mutex):
                if self.stopped:
                    layer.rollBack()
                    return

            layer.changeGeometry(feature.id(), feature.geometry())

            count += 1
            self.run_progressed.emit(self.layer_id, count, total_features)

        layer.commitChanges()

        self.completed = True