qgis / pyqgis Goto Github PK
View Code? Open in Web Editor NEWSphinx project to build python API documentation for QGIS
Home Page: https://qgis.org/pyqgis/master/
License: GNU General Public License v2.0
Sphinx project to build python API documentation for QGIS
Home Page: https://qgis.org/pyqgis/master/
License: GNU General Public License v2.0
See https://qgis.org/pyqgis/master/core/Layout/QgsLayoutManager.html (I'm not sure Methods and signals should be embedded in the note frame)
see QgsCoordinateReferenceSystem::CrsType
leads to overwhelmed doc
see QgsAdvancedDigitizingCanvasItem for instance
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.
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.
Since this commit, qgis/QGIS@64387a2 it's better to use from qgis.processing import run
. But these functions are not visible in the pyqgis documentation.
Paragraphs are wrongly formed (split, indentation) in the upper part of the QgsLayoutItemMapOverview class
Also, the "see also" frame is merged with the Methods one.
https://qgis.org/pyqgis/master/core/Layout/QgsLayoutItemMapOverview.html
the documentation for qgis.core.QgsWkbTypes shows different IDs depending on the wkbType. Link: Documention
Unfortunately the id for polygons is the same as for unknownGeometry which is 3:
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...
E.g in http://python.qgis.org/master/core/Layout/QgsLayoutItemLabel.html#qgis.core.QgsLayoutItemLabel.adjustPointForReferencePosition, there's the line
Bases: qgis._core.QgsLayoutItem
But because this isn't a link, you can't directly go to the base class docs without searching for the class manually.
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!
I wonder if the rendering of the brewer_string is as expected
The conversion to python code seems to not render correctly (https://qgis.org/pyqgis/master/core/QgsActionScopeRegistry.html)
and param documentation is discarded
QgsExpression
https://qgis.org/pyqgis/master/core/QgsExpression.html#module-QgsExpression
QgsFeature
https://qgis.org/pyqgis/master/core/QgsFeature.html#qgis.core.QgsFeature.setGeometry
QgsProjectDirtyBlocker
https://qgis.org/pyqgis/3.18/core/QgsProjectDirtyBlocker.html#module-QgsProjectDirtyBlocker
See eg qgis.core.QgsAbstractCacheIndex.getCacheIterator - the featureIterator Param docs get incorrectly split and half is formatted as a normal text block
https://qgis.org/pyqgis/master/core/QgsProviderMetadata.html incorrectly only contains:
All the real api docs for this class are missing
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
QGIS-Version | 3.10.0-A Coruña
BS-Version | Ubuntu 19.10
For example in https://qgis.org/pyqgis/master/core/QgsLogger.html
The asterisks are not present in the API documentation https://qgis.org/api/classQgsLogger.html
one improvement which would be really nice would be to make the return types hyperlinks
i think to do this we need this plugin
https://github.com/agronholm/sphinx-autodoc-typehints
at least, that's my understanding based on https://stackoverflow.com/questions/13920165/sphinx-method-return-types-with-links
although possible this could work which would just be sipify magic: https://stackoverflow.com/a/19400374/1861260
Hi, i was reading the README.md file, and in Prerequisites tells to install requirements.txt but this file is missing.
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"
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.
3.6 docs are available, but on index page (https://qgis.github.io/pyqgis/ or https://qgis.org/pyqgis) the link to it is not yet added
I think I should be able to fix it myself, or do a PR but fail to find the page...
Maybe also add a link to https://github.com/qgis/pyqgis on the bottom of the index page?
Looking into why https://qgis.org/pyqgis/3.4/core/Raster/QgsRasterHistogram.html has such poor docs, it's because the member variable documentation isn't transferred to sip docstrings.
This isn't currently supported by sip, but I think it should be possible. See https://stackoverflow.com/a/40488936/1861260
The title says all. This is the same issue as #31 but I fail to find my way in the repo structure to propose a PR so...
Environment:
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)
The QgsVectorLayer description has sections and subsections but the current rendering does not make this structure obvious nor ease the description reading.
See eg http://python.qgis.org/master/core/Layout/QgsLayoutItemLabel.html
The class docs start with:
"A layout item subclass for text labels.
New in version 3.0: Methods"
This makes it seem like the following methods were added in version 3 - when it's actually the class which was new in 3.0, and the ":" should be removed and replaced with a new paragraph instead.
Seems to happen with all classes marked with a since annotation
Not sure whether I should open it here or in the source repository
There should probably be code sample converted here
as we can see in the source .h file (missing in the sip.in one)
There are some \section and \subsection tags(?) used in the code to structure the doc but they are not rendered in the PyQGIS doc, making things less readable. See eg https://qgis.org/pyqgis/master/core/QgsVectorLayer.html (having sections in this long description would certainly help to quickly identify the provider you are interested in).
Silly issue maybe, but I was looking for:
https://qgis.org/pyqgis/master/core/QgsNetworkAccessManager.html?highlight=qgsnetwork
And then you see:
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?
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.).
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)
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.
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 :
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
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.
https://qgis.org/pyqgis/master/core/QgsCoordinateReferenceSystem.html
There are several problems with the way how the docs are generated now:
See e.g. https://qgis.org/pyqgis/master/core/QgsTriangle.html
The "Example" headings from methods like isDegenerate() do not show
Even non - QObject derived classes are showing an empty "signals" section - but this has no meaning and is misleading
Reading the docs at https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/geometry.html#access-to-geometry, trying to identify the QgsWkbTypes.GeometryType and QgsWkbTypes.Type classes (actually identify the enumeration of each) seems impossible (at least for the beginner I'm).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.