2015-11-18 16:27:25 +11:00
|
|
|
# -*- 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$'
|
|
|
|
|
2017-07-16 20:48:05 +10:00
|
|
|
from qgis.core import (QgsGeometry,
|
|
|
|
QgsProcessingException,
|
2017-07-20 13:06:18 +10:00
|
|
|
QgsProcessing)
|
|
|
|
from processing.algs.qgis.QgisAlgorithm import QgisFeatureBasedAlgorithm
|
2015-11-18 16:27:25 +11:00
|
|
|
|
|
|
|
|
2017-07-20 13:06:18 +10:00
|
|
|
class ReverseLineDirection(QgisFeatureBasedAlgorithm):
|
2015-11-18 16:27:25 +11:00
|
|
|
|
2017-03-29 12:04:09 +10:00
|
|
|
def group(self):
|
|
|
|
return self.tr('Vector geometry tools')
|
|
|
|
|
2017-05-15 13:40:38 +10:00
|
|
|
def __init__(self):
|
|
|
|
super().__init__()
|
2017-07-10 16:31:14 +10:00
|
|
|
|
2017-03-29 12:51:59 +10:00
|
|
|
def name(self):
|
2017-03-29 17:09:39 +10:00
|
|
|
return 'reverselinedirection'
|
2017-03-29 12:51:59 +10:00
|
|
|
|
|
|
|
def displayName(self):
|
|
|
|
return self.tr('Reverse line direction')
|
2015-11-18 16:27:25 +11:00
|
|
|
|
2017-07-20 13:06:18 +10:00
|
|
|
def outputName(self):
|
|
|
|
return self.tr('Reversed')
|
2015-11-18 16:27:25 +11:00
|
|
|
|
2017-07-20 13:06:18 +10:00
|
|
|
def outputType(self):
|
|
|
|
return QgsProcessing.TypeVectorLine
|
2015-11-18 16:27:25 +11:00
|
|
|
|
2017-07-20 13:06:18 +10:00
|
|
|
def processFeature(self, feature, feedback):
|
|
|
|
if feature.geometry():
|
|
|
|
inGeom = feature.geometry()
|
|
|
|
reversedLine = inGeom.geometry().reversed()
|
|
|
|
if not reversedLine:
|
|
|
|
raise QgsProcessingException(
|
|
|
|
self.tr('Error reversing line'))
|
|
|
|
outGeom = QgsGeometry(reversedLine)
|
2015-11-18 16:27:25 +11:00
|
|
|
|
2017-07-20 13:06:18 +10:00
|
|
|
feature.setGeometry(outGeom)
|
|
|
|
return feature
|