Giter Club home page Giter Club logo

pyqgis's Introduction

Read the documentation

QGIS Python API Documentation

Sphinx project to build python API documentation for QGIS..

You can see an online version of the generated documentation at this website:

https://qgis.org/pyqgis/master/index.html

Prerequisites:

Building and mostly pushing the docs properly requires SIP 4.19.7+.

To build:

Call build-docs.sh. QGIS python package must be found. You can either:

  • export the PYTHONPATH yourself
  • export your QGIS build directory with export QGIS_BUILD_DIR=/Users/timlinux/dev/QGIS/build
  • or provide QGIS build directory as argument to the script: ./build-docs.sh -qgis-build-dir /Users/timlinux/dev/QGIS/build

Viewing the docs

Open the build/html/ contents in your web browser.

e.g. on MacOS you can do open open build/html/docs/index.html

Publishing the docs

Use the publish-docs.sh script, with having build the docs before publishing them.

Credits

  • Tim Sutton 2017 - Initial prototype for this build system
  • Denis Rouzaud 2017 - Including work funded by QGIS.org

pyqgis's People

Contributors

3nids avatar delazj avatar dependabot[bot] avatar geo-ninja avatar ghtmtt avatar ismailsunni avatar m-kuhn avatar rduivenvoorde avatar srnetochan avatar timlinux 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

Watchers

 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

pyqgis's Issues

Remove "Not available in Python bindings" from c++ docs?

Related to this work - I've been wondering whether we should drop all the doxygen "Not available in Python bindings" notes from the c++ docs and headers. To me this information seems redundant now - either it's available in the bindings and included in the Python docs, or it's not and it won't be in the Python docs. This information was really just a hack while we only had c++ docs available for Python devs.

Identify sliver polygons and assign each to the neighboring polygon that shares the same attribute value such as block ID

I know there's a feature in QGIS to eliminate sliver polygons and it can also be implemented in standalone script. It seems like a blackbox to get the results directly. Is there a way in standalone script to identify (extract) sliver polygons? Also, can I use other parameters (e.g. the neighboring polygon that shares the same attribute value such as block ID) not the ones given in QGIS to assign slivers?

Thanks!

Missing code sample

Not sure whether I should open it here or in the source repository

There should probably be code sample converted here

image

as we can see in the source .h file (missing in the sip.in one)

image

QgsLayerTreeGroup.clone(self) doesn't clone children

The clone-Method of QgsLayerTreeGroup doesn't seem to work as expected. According to the documentation for QGIS 3.10 (and also current master) the children are cloned as well. However, when cloning a group with of map layers, the layers of the clone just seems to be references to the originals. Any changes applied to the supposedly cloned layer are also applied to the original.

From the documentation:

clone(self) → QgsLayerTreeGroup
Returns a clone of the group. The children are cloned too.
Return type
QgsLayerTreeGroup

https://qgis.org/pyqgis/master/core/QgsLayerTreeGroup.html?#qgis.core.QgsLayerTreeGroup.clone

Code Sample:

root = iface.layerTreeCanvasBridge().rootGroup()
group1 = QgsLayerTreeGroup('group 1')
layer1 = QgsVectorLayer("path" , "layer name 1")
group1.addLayer(layer1)
root.addChildNode(group1)
group2 = group1.clone()
group2.setName("group 2")
layer2 = group2.children()[0]
layer2.setName("layer name 2")
root.addChildNode(group2)

This code will result into the following layer-structure. In this example, layer2 is renamed, but renaming (as way as any other changes) also affects layer1

  • group 1
    • layer name 2
  • group 2
    • layer name 2
QGIS-Version | 3.10.0-A Coruña
BS-Version | Ubuntu 19.10

Add a link to the source code page to ease fixes

When you are browsing https://qgis.org/pyqgis/master and you find an issue, it might be really really convenient if there was a "fix me" link in the footer that would bring you to the class page (.h?) in qgis/QGIS repository. That would make contribution easier to proceed (we have this in qgis/QGIS-Documentation and it greatly saves time, avoiding waste of time with search in the repository)

Problem showing tables at docs.

Hi, i have been studing PyQgis docs and i found something.
Some descriptions are bigger than cell, that needs a scroll to see all description.

image

Maybe, can it set at CSS or html from the theme to make a line break.

I have tested in chrome and firefox.

QgsLogger() does not output anything

Dear developers,

I am developing some code in the QGIS Python Console. As I cannot set any breakpoints and print cannot be used due to multithreading I tried to use the QgsLogger class as described in the documentation. Unfortunately I couldn't get any output. Also there are no examples or comments regarding this topic in any public GIS related user group.
I even tried to set some environment variables in order to force the logging which didn't work out.

This is the code I use:

from qgis.core import QgsLogger

logname= "c:/temp/test.log"

Set environment variables

os.environ['QGIS_LOG_FILE'] = logname
os.environ['QGIS_DEBUG'] = '3'

print ("Logfile: ",QgsLogger.logFile())
QgsLogger.critical("QgsLoggerTest1")
QgsLogger.debug("QgsLoggerTest2")

QgsLogger.logMessageToFile("Mymessage")
print ("Debuglevel: ",QgsLogger.debugLevel())

The output in the console is as follows:

Logfile:
Debuglevel: 0

No file was created in c:/temp/test.log nor was the output written to any tab in the log messages window.

In the regarding QGIS documentation https://docs.qgis.org/3.10/en/docs/pyqgis_developer_cookbook/communicating.html#logging there is a link to https://qgis.org/pyqgis/3.10/core/QgsLogger.html#qgis.core.QgsLogger where the first sentence clearly states "QgsLogger is a class to print debug/warning/error messages to the console" which does not happen.

I'm running the following system:
QGIS version | 3.14.1-Pi | QGIS code revision | de08d6b
Compiled against Qt | 5.11.2 | Running against Qt | 5.11.2
Compiled against GDAL/OGR | 3.0.4 | Running against GDAL/OGR | 3.0.4
Compiled against GEOS | 3.8.1-CAPI-1.13.3 | Running against GEOS | 3.8.1-CAPI-1.13.3
Compiled against SQLite | 3.29.0 | Running against SQLite | 3.29.0
PostgreSQL Client Version | 11.5 | SpatiaLite Version | 4.3.0
QWT Version | 6.1.3 | QScintilla2 Version | 2.10.8
Compiled against PROJ | 6.3.2 | Running against PROJ | Rel. 6.3.2, May 1st, 2020
OS Version | Windows 10 (10.0)
Active python plugins | GroupStats; nominatim; QuickOSM; db_manager; MetaSearch; processing

Please note that I had opened an issue at the QGIS bug tracking site as well as I didn't know pyqgis has it's own site:
qgis/QGIS#38188

I had also set up a bug report for documentation at qgis/QGIS-Documentation#5995

As soon as we're sure what's the reason for the failure and that this site here is the correct one where to handle the bug I suggest to close it where obsolete.

Add overflow wrap in tables for Methods and Signals description

Currently, all tables displaying Methods and Signals have a max width of 800px which often forces the user to scroll horizontally to read all the content of a cell. I think it would be more user friendly (and elegant) if the cells had instead an overflow wrap. The max width could stay at 800px, but could also very well be unrestricted, the width being responsive anyway. I tried to find myself in the repo where the change could be made but I'm at a complete loss! I suppose the template with all the CSS/HTML is elsewhere...

overloaded methods

Go to https://qgis.org/pyqgis/master/core/Layout/QgsLayoutExporter.html#qgis.core.QgsLayoutExporter.exportToPdf
The exportToPdf has more than one way to call it but only the one in the grayed area (next to the name) is obvious, and when looking for a function you may miss the other alternative. This is also true for exportToImage, exportToSVG, print... (at least in this class).
Moreover, the paragraph showing the second alternative does not look sexy to read and you want to skip it (I unfortunately did it (!) for hours until I find in the github repo what I was looking for, which is not the way we want people to proceed.).

Unexpected crash using: QgsFeatureRenderer.symbolForFeature()

Hi all,
I'm trying to convert a 2D+Z vector layer to a 3D objet (using VTK) ...
So far I managed to get the geometry right :
qgis3d
but i'm looking to color the 3D object using the iface.mapCanvas() rendering ...

all I could find is to request the QgsSymbol for each feature and collect its color/label/whatever.
maybe there is a better way, but i could not find it

so when i try to call layer.renderer().symbolForFeature(feature, context) I got an unexpected crash ... linked to SIP and python binded methods

# -*- coding: utf-8 -*-
from qgis.core import QgsRenderContext
from qgis.core import QgsVectorLayer
from qgis.core import QgsWkbTypes
from qgis.utils import iface
from vtk import vtkCellArray
from vtk import vtkIntArray
from vtk import vtkPoints
from vtk import vtkPolyData
from vtk.util.numpy_support import numpy_to_vtk

__all__ = ["QgsVectorLayerToPolyData"]


def set_cells(poly: vtkPolyData, cells: vtkCellArray, dim: int):
    if dim == 0:
        poly.SetVerts(cells)
    elif dim == 1:
        poly.SetLines(cells)
    elif dim == 2:
        poly.SetPolys(cells)
    else:
        raise ValueError(f"Invalid data dimension: {dim}")


def QgsVectorLayerToPolyData(layer: QgsVectorLayer, build_lut=False):
    _type = layer.wkbType()
    _dim = QgsWkbTypes.wkbDimensions(_type)

    assert layer.isSpatial()  # i.e. have some geometries (might be empty)
    assert QgsWkbTypes.hasZ(_type)  # i.e. geometries are defined in R^3

    painter = layer.renderer().clone()
    context = QgsRenderContext.fromMapSettings(iface.mapCanvas().mapSettings())

    # Python side mesh primitives
    n, vertices = 0, []
    offsets, connectivity = [0], []
    colors = []
    for f in layer.getFeatures():
        symbol = painter.symbolForFeature(f, context)  # HERE IS THE PROBLEM
        colors.append(int(symbol.color().name().lstrip("#"), base = 16))
        for p in f.geometry().constParts():
            for v in p.vertices():
                vertices.append((v.x(), v.y(), v.z()))
                connectivity.append(n)
                n += 1
            if _dim == 2:  # OGR/WKT polygons duplicates first/last vertex
                del vertices[-1]
                del connectivity[-1]
                n -= 1
            offsets.append(n)

    # VTK/C++ side mesh
    polydata = vtkPolyData()
    points = vtkPoints()
    points.SetData(numpy_to_vtk(vertices, 1))
    cells = vtkCellArray()
    cells.SetData(numpy_to_vtk(offsets, 1), numpy_to_vtk(connectivity, 1))
    scalars = vtkIntArray()
    scalars.SetNumberOfComponents(1)
    scalars.SetName("Legend")
    scalars.SetData(numpy_to_vtk(colors, 1))
    # vtkPolyData generation
    polydata.SetPoints(points)
    set_cells(polydata, cells, _dim)
    polydata.GetCellData().AddArray(scalars)
    return polydata

the full crash repport:

Crash ID: cb1c4f2b11cbd392a38c522a5ed1e194e060e4a0


Stack Trace


