![]() If a parameter depends on another parameter, parentParameterName INPUT and OUTPUT are recommended names for the main input and Here we define the inputs and outputs of the algorithm. Returns a localised short help string for the algorithm. Returns the unique ID of the group this algorithm belongs to. Returns the name of the group this algorithm belongs to. Returns the unique algorithm name, used for identifying the algorithm. If you change the name of the class, make sure you also update the value Must return a new copy of your algorithm. parameterAsDouble ( parameters, 'CELLSIZE', 130 context ) 131 if feedback. parameterAsDouble ( parameters, 'BUFFERDIST', 128 context ) 129 rastercellsize = self. Since these are numeric values, they are retrieved 126 # using self.parameterAsDouble. featureCount () 123 124 # Retrieve the buffer distance and raster cell size numeric 125 # values. parameterAsSource ( parameters, 120 'INPUT', 121 context ) 122 numfeatures = input_featuresource. 116 # This layer is defined as a QgsProcessingParameterFeatureSource 117 # parameter, so it is retrieved by calling 118 # self.parameterAsSource. 114 """ 115 # First, we get the count of features from the INPUT layer. tr ( 'Number of features processed' ) 108 ) 109 ) 110 111 def processAlgorithm ( self, parameters, context, feedback ): 112 """ 113 Here is where the processing itself takes place. addOutput ( 105 QgsProcessingOutputNumber ( 106 'NUMBEROFFEATURES', 107 self. addParameter ( 97 QgsProcessingParameterDistance ( 98 'CELLSIZE', 99 self. tr ( 'BUFFERDIST' ), 91 defaultValue = 1.0, 92 # Make distance units match the INPUT layer units: 93 parentParameterName = 'INPUT' 94 ) 95 ) 96 self. addParameter ( 88 QgsProcessingParameterDistance ( 89 'BUFFERDIST', 90 self. tr ( 'Raster output' ) 85 ) 86 ) 87 self. addParameter ( 82 QgsProcessingParameterRasterDestination ( 83 'OUTPUT', 84 self. tr ( 'Buffer output' ), 77 ) 78 ) 79 # 'OUTPUT' is the recommended name for the main output 80 # parameter. addParameter ( 74 QgsProcessingParameterVectorDestination ( 75 'BUFFER_OUTPUT', 76 self. tr ( 'Input vector layer' ), 70 types = 71 ) 72 ) 73 self. addParameter ( 67 QgsProcessingParameterFeatureSource ( 68 'INPUT', 69 self. 63 """ 64 # 'INPUT' is the recommended name for the main input 65 # parameter. tr ( 'Example algorithm short description' ) 59 60 def initAlgorithm ( self, config = None ): 61 """ 62 Here we define the inputs and outputs of the algorithm. 51 """ 52 return 'examplescripts' 53 54 def shortHelpString ( self ): 55 """ 56 Returns a localised short help string for the algorithm. tr ( 'Example scripts' ) 46 47 def groupId ( self ): 48 """ 49 Returns the unique ID of the group this algorithm belongs 50 to. tr ( 'Buffer and export to raster (extend)' ) 40 41 def group ( self ): 42 """ 43 Returns the name of the group this algorithm belongs to. 32 """ 33 return 'bufferrasterextend' 34 35 def displayName ( self ): 36 """ 37 Returns the translated algorithm name. 27 return ExampleProcessingAlgorithm () 28 29 def name ( self ): 30 """ 31 Returns the unique algorithm name. translate ( 'Processing', string ) 24 25 def createInstance ( self ): 26 # Must return a new copy of your algorithm. 17 """ 18 19 def tr ( self, string ): 20 """ 21 Returns a translatable string with the () function. Returns the buffer layer, raster layer and number of featuresġ from import QCoreApplication 2 from re import ( QgsProcessing, 3 QgsProcessingAlgorithm, 4 QgsProcessingException, 5 QgsProcessingOutputNumber, 6 QgsProcessingParameterDistance, 7 QgsProcessingParameterFeatureSource, 8 QgsProcessingParameterVectorDestination, 9 QgsProcessingParameterRasterDestination ) 10 from qgis import processing 11 12 13 class ExampleProcessingAlgorithm ( QgsProcessingAlgorithm ): 14 """ 15 This is an example algorithm that takes a vector layer, 16 creates some new layers and returns some results. Extending QgsProcessingAlgorithm Ĭreates a raster layer from the result of the buffer operation py extension, the algorithm willīecome available in the Processing Toolbox. If you save the script in the scripts folder To simplify the task, you can start with a script template by usingĬreate new script from template from the same menu. To open the Processing Script Editor where you can write Scripts menu at the top of the Processing Toolbox Within QGIS, you can use Create new script in the There are two options for writing Processing algorithms using Python. Input and output types for Processing Algorithmsīest practices for writing script algorithms Best practices for writing script algorithms ![]() Input and output types for Processing Algorithms Writing new Processing algorithms as Python scripts Using processing algorithms from the console QGIS Desktop User Guide/Manual (QGIS 3.22).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |