4 ***************************************************************************
8 Copyright : (C) 2013 by Victor Olaya
9 Email : volayaf at gmail dot com
10 ***************************************************************************
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
17 ***************************************************************************
20 __author__ =
'Victor Olaya'
21 __date__ =
'July 2013'
22 __copyright__ =
'(C) 2013, Victor Olaya'
24 __revision__ =
'$Format:%H$'
32 from processing.core.Processing
import Processing
33 from processing.core.GeoAlgorithm
import GeoAlgorithm
34 from processing.core.QGisLayers
import QGisLayers
36 from processing.parameters.ParameterVector
import ParameterVector
38 from processing.outputs.OutputVector
import OutputVector
42 '''This is an example algorithm that takes a vector layer and creates
43 a new one just with just those features of the input layer that are
46 It is meant to be used as an example of how to create your own
47 algorithms and explain methods and variables used to do it. An algorithm
48 like this will be available in all elements, and there is not need
51 All processing algorithms should extend the GeoAlgorithm class.
57 OUTPUT_LAYER =
"OUTPUT_LAYER"
58 INPUT_LAYER =
"INPUT_LAYER"
61 '''Here we define the inputs and output of the algorithm, along
62 with some other properties
66 self.
name =
"Create copy of layer"
69 self.
group =
"Algorithms for vector layers"
73 self.addParameter(ParameterVector(self.
INPUT_LAYER,
"Input layer", [ParameterVector.VECTOR_TYPE_ANY],
False))
76 self.addOutput(OutputVector(self.
OUTPUT_LAYER,
"Output layer with selected features"))
79 '''Here is where the processing itself takes place'''
83 inputFilename = self.getParameterValue(self.
INPUT_LAYER)
89 vectorLayer = QGisLayers.getObjectFromUri(inputFilename)
95 settings = QSettings()
96 systemEncoding = settings.value(
"/UI/encoding",
"System" )
97 provider = vectorLayer.dataProvider()
98 writer = QgsVectorFileWriter(output,
101 provider.geometryType(),
109 features = QGisLayers.features(vectorLayer)