-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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 #6225 from alexbruy/processing-algs
[processing][needs-docs] use native syntax for Processing scripts
- Loading branch information
Showing
40 changed files
with
679 additions
and
1,606 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
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
python/plugins/processing/algs/examplescripts/ProcessingExampleScriptsPlugin.py
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
18 changes: 0 additions & 18 deletions
18
python/plugins/processing/algs/examplescripts/metadata.txt
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
python/plugins/processing/algs/examplescripts/scripts/examplescript.py
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,9 +1,4 @@ | ||
FILE(GLOB PY_FILES *.py) | ||
FILE(GLOB HELP_FILES help/*.rst) | ||
FILE(GLOB SCRIPT_FILES scripts/*.*) | ||
|
||
ADD_SUBDIRECTORY(ui) | ||
|
||
PLUGIN_INSTALL(processing algs/qgis ${PY_FILES}) | ||
PLUGIN_INSTALL(processing algs/qgis/help ${HELP_FILES}) | ||
PLUGIN_INSTALL(processing algs/qgis/scripts ${SCRIPT_FILES}) |
107 changes: 107 additions & 0 deletions
107
python/plugins/processing/algs/qgis/KeepNBiggestParts.py
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,107 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
""" | ||
*************************************************************************** | ||
KeepNBiggestParts.py | ||
--------------------- | ||
Date : July 2014 | ||
Copyright : (C) 2014 by Victor Olaya | ||
Email : volayaf 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__ = 'Victor Olaya' | ||
__date__ = 'July 2014' | ||
__copyright__ = '(C) 2014, Victor Olaya' | ||
|
||
# This will get replaced with a git SHA1 when you do a git archive | ||
|
||
__revision__ = '$Format:%H$' | ||
|
||
from operator import itemgetter | ||
|
||
|
||
from qgis.core import (QgsGeometry, | ||
QgsFeatureSink, | ||
QgsProcessing, | ||
QgsProcessingParameterFeatureSink, | ||
QgsProcessingParameterFeatureSource, | ||
QgsProcessingParameterNumber, | ||
) | ||
|
||
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm | ||
|
||
|
||
class KeepNBiggestParts(QgisAlgorithm): | ||
|
||
POLYGONS = 'POLYGONS' | ||
PARTS = 'PARTS' | ||
OUTPUT = 'OUTPUT' | ||
|
||
def group(self): | ||
return self.tr('Vector geometry') | ||
|
||
def groupId(self): | ||
return 'vectorgeometry' | ||
|
||
def __init__(self): | ||
super().__init__() | ||
|
||
def initAlgorithm(self, config=None): | ||
self.addParameter(QgsProcessingParameterFeatureSource(self.POLYGONS, | ||
self.tr('Polygons'), [QgsProcessing.TypeVectorPolygon])) | ||
self.addParameter(QgsProcessingParameterNumber(self.PARTS, | ||
self.tr('Parts to keep'), | ||
QgsProcessingParameterNumber.Integer, | ||
1, False, 1)) | ||
self.addParameter( | ||
QgsProcessingParameterFeatureSink(self.OUTPUT, self.tr('Parts'), QgsProcessing.TypeVectorPolygon)) | ||
|
||
def name(self): | ||
return 'keepnbiggestparts' | ||
|
||
def displayName(self): | ||
return self.tr('Keep N biggest parts') | ||
|
||
def processAlgorithm(self, parameters, context, feedback): | ||
source = self.parameterAsSource(parameters, self.POLYGONS, context) | ||
parts = self.parameterAsInt(parameters, self.PARTS, context) | ||
|
||
fields = source.fields() | ||
(sink, dest_id) = self.parameterAsSink(parameters, self.OUTPUT, context, | ||
source.fields(), source.wkbType(), source.sourceCrs()) | ||
|
||
features = source.getFeatures() | ||
total = 100.0 / source.featureCount() if source.featureCount() else 0 | ||
for current, feat in enumerate(features): | ||
if feedback.isCanceled(): | ||
break | ||
|
||
geom = feat.geometry() | ||
if geom.isMultipart(): | ||
out_feature = feat | ||
geoms = geom.asGeometryCollection() | ||
geom_area = [(i, geoms[i].area()) for i in range(len(geoms))] | ||
geom_area.sort(key=itemgetter(1)) | ||
if parts == 1: | ||
out_feature.setGeometry(geoms[geom_area[-1][0]]) | ||
elif parts > len(geoms): | ||
out_feature.setGeometry(geom) | ||
else: | ||
out_feature.setGeometry(geom) | ||
geomres = [geoms[i].asPolygon() for i, a in geom_area[-1 * parts:]] | ||
out_feature.setGeometry(QgsGeometry.fromMultiPolygonXY(geomres)) | ||
sink.addFeature(out_feature, QgsFeatureSink.FastInsert) | ||
else: | ||
sink.addFeature(feat, QgsFeatureSink.FastInsert) | ||
|
||
feedback.setProgress(int(current * total)) | ||
|
||
return {self.OUTPUT: dest_id} |
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
44 changes: 0 additions & 44 deletions
44
python/plugins/processing/algs/qgis/scripts/Keep_n_biggest_parts.py
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.