jagomart
digital resources
picture1_Qgis 16 Pyqgisdevelopercookbook En


 147x       Filetype PDF       File size 1.29 MB       Source: docs.qgis.org


File: Qgis 16 Pyqgisdevelopercookbook En
pyqgis3 16developercookbook qgisproject apr02 2022 contents 1 introduction 1 1 1 scripting in the python console 1 1 2 python plugins 2 1 3 running python code when qgis starts ...

icon picture PDF Filetype PDF | Posted on 03 Feb 2023 | 2 years ago
Partial capture of text on file.
             PyQGIS3.16developercookbook
                                           QGISProject
                                               Apr02,2022
                                                                                                                                                                                  CONTENTS
                             1     Introduction                                                                                                                                                                  1
                                   1.1        Scripting in the Python Console                      .  .  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                       1
                                   1.2        Python Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                             2
                                   1.3        Running Python code when QGIS starts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                                 3
                                              1.3.1         Thestartup.pyfile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                              3
                                              1.3.2         ThePYQGIS_STARTUPenvironmentvariable . . . . . . . . . . . . . . . . . . . . . .                                                                     3
                                   1.4        Python Applications                .  . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                              3
                                              1.4.1         Using PyQGIS in standalone scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                         4
                                              1.4.2         Using PyQGIS in custom applications . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          4
                                              1.4.3         Running Custom Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          5
                                   1.5        Technical notes on PyQt and SIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                              6
                             2     LoadingProjects                                                                                                                                                               7
                                   2.1        Resolving bad paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                            8
                             3     LoadingLayers                                                                                                                                                                 9
                                   3.1        Vector Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                            9
                                   3.2        Raster Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          12
                                   3.3        QgsProject instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          14
                             4     Accessing the Table Of Contents (TOC)                                                                                                                                       15
                                   4.1        TheQgsProject class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                            15
                                   4.2        QgsLayerTreeGroup class                     . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                          16
                             5     Using Raster Layers                                                                                                                                                         19
                                   5.1        Layer Details . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          19
                                   5.2        Renderer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                           20
                                              5.2.1         Single Band Rasters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                      20
                                              5.2.2         Multi Band Rasters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                       21
                                   5.3        Query Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                           21
                             6     Using Vector Layers                                                                                                                                                         23
                                   6.1        Retrieving information about attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          24
                                   6.2        Iterating over Vector Layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          24
                                   6.3        Selecting features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                         25
                                              6.3.1         Accessing attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                     26
                                              6.3.2         Iterating over selected features                   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                   26
                                              6.3.3         Iterating over a subset of features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                    26
                                   6.4        Modifying Vector Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                            27
                                              6.4.1         AddFeatures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                        28
                                              6.4.2         Delete Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                      28
                                              6.4.3         Modify Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                      28
                                              6.4.4         Modifying Vector Layers with an Editing Buffer . . . . . . . . . . . . . . . . . . . . . .                                                         29
                                              6.4.5         Adding and Removing Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                         30
                                   6.5        Using Spatial Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .                                                          31
                                                                                                                                                                                                                  i
                        6.6    TheQgsVectorLayerUtils class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        32
                        6.7    Creating Vector Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      32
                               6.7.1    Fromaninstance of QgsVectorFileWriter . . . . . . . . . . . . . . . . . . . . .                    32
                               6.7.2    Directly from features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     34
                               6.7.3    Fromaninstance of QgsVectorLayer . . . . . . . . . . . . . . . . . . . . . . . . .                 35
                        6.8    Appearance (Symbology) of Vector Layers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         36
                               6.8.1    Single Symbol Renderer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       37
                               6.8.2    Categorized Symbol Renderer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        38
                               6.8.3    Graduated Symbol Renderer        . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   38
                               6.8.4    Working with Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         39
                               6.8.5    Creating Custom Renderers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        42
                        6.9    Further Topics    . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   44
                    7   GeometryHandling                                                                                                   47
                        7.1    Geometry Construction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       47
                        7.2    Access to Geometry      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   48
                        7.3    Geometry Predicates and Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        49
                    8   Projections Support                                                                                                53
                        8.1    Coordinate reference systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      53
                        8.2    CRSTransformation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         54
                    9   Using the Map Canvas                                                                                               57
                        9.1    EmbeddingMapCanvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .            58
                        9.2    Rubber Bands and Vertex Markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         58
                        9.3    Using Map Tools with Canvas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         59
                               9.3.1    Select a feature using QgsMapToolIdentifyFeature . . . . . . . . . . . . . . . . . . . . .         60
                        9.4    Writing Custom Map Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        61
                        9.5    Writing Custom Map Canvas Items . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         62
                    10 MapRenderingandPrinting                                                                                             65
                        10.1 Simple Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        65
                        10.2 Rendering layers with different CRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         66
                        10.3 Output using print layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       66
                               10.3.1   Exporting the layout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     68
                               10.3.2   Exporting a layout atlas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .     68
                    11 Expressions, Filtering and Calculating Values                                                                       69
                        11.1 Parsing Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       70
                        11.2 Evaluating Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        70
                               11.2.1   Basic Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      70
                               11.2.2   Expressions with features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      71
                               11.2.3   Filtering a layer with expressions   . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   72
                        11.3 Handling expression errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        72
                    12 ReadingAndStoringSettings                                                                                           75
                    13 Communicatingwiththeuser                                                                                            77
                        13.1 Showingmessages. The QgsMessageBar class . . . . . . . . . . . . . . . . . . . . . . . . . . . .              77
                        13.2 Showingprogress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .         80
                        13.3 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .       80
                               13.3.1   QgsMessageLog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        81
                               13.3.2   Thepython built in logging module . . . . . . . . . . . . . . . . . . . . . . . . . . . . .        81
                    14 Authentication infrastructure                                                                                       83
                        14.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .      83
                        14.2 Glossary      . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   84
                        14.3 QgsAuthManagertheentry point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .            84
                               14.3.1   Init the manager and set the master password . . . . . . . . . . . . . . . . . . . . . . . .       84
                    ii
The words contained in this file might help you see if this file matches what you are looking for:

...Pyqgis developercookbook qgisproject apr contents introduction scripting in the python console plugins running code when qgis starts thestartup pyfile thepyqgis startupenvironmentvariable applications using standalone scripts custom technical notes on pyqt and sip loadingprojects resolving bad paths loadinglayers vector layers raster qgsproject instance accessing table of toc theqgsproject class qgslayertreegroup layer details renderer single band rasters multi query values retrieving information about attributes iterating over selecting features selected a subset modifying addfeatures delete modify with an editing buffer adding removing fields spatial index i theqgsvectorlayerutils creating fromaninstance qgsvectorfilewriter directly from qgsvectorlayer appearance symbology symbol...

no reviews yet
Please Login to review.