19
votes
Accepted
Make QGIS python plugin for both versions 2.x and 3.x?
Documentation
Here you can find what is new and what is break under the PyQGIS API.
To get details about how to port Python2 to Python3 go there
You can find some detail about testing from QGIS2 to ...
15
votes
Accepted
KeyError: '-1' when adding field and calculating expression with PyQGIS
The error you get says the field index is -1, so your new field wasn't found in your attribute table.
That may be happening because:
You need to use QVariant.Double instead of QVariant.Float.
You've ...
12
votes
Accepted
How to add a filter to “QFileDialog.getOpenFileName”
According to the documentation you can add filter in the definition of your class:
QString QFileDialog.getOpenFileName (QWidget parent = None, QString caption = QString(), QString directory = ...
8
votes
No module named 'osgeo'
Try this,
pip install --global-option=build_ext --global-option="-I/usr/include/gdal" GDAL==`gdal-config --version`
8
votes
Accepted
Select and use raster layer from python
Hopefully the following will help get you started, I've added comments to try and explain how it works.
Essentially, you can use a QgsMapLayerComboBox to filter out all layers loaded in QGIS and ...
8
votes
Accepted
Plugin crashes QGIS 2.18 if running simuntaneously with python console
This is indeed an effect of using the print statement and having the python console open. And using the logging module as proposed is a very good approach to solving this issue.
Here follow some ...
7
votes
Accepted
Get the identified feature
This is a simple code for connect your QgsMapToolIdentifyFeature signal.
from qgis.gui import QgsMapToolIdentifyFeature
def onFeatureIdentified(feature):
print "feature selected : "+ str(feature....
6
votes
Accepted
No module named 'osgeo'
This sounds like you have multiple python installations, and GDAL is installed on one and not the other.
Try the following (which I have based upon this). Create a text file within your python ...
6
votes
Developing QGIS plugin: AttributeError: object has no attribute
In new_mmqgis.py:
You set self.first_start = True in initGui, then, you set self.first_start = False in run method.
In geocode_web_service method, you are checking if self.first_start == True. That if ...
5
votes
How to add a filter to “QFileDialog.getOpenFileName”
dialog = QtGui.QFileDialog()
fname = dialog.getOpenFileName(None, "Window name", "", "CSV files (*.csv)")
Will do the job.
Just pass None as 1st agrument.
5
votes
Accepted
QgsMapCanvas has no attribute 'setLayers'?
The reason is, you are trying to use QGIS 3 API on QGIS 2.
Here is the API for QGIS 2:
https://qgis.org/api/2.18/classQgsMapCanvas.html
Here is the API for QGIS 3:
https://qgis.org/api/...
5
votes
Accepted
QGIS2 to QGIS3 plugin migration issue AttributeError: type object 'QObject' has no attribute 'connect'
With this documentation about PyQt5 signals, try this :
self.buttonBox.accepted.connect(Configuration.accept)
self.buttonBox.rejected.connect(Configuration.reject)
4
votes
4
votes
Plugin crashes QGIS 2.18 if running simuntaneously with python console
It looks like I overused print statement while debugging in python. Switching to logging module solved the problem. Use logging module instead of print, it's much more convenient and practical. It's a ...
4
votes
Showing startup-messages on QGIS splashscreen
I figured out another solution (QGIS 3.4): startup.py
from PyQt5.QtCore import QSettings,QStandardPaths
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QLabel, QWidget, QSplashScreen,...
4
votes
Accepted
How to get QGIS canvas in plugin window?
In QT designer you need make right click on the widget and select "promote to", and write the class and header as seen in the image.
after you need compile the .ui.
In the class that loads this ui, ...
3
votes
Accepted
Create a upload button in PyQt QGIS plugin
If the uploaded file is not in image or .csv file it should thrown an
message.
It is not the most common approach I think.
The best way to do this is to create a file dialog, that allows to choose ...
3
votes
How to use processing in a PyQT plugin in QGis
I can partly answer my own question!
The following works now also in my Python plugin: The reason was that I had a differed order of xmin/xmax/ymin/ymax for PROJWIN in the plugin code. Thus the ...
3
votes
Check if QLineEdit is NULL on a custom form?
If I understand well, you want to check for NULLs when the custom value for NULL is changed by the user from the Settings.
In this case, you may simply use:
from qgis.core import *
if <what you ...
3
votes
Accepted
Rendering a custom bounding box to an image file using python and QGIS?
Your code is ok, but there is probably a typo in the p list. The first item value seems too big for the location you are working on (I generally work using CRS UTM 32N): probably the last digits of ...
3
votes
Accepted
How to make my plugin dialog window open as QGIS default plugins?
Add parent=self.iface.mainWindow() parameter when instantiating dialog.
def __init__(self, iface):
self.iface = iface
...
...
def run(self):
...
# change dialog class name
self....
2
votes
No module named 'osgeo'
Got the same problem. I fixed ir by installing python-gdal using synaptic with my Debian Jessie
2
votes
How to call a method when self.iface.actionSelectRectangle().trigger() is released?
An answer is here : How to define an event for features selected in mapcanvas in qgis using python
You can connect your function to the selectionChanged signal of your vector layer
Example code from ...
2
votes
Accepted
Converting GeoTIFF file to numpy array to QPixmap with PyQt4?
I managed to do it in the end, so I'll post the answer here in case anyone needs it later.
The problem was that my image contained float32 and sometimes even complex32 data, but QImage does not ...
2
votes
Accepted
Trigger plugin button using PyQGIS?
It seems that this is more a PyQt4 question.
I guess the best way of doing it is to give your actions an objectName, so that you can access them directly instead of looping through toolbars and ...
2
votes
Accepted
QGIS plugin fields will not reset
You can call the function reset_form on closeEvent of the form.
Add this code to GNATDialog class:
def closeEvent(self, event):
self.reset_form()
2
votes
Keep track of current layers in PyQt plugin for QGIS
You can do that by using 'groupRelationsChanged' method of QgsLegendInterface to connect slot. Following code snippet is referred to pluging and works as expected:
.
.
.
def __init__(...
2
votes
Accepted
Keep track of current layers in PyQt plugin for QGIS
You can use QgsMapRegistry signals like layersAdded and LayersRemoved. Just connect function that can modify your QComboBox.
Another solution is to use QgsMapLayerComboBox:
https://qgis.org/api/...
2
votes
Get the identified feature
To stick with your code :
def onFeatureIdentified(self, ff):
print("feature selected")
def run(self):
mCanvas = self.iface.mapCanvas()
f = QgsMapToolIdentifyFeature(mCanvas, self.iface....
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
pyqt4 × 65pyqgis × 48
qgis × 28
qgis-plugins × 21
python × 15
qgis-2 × 11
pyqt × 6
pyqt5 × 5
qgis-3 × 4
python-2.7 × 4
qt-designer × 4
gdal × 2
gui × 2
raster × 1
postgresql × 1
geotiff-tiff × 1
fields-attributes × 1
qgis-processing × 1
error × 1
pyqgis-3 × 1
sld × 1
mac × 1
numpy × 1
snapping × 1
python-3 × 1