QgsExpression::evaluate :
QgsCategorizedSymbolRenderer::valueForFeature :
QgsCategorizedSymbolRenderer::originalSymbolForFeature :
PyInit__core :
PyMethodDef_RawFastCallKeywords :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyEval_EvalCodeWithName :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyEval_EvalCodeWithName :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyEval_EvalCodeWithName :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyEval_EvalCodeWithName :
PyFunction_FastCallDict :
PyTuple_New :
PyObject_FastCallKeywords :
PyObject_FastCallKeywords :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyEval_EvalCodeWithName :
PyFunction_FastCallDict :
PyTuple_New :
PyObject_FastCallKeywords :
PyObject_FastCallKeywords :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyMethodDef_RawFastCallKeywords :
PyEval_EvalFrameDefault :
PyFunction_FastCallDict :
PyMethodDef_RawFastCallDict :
PyObject_Call :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
PyInit_QtCore :
QMetaObject::activate :
QAction::activate :
QAbstractButton::click :
QAbstractButton::mouseReleaseEvent :
QToolButton::mouseReleaseEvent :
QWidget::event :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QApplicationPrivate::sendMouseEvent :
QSizePolicy::QSizePolicy :
QSizePolicy::QSizePolicy :
QApplicationPrivate::notify_helper :
QApplication::notify :
QgsApplication::notify :
QCoreApplication::notifyInternal2 :
QGuiApplicationPrivate::processMouseEvent :
QWindowSystemInterface::sendWindowSystemEvents :
QEventDispatcherWin32::processEvents :
UserCallWinProcCheckWow :
DispatchMessageWorker :
QEventDispatcherWin32::processEvents :
qt_plugin_query_metadata :
QEventLoop::exec :
QCoreApplication::exec :
main :
BaseThreadInitThunk :
RtlUserThreadStart :




QGIS Info
QGIS Version: 3.16.2-Hannover
QGIS code revision: f1660f9da5
Compiled against Qt: 5.11.2
Running against Qt: 5.11.2
Compiled against GDAL: 3.1.4
Running against GDAL: 3.1.4



System Info
CPU Type: x86_64
Kernel Type: winnt
Kernel Version: 10.0.17763

processing.algorithmHelp from terminal (outside QGIS desktop)

Environment:

  • Ubuntu 18.04.4
  • QGIS 3.12.1-București
  • python 3.6.9

No matter which provider:algorithm algorithmHelp is trying to display details for it seems to encounter the same issue when running from terminal outside of QGIS desktop.

Create grid (native:creategrid)
...
CRS: Grid CRS

        Parameter type: QgsProcessingParameterCrs

        Accepted data types:
Traceback (most recent call last):
    ...
    processing.algorithmHelp("native:creategrid")
  File "/usr/share/qgis/python/plugins/processing/tools/general.py", line 75, in algorithmHelp
    print('\n'.join(opts))
UnicodeEncodeError: 'ascii' codec can't encode character '\u2026' in position 94: ordinal not in range(128)

Class description and constructors are mixed up

https://qgis.org/pyqgis/master/core/QgsCoordinateReferenceSystem.html

There are several problems with the way how the docs are generated now:

  • constructors are listed before the class description, making the text slightly confusing
  • the first line of text "Constructs an invalid CRS object" belongs to the default constructor which is not listed there
  • constructor description should have the same style as ordinary methods: the constructor definition should be highlighted and the description should be indented.

Incorrect return type when %MethodCode present

E.g. see QgsFeature::attribute( int fieldIdx ). In this case the MethodCode requires the sip definition to use SIP_PYOBJECT as the return type, but this prevents the docs from showing the actual return type and only "object" is used.

Use OpenCV in PyQGIS

I developing QGIS module and I have a question, how to capture QgsMapCanvas window with OpenCV for shoving in different frame or different application?
OpenCV will have data from map view window, in my case raster data for interactive processing and show processed picture in other frame.

Is it possible to transfer data between pyqgis plugins?

I'm not sure if this is a right place to ask the question. Since I asked my question in QT forum, but no one could answer it.

Is there a way to send signals among different plugins directly to make them communicate?

Thanks in advance.

Search-highlights look like spaces

Silly issue maybe, but I was looking for:

https://qgis.org/pyqgis/master/core/QgsNetworkAccessManager.html?highlight=qgsnetwork

And then you see:

gnome-shell-screenshot-mczwxz

And I was thinking... uh. spaces between Class names? I tried to copy the class name by double clicking, and then also you only copy QgsNetwork???
Then I removed the ?highlight=qgsnetwork and then double clicking the classname rightfully selects the whole classname.

So in theme.css there is:

.rst-content .highlighted {
background: #F1C40F;
display: inline-block;
font-weight: bold;
padding: 0 6px;
}
removing the padding: 0 6px; line it's (I think better).

I cloned the repo for a PR, but cannot inf the theme.css? It is probably in the theme used in the build?

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.