27
27
28
28
import os
29
29
30
- from qgis .core import QgsGeometry , QgsWkbTypes , QgsProcessingUtils
30
+ from qgis .core import (QgsGeometry ,
31
+ QgsWkbTypes ,
32
+ QgsProcessingUtils ,
33
+ QgsProcessingParameterVectorLayer ,
34
+ QgsProcessingParameterOutputVectorLayer ,
35
+ QgsProcessingOutputVectorLayer )
31
36
32
37
from qgis .PyQt .QtGui import QIcon
33
38
34
- from processing .algs .qgis import QgisAlgorithm
39
+ from processing .algs .qgis . QgisAlgorithm import QgisAlgorithm
35
40
from processing .core .GeoAlgorithmExecutionException import GeoAlgorithmExecutionException
36
41
from processing .core .parameters import ParameterVector
37
42
from processing .core .outputs import OutputVector
@@ -45,27 +50,33 @@ class Boundary(QgisAlgorithm):
45
50
INPUT_LAYER = 'INPUT_LAYER'
46
51
OUTPUT_LAYER = 'OUTPUT_LAYER'
47
52
53
+ def __init__ (self ):
54
+ super ().__init__ ()
55
+ self .addParameter (QgsProcessingParameterVectorLayer (self .INPUT_LAYER , self .tr ('Input layer' )))
56
+
57
+ self .addParameter (QgsProcessingParameterOutputVectorLayer (self .OUTPUT_LAYER , self .tr ('Boundary' )))
58
+
59
+ self .addOutput (QgsProcessingOutputVectorLayer (self .OUTPUT_LAYER , self .tr ("Boundaries" )))
60
+
61
+ # self.addParameter(ParameterVector(self.INPUT_LAYER,
62
+ # self.tr('Input layer'), [dataobjects.TYPE_VECTOR_LINE,
63
+ # dataobjects.TYPE_VECTOR_POLYGON]))
64
+ # self.addOutput(OutputVector(self.OUTPUT_LAYER, self.tr('Boundary')))
65
+
48
66
def icon (self ):
49
67
return QIcon (os .path .join (pluginPath , 'images' , 'ftools' , 'convex_hull.png' ))
50
68
51
69
def group (self ):
52
70
return self .tr ('Vector geometry tools' )
53
71
54
- def __init__ (self ):
55
- super ().__init__ ()
56
- self .addParameter (ParameterVector (self .INPUT_LAYER ,
57
- self .tr ('Input layer' ), [dataobjects .TYPE_VECTOR_LINE ,
58
- dataobjects .TYPE_VECTOR_POLYGON ]))
59
- self .addOutput (OutputVector (self .OUTPUT_LAYER , self .tr ('Boundary' )))
60
-
61
72
def name (self ):
62
73
return 'boundary'
63
74
64
75
def displayName (self ):
65
76
return self .tr ('Boundary' )
66
77
67
78
def processAlgorithm (self , parameters , context , feedback ):
68
- layer = QgsProcessingUtils . mapLayerFromString ( self .getParameterValue ( self .INPUT_LAYER ) , context )
79
+ layer = self .parameterAsLayer ( parameters , self .INPUT_LAYER , context )
69
80
70
81
input_wkb = layer .wkbType ()
71
82
if QgsWkbTypes .geometryType (input_wkb ) == QgsWkbTypes .LineGeometry :
@@ -77,8 +88,8 @@ def processAlgorithm(self, parameters, context, feedback):
77
88
if QgsWkbTypes .hasM (input_wkb ):
78
89
output_wkb = QgsWkbTypes .addM (output_wkb )
79
90
80
- writer = self .getOutputFromName (
81
- self . OUTPUT_LAYER ). getVectorWriter ( layer .fields (), output_wkb , layer .crs (), context )
91
+ dest = self .parameterAsString ( parameters , self . OUTPUT_LAYER , context )
92
+ ( writer , dest_layer ) = QgsProcessingUtils . createFeatureSink ( dest , '' , layer .fields (), output_wkb , layer .crs (), context )
82
93
83
94
features = QgsProcessingUtils .getFeatures (layer , context )
84
95
total = 100.0 / QgsProcessingUtils .featureCount (layer , context )
@@ -97,4 +108,4 @@ def processAlgorithm(self, parameters, context, feedback):
97
108
writer .addFeature (output_feature )
98
109
feedback .setProgress (int (current * total ))
99
110
100
- del writer
111
+ return { self . OUTPUT_LAYER : dest_layer }
0 commit comments