Example: stock market

PyQGIS developer cookbook - Documentation

PyQGIS developer cookbookRelease ProjectMar 15, 2020 Contents1 in the Python Console .. Plugins .. Python code when QGIS starts .. Applications .. notes on PyQt and SIP ..52 Loading Projects73 Loading Layers .. Layers .. instance ..134 Using Raster Details .. Values ..175 Using Vector information about attributes .. over Vector Layer .. features .. Vector Layers .. Spatial Index .. Vector Layers .. (Symbology) of Vector Layers .. Topics ..386 Geometry Construction .. to Geometry .. Predicates and Operations ..417 Projections reference systems.

PyQGIS developer cookbook, Release 3.4 # second argument to False disables the GUI. qgs=QgsApplication([], False) # Load providers qgs.initQgis() # Write your code here to load some layers, use processing

Tags:

  Developer, Cookbook, Pyqgis developer cookbook, Pyqgis

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Transcription of PyQGIS developer cookbook - Documentation

1 PyQGIS developer cookbookRelease ProjectMar 15, 2020 Contents1 in the Python Console .. Plugins .. Python code when QGIS starts .. Applications .. notes on PyQt and SIP ..52 Loading Projects73 Loading Layers .. Layers .. instance ..134 Using Raster Details .. Values ..175 Using Vector information about attributes .. over Vector Layer .. features .. Vector Layers .. Spatial Index .. Vector Layers .. (Symbology) of Vector Layers .. Topics ..386 Geometry Construction .. to Geometry .. Predicates and Operations ..417 Projections reference systems.

2 Transformation ..448 Using the Map Map Canvas .. Bands and Vertex Markers .. Map Tools with Canvas .. Custom Map Tools .. Custom Map Canvas Items ..529 Map Rendering and Rendering .. layers with different CRS .. using print layout ..5410 Expressions, Filtering and Calculating Parsing Expressions .. Evaluating Expressions .. Handling expression errors ..6011 Reading And Storing Settings6112 Communicating with the Showing messages. The QgsMessageBar class .. Showing progress .. Logging ..6613 Authentication Introduction .. Glossary .. QgsAuthManager the entry point.

3 Adapt plugins to use Authentication infrastructure .. Authentication GUIs ..7114 Tasks - doing heavy work in the Introduction .. Examples ..7615 Developing Python Structuring Python Plugins .. Code Snippets .. Using Plugin Layers .. IDE settings for writing and debugging plugins .. Releasing your plugin ..9716 Writing a Processing plugin10117 Network analysis General information .. Building a graph .. Graph analysis .. 10518 QGIS Server Python Server Filter Plugins architecture .. Raising exception from a plugin .. Writing a server plugin.

4 Access control plugin .. 11719 Cheat sheet for User Interface .. Settings .. Toolbars .. Menus .. Canvas .. Layers .. Table of contents .. Advanced TOC .. Processing algorithms .. Decorators .. Sources .. 130iiiivCHAPTER1 IntroductionThis document is intended to be both a tutorial and a reference guide. While it does not list all possible use cases,it should give a good overview of the principal functionality. Scripting in the Python Console Python Plugins Running Python code when QGIS starts The PYQGIS_STARTUP environment variable Python Applications Using PyQGIS in standalone scripts Using PyQGIS in custom applications Running Custom Applications Technical notes on PyQt and SIPP ython support was first introduced in QGIS There are several ways to use Python in QGIS Desktop (coveredin the following sections).

5 Issue commands in the Python console within QGIS Create and use plugins Automatically run Python code when QGIS starts Create custom applications based on the QGIS APIP ython bindings are also available for QGIS Server, including Python plugins (seeQGIS Server Python Plugins)and Python bindings that can be used to embed QGIS Server into a Python is a complete QGIS API reference that documents the classes from the QGIS libraries. The Pythonic QGISAPI ( PyQGIS ) is nearly identical to the C++ good resource for learning how to perform common tasks is to download existing plugins from the pluginrepository and examine their developer cookbook , Release Scripting in the Python ConsoleQGIS provides an integrated Python console for scripting.

6 It can be opened from thePlugins Python Consolemenu:Fig. : QGIS Python consoleThe screenshot above illustrates how to get the layer currently selected in the layer list, show its ID and optionally,if it is a vector layer, show the feature count. For interaction with the QGIS environment, there is anifacevariable, which is an instance ofQgisInterface. This interface allows access to the map canvas, menus,toolbars and other parts of the QGIS user convenience, the following statements are executed when the console is started (in the future it will bepossible to set further initial commands)from import*import those which use the console often, it may be useful to set a shortcut for triggering the console (withinSettings Keyboard shortcuts.)

7 Python PluginsThe functionality of QGIS can be extended using plugins. Plugins can be written in Python. The main advantageover C++ plugins is simplicity of distribution (no compiling for each platform) and easier plugins covering various functionality have been written since the introduction of Python support. Theplugin installer allows users to easily fetch, upgrade and remove Python plugins. See the Python Plugins page formore information about plugins and plugin plugins in Python is simple, seeDeveloping Python Pluginsfor detailed :Python plugins are also available for QGIS server. SeeQGIS Server Python Pluginsfor further Running Python code when QGIS startsThere are two distinct methods to run Python code every time QGIS Creating a script2 Chapter 1.

8 IntroductionPyQGIS developer cookbook , Release Setting thePYQGIS_STARTUP environment variable to an existing Python time QGIS starts, the user s Python home directory Linux:.local/share/QGIS/QGIS3 Windows:AppData\Roaming\QGIS\QGIS3 macOS:Library/Application Support/QGIS/QGIS3is searched for a file If that file exists, it is executed by the embedded Python :The default path depends on the operating system. To find the path that will work for you, open the PythonConsole and ( )to see the list of default The PYQGIS_STARTUP environment variableYou can run Python code just before QGIS initialization completes by setting thePYQGIS_STARTUP environ-ment variable to the path of an existing Python code will run before QGIS initialization is complete.

9 This method is very useful for cleaning ,which may have undesireable paths, or for isolating/loading the initial environment without requiring a virtualenvironment, homebrew or MacPorts installs on Python ApplicationsIt is often handy to create scripts for automating processes. With PyQGIS , this is perfectly possible import , initialize it and you are ready for the you may want to create an interactive application that uses GIS functionality perform measurements, exporta map as PDF, .. provides various GUI components, most notably the map canvaswidget that can be incorporated into the application with support for zooming, panning and/or any further custommap custom applications or standalone scripts must be configured to locate the QGIS resources, such asprojection information and providers for reading vector and raster layers.

10 QGIS Resources are initialized by addinga few lines to the beginning of your application or script. The code to initialize QGIS for custom applications andstandalone scripts is similar. Examples of each are provided a name for your script. Python will not be able to import the bindings as thescript s name will shadow Using PyQGIS in standalone scriptsTo start a standalone script, initialize the QGIS resources at the beginning of the script:from import*# Supply path to qgis install ("/path/to/qgis/installation",True)# Create a reference to the QgsApplication. Setting Python Applications3 PyQGIS developer cookbook , Release # second argument to False disables the = QgsApplication([],False)# Load ()# Write your code here to load some layers, use processing# algorithms, etc.


Related search queries