-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from QGEP/inverseReaches
Add processing algorithm to reverse reaches
- Loading branch information
Showing
2 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
/*************************************************************************** | ||
QGEP processing provider | ||
------------------- | ||
begin : 18.11.2017 | ||
copyright : (C) 2017 by OPENGIS.ch | ||
email : [email protected] | ||
***************************************************************************/ | ||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
""" | ||
|
||
from qgis.core import ( | ||
QgsExpression, | ||
QgsFeatureRequest, | ||
QgsGeometry, | ||
QgsProcessingAlgorithm, | ||
QgsProcessingParameterNumber, | ||
QgsProcessingParameterBoolean, | ||
QgsProcessingParameterVectorLayer | ||
) | ||
|
||
from PyQt5.QtCore import QCoreApplication | ||
|
||
from .qgep_algorithm import QgepAlgorithm | ||
|
||
__author__ = 'Matthias Kuhn & Maxime Trolliet' | ||
__date__ = '2018-08-07' | ||
__copyright__ = '(C) 2018 by OPENGIS.ch' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
|
||
class ChangeReachDirection(QgepAlgorithm): | ||
""" | ||
Change the direction of the selected reaches | ||
""" | ||
|
||
REACH_LAYER = 'REACH_LAYER' | ||
|
||
|
||
def name(self): | ||
return 'change_direction' | ||
|
||
def displayName(self): | ||
return self.tr('Change reach direction') | ||
|
||
def flags(self): | ||
return super().flags() | QgsProcessingAlgorithm.FlagNoThreading | ||
|
||
def initAlgorithm(self, config=None): | ||
"""Here we define the inputs and output of the algorithm, along | ||
with some other properties. | ||
""" | ||
|
||
self.addParameter(QgsProcessingParameterVectorLayer(self.REACH_LAYER, description=self.tr( | ||
'Selected features only - Reach layer, will be modified in place and its direction will be inverted'))) | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
"""Here is where the processing itself takes place.""" | ||
reach_layer = self.parameterAsVectorLayer(parameters, self.REACH_LAYER, context) | ||
|
||
reach_layer.startEditing() | ||
|
||
feature_count = 0 | ||
|
||
iterator = reach_layer.getSelectedFeatures() | ||
feature_count = reach_layer.selectedFeatureCount() | ||
|
||
# Loop through relevant reaches | ||
reach_layer.beginEditCommand('change directions') | ||
transaction = reach_layer.dataProvider().transaction() | ||
#if not transaction: | ||
# raise Exception: if there is no transaction, complain to the user! | ||
selected_obj_ids = [feature['obj_id'] for feature in iterator] | ||
transaction.executeSql('SELECT qgep_od.reach_direction_change(\'{{{obj_ids}}}\');'.format(obj_ids=','.join(selected_obj_ids))) | ||
reach_layer.endEditCommand() | ||
feedback.setProgress(100) | ||
|
||
return {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters