Git Product home page Git Product logo

pyqgis-samples's Introduction

PyQGIS samples

Purpose

When you start to use the QGIS Python API ((also known as "PyQGIS"), your most complete documentation is the C++ QGIS API documentation. Then, you will rely on the the PyQGIS cookbook, the examples available online and the code from the existing plugins (if you are already good at programming).

Numerous users are struggling to use the C++ QGIS API documentation and apply it to Python, to go further.

This repository is an attempt to start to cover all the Python QGIS API.

It's a work in progress. At the moment, we are documenting mainly gui and core modules from Python QGIS API.

The long term goals are:

Work progression

For the main "shiny" content, go to https://webgeodatavore.github.io/pyqgis-samples/

To follow our documentation coverage progress, go at:

We may have more code available in the Github repository than the one publish on the website. Do not hesitate to browse the repository to find more samples.

Want to contribute?

It can be for doing corrections, just mentioning an issue in current samples or contributing to new samples.

Fork the code or just open an issue if you are afraid of code (not a joke, end users input feedbacks are welcome!)

Licence

GPL version 2 or greater to avoid the "hassle" with QGIS plugins recommended license.

Acknowledgements

We already borrowed some code available online from third party.

We plan to track all the credits here but didn't constitute the full list.

Wait for an update or ask to be credited.

Contact

contact(at)webgeodatavore(dot)com

pyqgis-samples's People

Contributors

thomasg77 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pyqgis-samples's Issues

Any Help Needed?

Hi @ThomasG77 thanks for this great resource that capture some of the bits not available within the official pyQGIS docs.
the site has been helpful despite the API referencing to QGIS 2 thus been a learning sprint by trying to refactor them to 3.

While going through the examples(those of concern to me) realized how much it simplified reading the official Documentation both the C++ and python as it gave me hints to the specific class and methods to look out for.

I have been trying on my own to refactor the whole resource to PyQGIS3 API:
Here is my work flow at the moment:

  • Use qgis2apifinder --all to find all api2 reference in the repo and log to a file q2to3qAPI.log
  • Use qgis2to3 -w to rewrite obvious changes to the files
  • (I also at times use py2to3 tool of other pythonic migrations but no use in this case)
  • The manual step: test out all the resources in qgis and amend further changes that might have been missed from above
  • finally as of now i'm just testing them out. No screen captures yet.

Any guidelines on how to PR and contrib my fork?
Curious cat happy to break and make things

How to show QgsLayerTreeView in a custom applications

I need to read some raster data and show their information in a tree widget, but while I use QgsLayerTreeView, it can not shown in my GUI. The last is my code, I want to know where i am wrong

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from qgis.gui import *
from qgis.core import *
import sys
import os


class MyWnd(QMainWindow):
    def __init__(self):
        QMainWindow.__init__(self)

        self.main_widget = QWidget()
        self.tree = QgsLayerTreeView()

        pro = QgsProject.instance()
        pro.read("D:/项目/GUI开发/code/20181030/data2/my_pro.qgs")

        k = 1
        for file in os.listdir(file_folder):
            if file[-3:] == 'tif':
                filename = file_folder + "/" + file
                file_info = QFileInfo(filename)
                base_name = file_info.baseName()

                if k < 10:
                    layer = QgsRasterLayer(filename, base_name)
                    QgsProject.instance().addMapLayer(layer)
                    k = k + 1

        root = QgsProject.instance().layerTreeRoot()
        model = QgsLayerTreeModel(root)
        self.tree.setModel(model)

        self.setCentralWidget(self.tree)
        self.show()
        pro.write()


if __name__ == '__main__':

    file_folder = "D:/项目/GUI开发/code/20181030/data2"
    QgsApplication.setPrefixPath(r"C:\OSGeo4W64", True)
    qgs = QgsApplication([], True)
    qgs.initQgis()
    app = QApplication(sys.argv)
    w = MyWnd()
    sys.exit(app.exec_())
    qgs.exitQgis()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.