Created
April 25, 2018 08:30
-
-
Save ghtmtt/54b3253836c3b7aaff910006de091a91 to your computer and use it in GitHub Desktop.
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
# -*- coding: utf-8 -*- | |
from operator import itemgetter | |
from PyQt5.QtCore import QCoreApplication | |
from qgis.core import (QgsFeatureSink, | |
QgsProcessing, | |
QgsProcessingAlgorithm, | |
QgsProcessingParameterFeatureSink, | |
QgsProcessingParameterNumber, | |
QgsProcessingParameterFeatureSource | |
) | |
import processing | |
class QNorth(QgsProcessingAlgorithm): | |
INPUT = 'INPUT' | |
NUMBER = 'NUMBER' | |
OUTPUT = 'OUTPUT' | |
def init(self): | |
super().__init__() | |
def createInstance(self): | |
return QNorth() | |
def name(self): | |
return 'qnorth' | |
def tr(self, text): | |
return QCoreApplication.translate("qnorth", text) | |
def displayName(self): | |
return 'QNorth' | |
def group(self): | |
return 'My Scripts' | |
def groupId(self): | |
return 'myscripts' | |
def initAlgorithm(self, config = None): | |
self.addParameter(QgsProcessingParameterFeatureSource( | |
self.INPUT, | |
"Input layer", | |
[QgsProcessing.TypeVectorPoint] | |
) | |
) | |
self.addParameter( | |
QgsProcessingParameterNumber( | |
self.NUMBER, | |
self.tr('Distance'), | |
QgsProcessingParameterNumber.Integer, | |
10 | |
) | |
) | |
self.addParameter(QgsProcessingParameterFeatureSink( | |
self.OUTPUT, | |
"North point", | |
QgsProcessing.TypeVectorPoint | |
) | |
) | |
def processAlgorithm(self, parameters, context, feedback): | |
source = self.parameterAsSource(parameters, | |
self.INPUT, | |
context | |
) | |
distance = self.parameterAsInt( | |
parameters, | |
self.NUMBER, | |
context | |
) | |
(sink, dest_id) = self.parameterAsSink( | |
parameters, | |
self.OUTPUT, | |
context, | |
source.fields(), | |
source.wkbType(), | |
source.sourceCrs() | |
) | |
coords = [] | |
for f in source.getFeatures(): | |
coords.append(f.geometry().asPoint()) | |
maximum = max(coords,key=itemgetter(1)) | |
features = source.getFeatures() | |
for current, feat in enumerate(features): | |
if feat.geometry().asPoint() == maximum: | |
sink.addFeature(feat, QgsFeatureSink.FastInsert) | |
param = { | |
'INPUT': dest_id, | |
'DISTANCE': distance, | |
'SEGMENTS':5, | |
'END_CAP_STYLE':0, | |
'JOIN_STYLE':0, | |
'MITER_LIMIT':2, | |
'DISSOLVE':False, | |
'OUTPUT':'memory:' | |
} | |
buffer = processing.run("native:buffer", param) | |
return {self.OUTPUT: dest_id} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment