Skip to content

Workers

Worker

Source code in python\engine\workers.py
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
class Worker:
    logger = get_logger() 

    ## ##################################
    ## ATTRIBUTE WORKERS
    ## ##################################

    def extractByExpression(layer, expression):
        """
        Creates a vector layer from an input layer, containing only matching features.
        The criteria for adding features to the resulting layer is based on a QGIS expression.

        Parameters
        ----------
        layer : QgsVectorLayer
            The QgsVectorLayer that is used as input.

        expression : String
            Expression to filter the vector layer

        Returns
        -------
        QgsVectorLayer
            The QgsVectorLayer output layer.
        """
        logger.info("Extracting by expression")
        try:
            parameter = {
                'INPUT': layer,
                'EXPRESSION': expression,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:extractbyexpression', parameter)['OUTPUT']
            logger.info("Extractbyexpression  finished")
            return result
        except Exception as error:
            logger.error("An error occured in extractByExpression")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def addAutoIncrementalField(layer, fieldname, start):
        """
        Adds a new integer field to a vector layer, with a sequential value for each feature.
        This field can be used as a unique ID for features in the layer. The new attribute is not added to the input layer but a new layer is generated instead.
        The initial starting value for the incremental series can be specified. Optionally, the incremental series can be based on grouping 
        fields and a sort order for features can also be specified.

        Parameters
        ----------
        layer : QgsVectorLayer
            The QgsVectorLayer that is used as input.

        fieldname : String
            Name of the field with autoincremental values.

        start : Integer
            Choose the initial number of the incremental count, Default: 0.

        Returns
        -------
        QgsVectorLayer
            The QgsVectorLayer output layer.
        """
        logger.info("Adding incremental field")
        try:
            parameter = {
                'INPUT': layer,
                'FIELD_NAME': fieldname,
                'START':start,
                'MODULUS':0,
                'GROUP_FIELDS':[],
                'SORT_EXPRESSION':'',
                'SORT_ASCENDING':True,
                'SORT_NULLS_FIRST':False,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:addautoincrementalfield', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("addAutoIncrementalField  finished")
            return result
        except Exception as error:
            logger.error("An error occured in addAutoIncrementalField")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def deleteColumns (layer, columns):
        """
        Takes a vector layer and generates a new one that has the same features but without the selected columns.

        Parameters
        ----------
        layer : QgsVectorLayer
            Input vector layer to drop field(s) from

        columns : List of tablefields
            The field(s) to drop

        Returns
        -------
        QgsVectorLayer
            The QgsVectorLayer output layer.
        """
        logger.info("deleting fields")
        try:
            parameter = {
                'INPUT': layer,
                'COLUMN':columns,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:deletecolumn', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("deleteColumns  finished")
            return result
        except Exception as error:
            logger.error("An error occured in deleteColumns")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def fieldCalculator (layer, fieldname, fieldtype, fieldlength, fieldprecision, formula):
        """
        Scripting the field calcualtor
        You can use all the supported expressions and functions.
        The original layer is not modified. A new layer is generated where the attribute table contains the calucalted field
        QGIS processing algorithem: native:fieldcalculator

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        fieldname : String
            The name of the new calcualted field

        fieldtype : Enumeration
            Type of the field,  Default: 0  (0 — Float, 1 — Integer, 2 — String, 3 — Date)

        fieldlength : Integer
            Lenght of the field, Default: 10.

        fieldprecision : Integer
            Precision of the field, Default: 3.

        formula : Expression
            The expression that populates the values of the field.


        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem
        """
        logger.info("Calculating field")
        try:
            parameter = {
                'INPUT': layer,
                'FIELD_NAME': fieldname,
                'FIELD_TYPE': fieldtype,
                'FIELD_LENGTH': fieldlength,
                'FIELD_PRECISION': fieldprecision,
                'FORMULA': formula,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:fieldcalculator', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("fieldCalculator  finished")
            return result
        except Exception as error:
            logger.error("An error occured in fieldCalculator")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def timeStamper(layer, ts_fieldname):
        """
            Create an attribute woth current timestamp on features.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        ts_fieldname : String
            The name of the new timestamp field

        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem
        """
        logger.info(f'Creating timestamp {ts_fieldname} using fieldCalculator')
        newLayer = Worker.fieldCalculator(layer, ts_fieldname, 5, 0, 0, ' now() ')
        return newLayer

    def renameTableField (layer, field, newname):
        """
        Renames an existing field from a vector layer.  
        The original layer is not modified. A new layer is generated where the attribute table contains the renamed field.
        QGIS processing algorithem: native:renametablefield

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        field : Tablefield
            The field that is to be renamed

        newname : String
            New name for the field


        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem
        """
        logger.info("Renaming field")
        try:
            parameter = {
                'INPUT': layer,
                'FIELD': field,
                'NEW_NAME': newname,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:renametablefield', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("renameTableField  finished")
            return result
        except Exception as error:
            logger.error("An error occured in renameTableField")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def attributeindex(layer, field):
        """
        Creates an index to speed up queries made against a field in a table.
        Support for index creation is dependent on the layer's data provider and the field type.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        field : Field
            The field to base the index on

        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem
        """
        logger.info("Crating attribute index on " + layer + " on filed " + field)
        try:
            parameter = {
                'INPUT': field,
                'FIELD': field,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:createattributeindex', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("createattributeindex  finished")
            return result
        except Exception as error:
            logger.error("An error occured in createattributeindex")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()


    def spatialindex(layer):
        """
        Creates an index to speed up access to the features in a layer based on their spatial location.
        Support for spatial index creation is dependent on the layer's data provider.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem
        """

        logger.info("Crating spatial index on " + layer)
        try:
            parameter = {
                'INPUT': field,
                'OUTPUT': 'memory:extracted'
            }
            result = processing.run('native:createspatialindex', parameter)['OUTPUT']
            logger.info(f'Parameters: {str(parameter)}')
            logger.info("createspatialindex  finished")
            return result
        except Exception as error:
            logger.error("An error occured in createspatialindex")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    ## ##################################
    ## ANALYSIS WORKERS
    ## ##################################

    def clip(layer, overlay):
        """
        Clips a vector layer using the features of an additional polygon layer.
        Only the parts of the features in the input layer that fall within the polygons of 
        the overlay layer will be added to the resulting layer.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            Layer containing the features to be clipped

        overlay : [vector: polygon]
            Layer containing the clipping features

        Returns
        -------
        Qgsvectorlayer [vector: any]
            Layer to contain the features from the input layer that are inside the overlay (clipping) layer
        """
        logger.info("Clipping layers")
        try:
            parameter = {
                'INPUT': layer,
                'OVERLAY': overlay,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:clip', parameter)['OUTPUT']
            logger.info("Clip  finished")
            return result
        except Exception as error:
            logger.error("An error occured in Clip")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def joinByLocation(layer, predicate, join, join_fields, method, discard_nomatching, prefix):
        """
        Takes an input vector layer and creates a new vector layer that is an extended version of
        the input one, with additional attributes in its attribute table.
        The additional attributes and their values are taken from a second vector layer.
        A spatial criteria is applied to select the values from the second layer that are added to each 
        feature from the first layer.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            Input vector layer. 
            The output layer will consist of the features of this layer with attributes from 
            matching features in the second layer.

        predicate : [enumeration] [list] Default: [0]
            Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of:
            0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

        join : [vector: any]
            The join layer. 
            Features of this vector layer will add their attributes to the source layer attribute table if 
            they satisfy the spatial relationship.

        join_fields : [tablefield: any] [list]
            Select the specific fields you want to add from the join layer. 
            By default all the fields are added.

        method : [enumeration]           	
            The type of the final joined layer. One of: 
            0 — Create separate feature for each matching feature (one-to-many)
            1 — Take attributes of the first matching feature only (one-to-one)
            2 — Take attributes of the feature with largest overlap only (one-to-one)

        discard_nomatching : [boolean] Default: False
            Remove from the output the input layer’s features which could not be joined

        prefix : [string]
            Add a prefix to joined fields in order to easily identify them and avoid field name collision

        Returns
        -------
        Qgsvectorlayer [vector: any]
            the output vector layer for the join.
        """
        logger.info("Clipping layers")
        try:
            parameter = {
                'INPUT': layer,
                'PREDICATE':predicate,
                'JOIN':join,
                'JOIN_FIELDS':join_fields,
                'METHOD':method,
                'DISCARD_NONMATCHING':discard_nomatching,
                'PREFIX':prefix,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:joinattributesbylocation', parameter)['OUTPUT']
            logger.info("joinByLocation finished")
            return result
        except Exception as error:
            logger.error("An error occured in joinByLocation")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def extractByLocation(layer, predicate, intersect):
        """_summary_

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            Input vector layer. 

        predicate : [enumeration] [list] Default: [0]
            Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of:
            0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

        intersect : Qgsvectorlayer [vector: any]
            Intersection vector layer

        Returns
        -------
        Qgsvectorlayer [vector: any]
            the output vector layer for the join.
        """
        logger.info("Extracting by location")
        try:
            parameter = {
                'INPUT': layer,
                'PREDICATE':predicate,
                'INTERSECT':intersect,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:extractbylocation', parameter)['OUTPUT']
            logger.info("extractByLocation finished")
            return result
        except Exception as error:
            logger.error("An error occured in extractByLocation")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def randomExtract(layer, method, number):
        """
        Takes a vector layer and generates a new one that contains only a subset of the features in the input layer.
        The subset is defined randomly, based on feature IDs, using a percentage or count value to define 
        the total number of features in the subset.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            Input vector layer. 

        method : _type_
            _description_

        number : [enumeration] Default: 0
            Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

        Returns
        -------
        Qgsvectorlayer [vector: polygon/line]
            The result output from the algorithem
        """
        logger.info("Extracting random features")
        try:
            parameter = {
                'INPUT': layer,
                'METHOD':method,
                'NUMBER':number,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:randomextract', parameter)['OUTPUT']
            logger.info("randomExtract finished")
            return result
        except Exception as error:
            logger.error("An error occured in randomExtract")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def difference(layer, overlay):
        """
        Extracts features from the input layer that don’t fall within the boundaries of the overlay layer.
        Input layer features that partially overlap the overlay layer feature(s) are split along the 
        boundary of those feature(s.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            Layer to extract (parts of) features from.

        overlay : Qgsvectorlayer [vector: any]
            Layer containing the geometries that will be subtracted from the iniput layer geometries

        Returns
        -------
        Qgsvectorlayer [vector: polygon/line]
            The result output from the algorithem
        """
        logger.info("Finding differences")
        try:
            parameter = {
                'INPUT': layer,
                'OVERLAY': overlay,
                'OUTPUT': 'memory:extracted'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:difference', parameter)['OUTPUT']
            logger.info("Difference  finished")
            return result
        except Exception as error:
            logger.error("An error occured in Difference")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    ## ##################################
    ## GEOMETRY WORKERS
    ## ##################################


    def reproject(layer, targetEPSG):
        """
        Reprojects a vector layer in a different CRS.
        The reprojected layer will have the same features and attributes of the input layer.
        QGIS processing algorithem: native:reprojectlayer.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: polygon]
            The Qgsvectorlayer input for the algorithem

        targetEPSG : Integer
            The EPSG code og the target coordinate system.


        Returns
        -------
        Qgsvectorlayer [vector: polygon]
            The result output from the algorithem
        """

        logger.info("Running reporjector V2")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'TARGET_CRS': QgsCoordinateReferenceSystem(targetEPSG),
                'OUTPUT': 'memory:Reprojected'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:reprojectlayer', parameter)['OUTPUT']
            logger.info("Reproject finished")
            return result
        except Exception as error:
            logger.error("An error occured reprojectiong layer")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def simplify(layer, method, tolerance):
            """
            Simplifies the geometries in a line or polygon layer. 
            It creates a new layer with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.
            QGIS processing algorithem: native:simplifygeometries.

            Parameters
            ----------
            layer : Qgsvectorlayer [vector: polygon]
                The Qgsvectorlayer input for the algorithem

            method : Integer
                Simplification method. One of: 0 — Distance (Douglas-Peucker), 1 — Snap to grid, 2 — Area (Visvalingam)

            tolerance : Integer
                Threshold tolerance (in units of the layer): if the distance between two nodes is smaller than the tolerance value,
                the segment will be simplified and vertices will be removed.


            Returns
            -------
            Qgsvectorlayer [vector: polygon/line]
                The result output from the algorithem
            """

            logger.info("Running reporjector V2")
            logger.info("Processing " + str(layer.featureCount()) +" features")
            try:
                parameter = {
                    'METHOD':method,
                    'TOLERANCE':tolerance,
                    'OUTPUT': 'memory:Reprojected'
                }
                logger.info(f'Parameters: {str(parameter)}')
                result = processing.run('native:simplifygeometries', parameter)['OUTPUT']
                logger.info("Simplifygeometries finished")
                return result
            except Exception as error:
                logger.error("An error occured in simplifygeometries")
                logger.error(f'{type(error).__name__}{str(error)}')
                logger.critical("Program terminated" )
                sys.exit()

    def forceRHR(layer):
        """
        Forces polygon geometries to respect the Right-Hand-Rule, in which the area that is bounded
        by a polygon is to the right of the boundary. 
        In particular, the exterior ring is oriented in a clockwise direction and any interior
        rings in a counter-clockwise direction.
        QGIS processing algorithem: native:forcerhr

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: polygon]
            The Qgsvectorlayer input for the algorithem


        Returns
        -------
        Qgsvectorlayer [vector: polygon]
            The result output from the algorithem
        """

        logger.info("Running force right-hand rule")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'OUTPUT': 'memory:forced'
            }
            result = processing.run('native:forcerhr', parameter)['OUTPUT']
            logger.info("forceRHR finished")
            return result
        except Exception as error:
            logger.error("An error occured in forceRHR")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def join_by_attribute(layer1, layer1_field, layer2, layer2_field, fields_to_copy, method, discard, prefix):
        """
        Takes an input vector layer and creates a new vector layer that is an extended version of the input one, 
        with additional attributes in its attribute table.
        The additional attributes and their values are taken from a second vector layer. An attribute is selected in each of them 
        to define the join criteria.
        QGIS processing algorithem: native:joinattributestable.

        Parameters
        ----------
        layer1 : Qgsvectorlayer [vector: any]
            The 1. Qgsvectorlayer input for the algorithem

        layer1_field : String
            Field of the source layer to use for the join

        layer2 : Qgsvectorlayer [vector: any]
            The 2. Qgsvectorlayer input for the algorithem

        layer2_field : String
            Field of the source layer to use for the join

        fields_to_copy : List
            Select the specific fields you want to add. By default all the fields are added. Default []

        method : Integer
            The type of the final joined layer. One of: 
            0 — Create separate feature for each matching feature (one-to-many)
            1 — Take attributes of the first matching feature only (one-to-one)

        discard : Boolean
            Check if you don’t want to keep the features that could not be joined

        prefix : String
            Add a prefix to joined fields in order to easily identify them and avoid field name collision

        Returns
        -------
        Qgsvectorlayer [vector: polygon]
            The result output from the algorithem

        """
        logger.info("Joining features features")
        logger.info("Processing " + str(layer1.featureCount()) +" features")
        try:
            parameter = {
                'INPUT':layer1,
                'FIELD':layer1_field,
                'INPUT_2':layer2,
                'FIELD_2':layer2_field,
                'FIELDS_TO_COPY':fields_to_copy,
                'METHOD':method,
                'DISCARD_NONMATCHING':discard,
                'PREFIX':prefix,
                'OUTPUT': 'memory:joined'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:joinattributestable', parameter)['OUTPUT']
            logger.info("Joinattributestable finished")
            logger.info("Returning " + str(result.featureCount()) +" features")
            return result
        except Exception as error:
            logger.error("An error occured in joinattributestable")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def dissolveFeatures(layer, fieldList, disjoined):
        """
        Takes a vector layer and combines its features into new features. 
        One or more attributes can be specified to dissolve features belonging to the same class 
        (having the same value for the specified attributes), alternatively all features can be dissolved to a single feature.
        All output geometries will be converted to multi geometries. 
        QGIS processing algorithem: native:dissolve.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        fieldList : List
            List of fields to dissolve on. Default []

        disjoined : Boolean
            Keep disjoint features separate ? Default: False


        Returns
        -------
        Qgsvectorlayer [vector: polygon]
            The result output from the algorithem

        """
        logger.info("Dissolving features")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'FIELD' : fieldList,
                'SEPARATE_DISJOINT' : False,
                'OUTPUT': 'memory:dissolved'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:dissolve', parameter)['OUTPUT']
            logger.info("DissolveFeatures finished")
            logger.info("Returning " + str(result.featureCount()) +" features")
            return result
        except Exception as error:
            logger.error("An error occured in dissolveFeatures")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def bufferLayer(layer, distance, segements, endcapStyle, joinStyle, miterLimit, dissolve):
        """
        Computes a buffer area for all the features in an input layer, using a fixed or data defined distance.
        It is possible to use a negative distance for polygon input layers.
        In this case the buffer will result in a smaller polygon (setback).
        QGIS processing algorithem: native:buffer

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        distance : Integer
            The buffer distance. Default: 10.0

        segements : Integer
            Number og segments. Default: 5

        endcapStyle : Enumeration
            Controls how line endings are handled in the buffer. Default: 0 
            (One of: 0 — Round, 1 — Flat, 2 — Square)

        joinStyle : Enumeration
            Specifies whether round, miter or beveled joins should be used when offsetting corners in a line.
            Default: 0 (Options are: 0 — Round, 1 — Miter, 2 — Bevel)

        miterLimit : Integer
            Sets the maximum distance from the offset geometry to use when creating a mitered join as a factor of the offset distance
            Default: 0, Minimum: 1

        dissolve : Boolean
            Dissolve the final buffer. Default: false.


        Returns
        -------
        Qgsvectorlayer [vector: polygon]
            The result output from the algorithem
        """

        logger.info("Creating buffer layer")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'DISTANCE': distance,
                'SEGMENTS': segements,
                'END_CAP_STYLE': endcapStyle,
                'JOIN_STYLE': joinStyle,
                'MITER_LIMIT': miterLimit,
                'DISSOLVE': dissolve,
                'OUTPUT': 'memory:buffer'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:buffer', parameter)['OUTPUT']
            logger.info("BufferLayer finished")
            return result
        except Exception as error:
            logger.error("An error occured in BufferLayer")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def fixGeometry(layer):
        """
        Attempts to create a valid representation of a given invalid geometry without losing any of the input vertices.
        Already valid geometries are returned without further intervention. Always outputs multi-geometry layer.
        QGIS processing algorithem: native:fixgeometries

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem


        Returns
        -------
        Qgsvectorlayer [vector: any]
            The result output from the algorithem

        """
        logger.info("Fixing geometries")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'OUTPUT': 'memory:buffer'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:fixgeometries', parameter)['OUTPUT']
            logger.info("FixGeometry finished")
            return result
        except Exception as error:
            logger.error("An error occured in FixGeometry")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

    def randomselection(layer,method, number):
        """
        Takes a vector layer and selects a subset of its features. No new layer is generated by this algorithm.
        The subset is defined randomly, based on feature IDs, using a percentage or count value to define the 
        total number of features in the subset.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: any]
            The Qgsvectorlayer input for the algorithem

        method : Integer
            Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

        number : Integer
            Number or percentage of features to select

        Returns
        -------
        _type_
            _description_
        """
        logger.info("Performing random selection")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'INPUT': layer,
                'METHOD':method,
                'NUMBER':number,
                'OUTPUT': 'memory:buffer'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:randomextract', parameter)['OUTPUT']
            logger.info("Returning " + str(result.featureCount()) +" features")
            logger.info("randomextract finished")
            return result
        except Exception as error:
            logger.error("An error occured in FixGeometry")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

addAutoIncrementalField(layer, fieldname, start)

Adds a new integer field to a vector layer, with a sequential value for each feature. This field can be used as a unique ID for features in the layer. The new attribute is not added to the input layer but a new layer is generated instead. The initial starting value for the incremental series can be specified. Optionally, the incremental series can be based on grouping fields and a sort order for features can also be specified.

Parameters

layer : QgsVectorLayer The QgsVectorLayer that is used as input.

String

Name of the field with autoincremental values.

Integer

Choose the initial number of the incremental count, Default: 0.

Returns

QgsVectorLayer The QgsVectorLayer output layer.

Source code in python\engine\workers.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
def addAutoIncrementalField(layer, fieldname, start):
    """
    Adds a new integer field to a vector layer, with a sequential value for each feature.
    This field can be used as a unique ID for features in the layer. The new attribute is not added to the input layer but a new layer is generated instead.
    The initial starting value for the incremental series can be specified. Optionally, the incremental series can be based on grouping 
    fields and a sort order for features can also be specified.

    Parameters
    ----------
    layer : QgsVectorLayer
        The QgsVectorLayer that is used as input.

    fieldname : String
        Name of the field with autoincremental values.

    start : Integer
        Choose the initial number of the incremental count, Default: 0.

    Returns
    -------
    QgsVectorLayer
        The QgsVectorLayer output layer.
    """
    logger.info("Adding incremental field")
    try:
        parameter = {
            'INPUT': layer,
            'FIELD_NAME': fieldname,
            'START':start,
            'MODULUS':0,
            'GROUP_FIELDS':[],
            'SORT_EXPRESSION':'',
            'SORT_ASCENDING':True,
            'SORT_NULLS_FIRST':False,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:addautoincrementalfield', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("addAutoIncrementalField  finished")
        return result
    except Exception as error:
        logger.error("An error occured in addAutoIncrementalField")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

attributeindex(layer, field)

Creates an index to speed up queries made against a field in a table. Support for index creation is dependent on the layer's data provider and the field type.

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Field

The field to base the index on

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
def attributeindex(layer, field):
    """
    Creates an index to speed up queries made against a field in a table.
    Support for index creation is dependent on the layer's data provider and the field type.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    field : Field
        The field to base the index on

    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem
    """
    logger.info("Crating attribute index on " + layer + " on filed " + field)
    try:
        parameter = {
            'INPUT': field,
            'FIELD': field,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:createattributeindex', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("createattributeindex  finished")
        return result
    except Exception as error:
        logger.error("An error occured in createattributeindex")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

bufferLayer(layer, distance, segements, endcapStyle, joinStyle, miterLimit, dissolve)

Computes a buffer area for all the features in an input layer, using a fixed or data defined distance. It is possible to use a negative distance for polygon input layers. In this case the buffer will result in a smaller polygon (setback). QGIS processing algorithem: native:buffer

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Integer

The buffer distance. Default: 10.0

Integer

Number og segments. Default: 5

Enumeration

Controls how line endings are handled in the buffer. Default: 0 (One of: 0 — Round, 1 — Flat, 2 — Square)

Enumeration

Specifies whether round, miter or beveled joins should be used when offsetting corners in a line. Default: 0 (Options are: 0 — Round, 1 — Miter, 2 — Bevel)

Integer

Sets the maximum distance from the offset geometry to use when creating a mitered join as a factor of the offset distance Default: 0, Minimum: 1

Boolean

Dissolve the final buffer. Default: false.

Returns

Qgsvectorlayer [vector: polygon] The result output from the algorithem

Source code in python\engine\workers.py
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
def bufferLayer(layer, distance, segements, endcapStyle, joinStyle, miterLimit, dissolve):
    """
    Computes a buffer area for all the features in an input layer, using a fixed or data defined distance.
    It is possible to use a negative distance for polygon input layers.
    In this case the buffer will result in a smaller polygon (setback).
    QGIS processing algorithem: native:buffer

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    distance : Integer
        The buffer distance. Default: 10.0

    segements : Integer
        Number og segments. Default: 5

    endcapStyle : Enumeration
        Controls how line endings are handled in the buffer. Default: 0 
        (One of: 0 — Round, 1 — Flat, 2 — Square)

    joinStyle : Enumeration
        Specifies whether round, miter or beveled joins should be used when offsetting corners in a line.
        Default: 0 (Options are: 0 — Round, 1 — Miter, 2 — Bevel)

    miterLimit : Integer
        Sets the maximum distance from the offset geometry to use when creating a mitered join as a factor of the offset distance
        Default: 0, Minimum: 1

    dissolve : Boolean
        Dissolve the final buffer. Default: false.


    Returns
    -------
    Qgsvectorlayer [vector: polygon]
        The result output from the algorithem
    """

    logger.info("Creating buffer layer")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'DISTANCE': distance,
            'SEGMENTS': segements,
            'END_CAP_STYLE': endcapStyle,
            'JOIN_STYLE': joinStyle,
            'MITER_LIMIT': miterLimit,
            'DISSOLVE': dissolve,
            'OUTPUT': 'memory:buffer'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:buffer', parameter)['OUTPUT']
        logger.info("BufferLayer finished")
        return result
    except Exception as error:
        logger.error("An error occured in BufferLayer")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

clip(layer, overlay)

Clips a vector layer using the features of an additional polygon layer. Only the parts of the features in the input layer that fall within the polygons of the overlay layer will be added to the resulting layer.

Parameters

layer : Qgsvectorlayer [vector: any] Layer containing the features to be clipped

[vector: polygon]

Layer containing the clipping features

Returns

Qgsvectorlayer [vector: any] Layer to contain the features from the input layer that are inside the overlay (clipping) layer

Source code in python\engine\workers.py
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
def clip(layer, overlay):
    """
    Clips a vector layer using the features of an additional polygon layer.
    Only the parts of the features in the input layer that fall within the polygons of 
    the overlay layer will be added to the resulting layer.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        Layer containing the features to be clipped

    overlay : [vector: polygon]
        Layer containing the clipping features

    Returns
    -------
    Qgsvectorlayer [vector: any]
        Layer to contain the features from the input layer that are inside the overlay (clipping) layer
    """
    logger.info("Clipping layers")
    try:
        parameter = {
            'INPUT': layer,
            'OVERLAY': overlay,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:clip', parameter)['OUTPUT']
        logger.info("Clip  finished")
        return result
    except Exception as error:
        logger.error("An error occured in Clip")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

deleteColumns(layer, columns)

Takes a vector layer and generates a new one that has the same features but without the selected columns.

Parameters

layer : QgsVectorLayer Input vector layer to drop field(s) from

List of tablefields

The field(s) to drop

Returns

QgsVectorLayer The QgsVectorLayer output layer.

Source code in python\engine\workers.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
def deleteColumns (layer, columns):
    """
    Takes a vector layer and generates a new one that has the same features but without the selected columns.

    Parameters
    ----------
    layer : QgsVectorLayer
        Input vector layer to drop field(s) from

    columns : List of tablefields
        The field(s) to drop

    Returns
    -------
    QgsVectorLayer
        The QgsVectorLayer output layer.
    """
    logger.info("deleting fields")
    try:
        parameter = {
            'INPUT': layer,
            'COLUMN':columns,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:deletecolumn', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("deleteColumns  finished")
        return result
    except Exception as error:
        logger.error("An error occured in deleteColumns")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

difference(layer, overlay)

Extracts features from the input layer that don’t fall within the boundaries of the overlay layer. Input layer features that partially overlap the overlay layer feature(s) are split along the boundary of those feature(s.

Parameters

layer : Qgsvectorlayer [vector: any] Layer to extract (parts of) features from.

Qgsvectorlayer [vector: any]

Layer containing the geometries that will be subtracted from the iniput layer geometries

Returns

Qgsvectorlayer [vector: polygon/line] The result output from the algorithem

Source code in python\engine\workers.py
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
def difference(layer, overlay):
    """
    Extracts features from the input layer that don’t fall within the boundaries of the overlay layer.
    Input layer features that partially overlap the overlay layer feature(s) are split along the 
    boundary of those feature(s.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        Layer to extract (parts of) features from.

    overlay : Qgsvectorlayer [vector: any]
        Layer containing the geometries that will be subtracted from the iniput layer geometries

    Returns
    -------
    Qgsvectorlayer [vector: polygon/line]
        The result output from the algorithem
    """
    logger.info("Finding differences")
    try:
        parameter = {
            'INPUT': layer,
            'OVERLAY': overlay,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:difference', parameter)['OUTPUT']
        logger.info("Difference  finished")
        return result
    except Exception as error:
        logger.error("An error occured in Difference")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

dissolveFeatures(layer, fieldList, disjoined)

Takes a vector layer and combines its features into new features. One or more attributes can be specified to dissolve features belonging to the same class (having the same value for the specified attributes), alternatively all features can be dissolved to a single feature. All output geometries will be converted to multi geometries. QGIS processing algorithem: native:dissolve.

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

List

List of fields to dissolve on. Default []

Boolean

Keep disjoint features separate ? Default: False

Returns

Qgsvectorlayer [vector: polygon] The result output from the algorithem

Source code in python\engine\workers.py
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
def dissolveFeatures(layer, fieldList, disjoined):
    """
    Takes a vector layer and combines its features into new features. 
    One or more attributes can be specified to dissolve features belonging to the same class 
    (having the same value for the specified attributes), alternatively all features can be dissolved to a single feature.
    All output geometries will be converted to multi geometries. 
    QGIS processing algorithem: native:dissolve.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    fieldList : List
        List of fields to dissolve on. Default []

    disjoined : Boolean
        Keep disjoint features separate ? Default: False


    Returns
    -------
    Qgsvectorlayer [vector: polygon]
        The result output from the algorithem

    """
    logger.info("Dissolving features")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'FIELD' : fieldList,
            'SEPARATE_DISJOINT' : False,
            'OUTPUT': 'memory:dissolved'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:dissolve', parameter)['OUTPUT']
        logger.info("DissolveFeatures finished")
        logger.info("Returning " + str(result.featureCount()) +" features")
        return result
    except Exception as error:
        logger.error("An error occured in dissolveFeatures")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

extractByExpression(layer, expression)

Creates a vector layer from an input layer, containing only matching features. The criteria for adding features to the resulting layer is based on a QGIS expression.

Parameters

layer : QgsVectorLayer The QgsVectorLayer that is used as input.

String

Expression to filter the vector layer

Returns

QgsVectorLayer The QgsVectorLayer output layer.

Source code in python\engine\workers.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
def extractByExpression(layer, expression):
    """
    Creates a vector layer from an input layer, containing only matching features.
    The criteria for adding features to the resulting layer is based on a QGIS expression.

    Parameters
    ----------
    layer : QgsVectorLayer
        The QgsVectorLayer that is used as input.

    expression : String
        Expression to filter the vector layer

    Returns
    -------
    QgsVectorLayer
        The QgsVectorLayer output layer.
    """
    logger.info("Extracting by expression")
    try:
        parameter = {
            'INPUT': layer,
            'EXPRESSION': expression,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:extractbyexpression', parameter)['OUTPUT']
        logger.info("Extractbyexpression  finished")
        return result
    except Exception as error:
        logger.error("An error occured in extractByExpression")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

extractByLocation(layer, predicate, intersect)

summary

Parameters

layer : Qgsvectorlayer [vector: any] Input vector layer.

[enumeration][list] Default: [0]

Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of: 0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

Qgsvectorlayer [vector: any]

Intersection vector layer

Returns

Qgsvectorlayer [vector: any] the output vector layer for the join.

Source code in python\engine\workers.py
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
def extractByLocation(layer, predicate, intersect):
    """_summary_

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        Input vector layer. 

    predicate : [enumeration] [list] Default: [0]
        Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of:
        0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

    intersect : Qgsvectorlayer [vector: any]
        Intersection vector layer

    Returns
    -------
    Qgsvectorlayer [vector: any]
        the output vector layer for the join.
    """
    logger.info("Extracting by location")
    try:
        parameter = {
            'INPUT': layer,
            'PREDICATE':predicate,
            'INTERSECT':intersect,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:extractbylocation', parameter)['OUTPUT']
        logger.info("extractByLocation finished")
        return result
    except Exception as error:
        logger.error("An error occured in extractByLocation")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

fieldCalculator(layer, fieldname, fieldtype, fieldlength, fieldprecision, formula)

Scripting the field calcualtor You can use all the supported expressions and functions. The original layer is not modified. A new layer is generated where the attribute table contains the calucalted field QGIS processing algorithem: native:fieldcalculator

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

String

The name of the new calcualted field

Enumeration

Type of the field, Default: 0 (0 — Float, 1 — Integer, 2 — String, 3 — Date)

Integer

Lenght of the field, Default: 10.

Integer

Precision of the field, Default: 3.

Expression

The expression that populates the values of the field.

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
def fieldCalculator (layer, fieldname, fieldtype, fieldlength, fieldprecision, formula):
    """
    Scripting the field calcualtor
    You can use all the supported expressions and functions.
    The original layer is not modified. A new layer is generated where the attribute table contains the calucalted field
    QGIS processing algorithem: native:fieldcalculator

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    fieldname : String
        The name of the new calcualted field

    fieldtype : Enumeration
        Type of the field,  Default: 0  (0 — Float, 1 — Integer, 2 — String, 3 — Date)

    fieldlength : Integer
        Lenght of the field, Default: 10.

    fieldprecision : Integer
        Precision of the field, Default: 3.

    formula : Expression
        The expression that populates the values of the field.


    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem
    """
    logger.info("Calculating field")
    try:
        parameter = {
            'INPUT': layer,
            'FIELD_NAME': fieldname,
            'FIELD_TYPE': fieldtype,
            'FIELD_LENGTH': fieldlength,
            'FIELD_PRECISION': fieldprecision,
            'FORMULA': formula,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:fieldcalculator', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("fieldCalculator  finished")
        return result
    except Exception as error:
        logger.error("An error occured in fieldCalculator")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

fixGeometry(layer)

Attempts to create a valid representation of a given invalid geometry without losing any of the input vertices. Already valid geometries are returned without further intervention. Always outputs multi-geometry layer. QGIS processing algorithem: native:fixgeometries

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
def fixGeometry(layer):
    """
    Attempts to create a valid representation of a given invalid geometry without losing any of the input vertices.
    Already valid geometries are returned without further intervention. Always outputs multi-geometry layer.
    QGIS processing algorithem: native:fixgeometries

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem


    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem

    """
    logger.info("Fixing geometries")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'OUTPUT': 'memory:buffer'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:fixgeometries', parameter)['OUTPUT']
        logger.info("FixGeometry finished")
        return result
    except Exception as error:
        logger.error("An error occured in FixGeometry")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

forceRHR(layer)

Forces polygon geometries to respect the Right-Hand-Rule, in which the area that is bounded by a polygon is to the right of the boundary. In particular, the exterior ring is oriented in a clockwise direction and any interior rings in a counter-clockwise direction. QGIS processing algorithem: native:forcerhr

Parameters

layer : Qgsvectorlayer [vector: polygon] The Qgsvectorlayer input for the algorithem

Returns

Qgsvectorlayer [vector: polygon] The result output from the algorithem

Source code in python\engine\workers.py
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
def forceRHR(layer):
    """
    Forces polygon geometries to respect the Right-Hand-Rule, in which the area that is bounded
    by a polygon is to the right of the boundary. 
    In particular, the exterior ring is oriented in a clockwise direction and any interior
    rings in a counter-clockwise direction.
    QGIS processing algorithem: native:forcerhr

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: polygon]
        The Qgsvectorlayer input for the algorithem


    Returns
    -------
    Qgsvectorlayer [vector: polygon]
        The result output from the algorithem
    """

    logger.info("Running force right-hand rule")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'OUTPUT': 'memory:forced'
        }
        result = processing.run('native:forcerhr', parameter)['OUTPUT']
        logger.info("forceRHR finished")
        return result
    except Exception as error:
        logger.error("An error occured in forceRHR")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

joinByLocation(layer, predicate, join, join_fields, method, discard_nomatching, prefix)

Takes an input vector layer and creates a new vector layer that is an extended version of the input one, with additional attributes in its attribute table. The additional attributes and their values are taken from a second vector layer. A spatial criteria is applied to select the values from the second layer that are added to each feature from the first layer.

Parameters

layer : Qgsvectorlayer [vector: any] Input vector layer. The output layer will consist of the features of this layer with attributes from matching features in the second layer.

[enumeration][list] Default: [0]

Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of: 0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

[vector: any]

The join layer. Features of this vector layer will add their attributes to the source layer attribute table if they satisfy the spatial relationship.

[tablefield: any][list]

Select the specific fields you want to add from the join layer. By default all the fields are added.

[enumeration]

The type of the final joined layer. One of: 0 — Create separate feature for each matching feature (one-to-many) 1 — Take attributes of the first matching feature only (one-to-one) 2 — Take attributes of the feature with largest overlap only (one-to-one)

[boolean] Default: False

Remove from the output the input layer’s features which could not be joined

[string]

Add a prefix to joined fields in order to easily identify them and avoid field name collision

Returns

Qgsvectorlayer [vector: any] the output vector layer for the join.

Source code in python\engine\workers.py
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
def joinByLocation(layer, predicate, join, join_fields, method, discard_nomatching, prefix):
    """
    Takes an input vector layer and creates a new vector layer that is an extended version of
    the input one, with additional attributes in its attribute table.
    The additional attributes and their values are taken from a second vector layer.
    A spatial criteria is applied to select the values from the second layer that are added to each 
    feature from the first layer.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        Input vector layer. 
        The output layer will consist of the features of this layer with attributes from 
        matching features in the second layer.

    predicate : [enumeration] [list] Default: [0]
        Type of spatial relation the source feature should have with the target feature so that they could be joined. One or more of:
        0 — intersect, 1 — contain, 2 — equal, 3 — touch, 4 — overlap, 5 — are within 6 — cross.

    join : [vector: any]
        The join layer. 
        Features of this vector layer will add their attributes to the source layer attribute table if 
        they satisfy the spatial relationship.

    join_fields : [tablefield: any] [list]
        Select the specific fields you want to add from the join layer. 
        By default all the fields are added.

    method : [enumeration]           	
        The type of the final joined layer. One of: 
        0 — Create separate feature for each matching feature (one-to-many)
        1 — Take attributes of the first matching feature only (one-to-one)
        2 — Take attributes of the feature with largest overlap only (one-to-one)

    discard_nomatching : [boolean] Default: False
        Remove from the output the input layer’s features which could not be joined

    prefix : [string]
        Add a prefix to joined fields in order to easily identify them and avoid field name collision

    Returns
    -------
    Qgsvectorlayer [vector: any]
        the output vector layer for the join.
    """
    logger.info("Clipping layers")
    try:
        parameter = {
            'INPUT': layer,
            'PREDICATE':predicate,
            'JOIN':join,
            'JOIN_FIELDS':join_fields,
            'METHOD':method,
            'DISCARD_NONMATCHING':discard_nomatching,
            'PREFIX':prefix,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:joinattributesbylocation', parameter)['OUTPUT']
        logger.info("joinByLocation finished")
        return result
    except Exception as error:
        logger.error("An error occured in joinByLocation")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

join_by_attribute(layer1, layer1_field, layer2, layer2_field, fields_to_copy, method, discard, prefix)

Takes an input vector layer and creates a new vector layer that is an extended version of the input one, with additional attributes in its attribute table. The additional attributes and their values are taken from a second vector layer. An attribute is selected in each of them to define the join criteria. QGIS processing algorithem: native:joinattributestable.

Parameters

layer1 : Qgsvectorlayer [vector: any] The 1. Qgsvectorlayer input for the algorithem

String

Field of the source layer to use for the join

Qgsvectorlayer [vector: any]

The 2. Qgsvectorlayer input for the algorithem

String

Field of the source layer to use for the join

List

Select the specific fields you want to add. By default all the fields are added. Default []

Integer

The type of the final joined layer. One of: 0 — Create separate feature for each matching feature (one-to-many) 1 — Take attributes of the first matching feature only (one-to-one)

Boolean

Check if you don’t want to keep the features that could not be joined

String

Add a prefix to joined fields in order to easily identify them and avoid field name collision

Returns

Qgsvectorlayer [vector: polygon] The result output from the algorithem

Source code in python\engine\workers.py
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
def join_by_attribute(layer1, layer1_field, layer2, layer2_field, fields_to_copy, method, discard, prefix):
    """
    Takes an input vector layer and creates a new vector layer that is an extended version of the input one, 
    with additional attributes in its attribute table.
    The additional attributes and their values are taken from a second vector layer. An attribute is selected in each of them 
    to define the join criteria.
    QGIS processing algorithem: native:joinattributestable.

    Parameters
    ----------
    layer1 : Qgsvectorlayer [vector: any]
        The 1. Qgsvectorlayer input for the algorithem

    layer1_field : String
        Field of the source layer to use for the join

    layer2 : Qgsvectorlayer [vector: any]
        The 2. Qgsvectorlayer input for the algorithem

    layer2_field : String
        Field of the source layer to use for the join

    fields_to_copy : List
        Select the specific fields you want to add. By default all the fields are added. Default []

    method : Integer
        The type of the final joined layer. One of: 
        0 — Create separate feature for each matching feature (one-to-many)
        1 — Take attributes of the first matching feature only (one-to-one)

    discard : Boolean
        Check if you don’t want to keep the features that could not be joined

    prefix : String
        Add a prefix to joined fields in order to easily identify them and avoid field name collision

    Returns
    -------
    Qgsvectorlayer [vector: polygon]
        The result output from the algorithem

    """
    logger.info("Joining features features")
    logger.info("Processing " + str(layer1.featureCount()) +" features")
    try:
        parameter = {
            'INPUT':layer1,
            'FIELD':layer1_field,
            'INPUT_2':layer2,
            'FIELD_2':layer2_field,
            'FIELDS_TO_COPY':fields_to_copy,
            'METHOD':method,
            'DISCARD_NONMATCHING':discard,
            'PREFIX':prefix,
            'OUTPUT': 'memory:joined'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:joinattributestable', parameter)['OUTPUT']
        logger.info("Joinattributestable finished")
        logger.info("Returning " + str(result.featureCount()) +" features")
        return result
    except Exception as error:
        logger.error("An error occured in joinattributestable")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

randomExtract(layer, method, number)

Takes a vector layer and generates a new one that contains only a subset of the features in the input layer. The subset is defined randomly, based on feature IDs, using a percentage or count value to define the total number of features in the subset.

Parameters

layer : Qgsvectorlayer [vector: any] Input vector layer.

type

description

[enumeration] Default: 0

Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

Returns

Qgsvectorlayer [vector: polygon/line] The result output from the algorithem

Source code in python\engine\workers.py
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
def randomExtract(layer, method, number):
    """
    Takes a vector layer and generates a new one that contains only a subset of the features in the input layer.
    The subset is defined randomly, based on feature IDs, using a percentage or count value to define 
    the total number of features in the subset.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        Input vector layer. 

    method : _type_
        _description_

    number : [enumeration] Default: 0
        Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

    Returns
    -------
    Qgsvectorlayer [vector: polygon/line]
        The result output from the algorithem
    """
    logger.info("Extracting random features")
    try:
        parameter = {
            'INPUT': layer,
            'METHOD':method,
            'NUMBER':number,
            'OUTPUT': 'memory:extracted'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:randomextract', parameter)['OUTPUT']
        logger.info("randomExtract finished")
        return result
    except Exception as error:
        logger.error("An error occured in randomExtract")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

randomselection(layer, method, number)

Takes a vector layer and selects a subset of its features. No new layer is generated by this algorithm. The subset is defined randomly, based on feature IDs, using a percentage or count value to define the total number of features in the subset.

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Integer

Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

Integer

Number or percentage of features to select

Returns

type description

Source code in python\engine\workers.py
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
def randomselection(layer,method, number):
    """
    Takes a vector layer and selects a subset of its features. No new layer is generated by this algorithm.
    The subset is defined randomly, based on feature IDs, using a percentage or count value to define the 
    total number of features in the subset.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    method : Integer
        Random selection method. One of: 0 — Number of selected features, 1 — Percentage of selected features

    number : Integer
        Number or percentage of features to select

    Returns
    -------
    _type_
        _description_
    """
    logger.info("Performing random selection")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'METHOD':method,
            'NUMBER':number,
            'OUTPUT': 'memory:buffer'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:randomextract', parameter)['OUTPUT']
        logger.info("Returning " + str(result.featureCount()) +" features")
        logger.info("randomextract finished")
        return result
    except Exception as error:
        logger.error("An error occured in FixGeometry")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

renameTableField(layer, field, newname)

Renames an existing field from a vector layer.
The original layer is not modified. A new layer is generated where the attribute table contains the renamed field. QGIS processing algorithem: native:renametablefield

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Tablefield

The field that is to be renamed

String

New name for the field

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
def renameTableField (layer, field, newname):
    """
    Renames an existing field from a vector layer.  
    The original layer is not modified. A new layer is generated where the attribute table contains the renamed field.
    QGIS processing algorithem: native:renametablefield

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    field : Tablefield
        The field that is to be renamed

    newname : String
        New name for the field


    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem
    """
    logger.info("Renaming field")
    try:
        parameter = {
            'INPUT': layer,
            'FIELD': field,
            'NEW_NAME': newname,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:renametablefield', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("renameTableField  finished")
        return result
    except Exception as error:
        logger.error("An error occured in renameTableField")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

reproject(layer, targetEPSG)

Reprojects a vector layer in a different CRS. The reprojected layer will have the same features and attributes of the input layer. QGIS processing algorithem: native:reprojectlayer.

Parameters

layer : Qgsvectorlayer [vector: polygon] The Qgsvectorlayer input for the algorithem

Integer

The EPSG code og the target coordinate system.

Returns

Qgsvectorlayer [vector: polygon] The result output from the algorithem

Source code in python\engine\workers.py
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
def reproject(layer, targetEPSG):
    """
    Reprojects a vector layer in a different CRS.
    The reprojected layer will have the same features and attributes of the input layer.
    QGIS processing algorithem: native:reprojectlayer.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: polygon]
        The Qgsvectorlayer input for the algorithem

    targetEPSG : Integer
        The EPSG code og the target coordinate system.


    Returns
    -------
    Qgsvectorlayer [vector: polygon]
        The result output from the algorithem
    """

    logger.info("Running reporjector V2")
    logger.info("Processing " + str(layer.featureCount()) +" features")
    try:
        parameter = {
            'INPUT': layer,
            'TARGET_CRS': QgsCoordinateReferenceSystem(targetEPSG),
            'OUTPUT': 'memory:Reprojected'
        }
        logger.info(f'Parameters: {str(parameter)}')
        result = processing.run('native:reprojectlayer', parameter)['OUTPUT']
        logger.info("Reproject finished")
        return result
    except Exception as error:
        logger.error("An error occured reprojectiong layer")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

simplify(layer, method, tolerance)

Simplifies the geometries in a line or polygon layer. It creates a new layer with the same features as the ones in the input layer, but with geometries containing a lower number of vertices. QGIS processing algorithem: native:simplifygeometries.

Parameters

layer : Qgsvectorlayer [vector: polygon] The Qgsvectorlayer input for the algorithem

Integer

Simplification method. One of: 0 — Distance (Douglas-Peucker), 1 — Snap to grid, 2 — Area (Visvalingam)

Integer

Threshold tolerance (in units of the layer): if the distance between two nodes is smaller than the tolerance value, the segment will be simplified and vertices will be removed.

Returns

Qgsvectorlayer [vector: polygon/line] The result output from the algorithem

Source code in python\engine\workers.py
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
def simplify(layer, method, tolerance):
        """
        Simplifies the geometries in a line or polygon layer. 
        It creates a new layer with the same features as the ones in the input layer, but with geometries containing a lower number of vertices.
        QGIS processing algorithem: native:simplifygeometries.

        Parameters
        ----------
        layer : Qgsvectorlayer [vector: polygon]
            The Qgsvectorlayer input for the algorithem

        method : Integer
            Simplification method. One of: 0 — Distance (Douglas-Peucker), 1 — Snap to grid, 2 — Area (Visvalingam)

        tolerance : Integer
            Threshold tolerance (in units of the layer): if the distance between two nodes is smaller than the tolerance value,
            the segment will be simplified and vertices will be removed.


        Returns
        -------
        Qgsvectorlayer [vector: polygon/line]
            The result output from the algorithem
        """

        logger.info("Running reporjector V2")
        logger.info("Processing " + str(layer.featureCount()) +" features")
        try:
            parameter = {
                'METHOD':method,
                'TOLERANCE':tolerance,
                'OUTPUT': 'memory:Reprojected'
            }
            logger.info(f'Parameters: {str(parameter)}')
            result = processing.run('native:simplifygeometries', parameter)['OUTPUT']
            logger.info("Simplifygeometries finished")
            return result
        except Exception as error:
            logger.error("An error occured in simplifygeometries")
            logger.error(f'{type(error).__name__}{str(error)}')
            logger.critical("Program terminated" )
            sys.exit()

spatialindex(layer)

Creates an index to speed up access to the features in a layer based on their spatial location. Support for spatial index creation is dependent on the layer's data provider.

Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
def spatialindex(layer):
    """
    Creates an index to speed up access to the features in a layer based on their spatial location.
    Support for spatial index creation is dependent on the layer's data provider.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem
    """

    logger.info("Crating spatial index on " + layer)
    try:
        parameter = {
            'INPUT': field,
            'OUTPUT': 'memory:extracted'
        }
        result = processing.run('native:createspatialindex', parameter)['OUTPUT']
        logger.info(f'Parameters: {str(parameter)}')
        logger.info("createspatialindex  finished")
        return result
    except Exception as error:
        logger.error("An error occured in createspatialindex")
        logger.error(f'{type(error).__name__}{str(error)}')
        logger.critical("Program terminated" )
        sys.exit()

timeStamper(layer, ts_fieldname)

Create an attribute woth current timestamp on features.
Parameters

layer : Qgsvectorlayer [vector: any] The Qgsvectorlayer input for the algorithem

String

The name of the new timestamp field

Returns

Qgsvectorlayer [vector: any] The result output from the algorithem

Source code in python\engine\workers.py
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
def timeStamper(layer, ts_fieldname):
    """
        Create an attribute woth current timestamp on features.

    Parameters
    ----------
    layer : Qgsvectorlayer [vector: any]
        The Qgsvectorlayer input for the algorithem

    ts_fieldname : String
        The name of the new timestamp field

    Returns
    -------
    Qgsvectorlayer [vector: any]
        The result output from the algorithem
    """
    logger.info(f'Creating timestamp {ts_fieldname} using fieldCalculator')
    newLayer = Worker.fieldCalculator(layer, ts_fieldname, 5, 0, 0, ' now() ')
    return newLayer