mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-10-31 00:06:02 -04:00 
			
		
		
		
	Instead of returning a single QgsFeature from processFeature, we now return a list of features. This allows feature based algorithms which return multiple features per input feature, e.g. "explode" type algorithms which split a single input feature into multiple output features.
		
			
				
	
	
		
			71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			71 lines
		
	
	
		
			2.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| # -*- coding: utf-8 -*-
 | |
| 
 | |
| """
 | |
| ***************************************************************************
 | |
|     ReverseLineDirection.py
 | |
|     -----------------------
 | |
|     Date                 : November 2015
 | |
|     Copyright            : (C) 2015 by Nyall Dawson
 | |
|     Email                : nyall dot dawson at gmail dot com
 | |
| ***************************************************************************
 | |
| *                                                                         *
 | |
| *   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.                                   *
 | |
| *                                                                         *
 | |
| ***************************************************************************
 | |
| """
 | |
| 
 | |
| __author__ = 'Nyall Dawson'
 | |
| __date__ = 'November 2015'
 | |
| __copyright__ = '(C) 2015, Nyall Dawson'
 | |
| 
 | |
| # This will get replaced with a git SHA1 when you do a git archive323
 | |
| 
 | |
| __revision__ = '$Format:%H$'
 | |
| 
 | |
| from qgis.core import (QgsGeometry,
 | |
|                        QgsProcessingException,
 | |
|                        QgsProcessing)
 | |
| from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
 | |
| 
 | |
| 
 | |
| class ReverseLineDirection(QgisFeatureBasedAlgorithm):
 | |
| 
 | |
|     def group(self):
 | |
|         return self.tr('Vector geometry')
 | |
| 
 | |
|     def groupId(self):
 | |
|         return 'vectorgeometry'
 | |
| 
 | |
|     def __init__(self):
 | |
|         super().__init__()
 | |
| 
 | |
|     def name(self):
 | |
|         return 'reverselinedirection'
 | |
| 
 | |
|     def displayName(self):
 | |
|         return self.tr('Reverse line direction')
 | |
| 
 | |
|     def outputName(self):
 | |
|         return self.tr('Reversed')
 | |
| 
 | |
|     def outputType(self):
 | |
|         return QgsProcessing.TypeVectorLine
 | |
| 
 | |
|     def inputLayerTypes(self):
 | |
|         return [QgsProcessing.TypeVectorLine]
 | |
| 
 | |
|     def processFeature(self, feature, context, feedback):
 | |
|         if feature.geometry():
 | |
|             inGeom = feature.geometry()
 | |
|             reversedLine = inGeom.constGet().reversed()
 | |
|             if not reversedLine:
 | |
|                 raise QgsProcessingException(
 | |
|                     self.tr('Error reversing line'))
 | |
|             outGeom = QgsGeometry(reversedLine)
 | |
| 
 | |
|             feature.setGeometry(outGeom)
 | |
|         return [feature]
 |