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 QGIS3 on this question :Writing automated tests for QGIS plugins?
And you will find an interesting OpenGis.ch's paper here about the migrations tools.
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 = QString(), QString filter = QString(), Options options = 0)
So with your code it should looks like :
qfd = QFileDialog()
path = "D:\...
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 only have it list the multiband rasters. You can then define a function which will read the selected layer and populate the combo boxes for the bands (note that I ...
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 insights into what exactly happens. It boils down to print() internally calling QCoreApplication::processEvents() and processEvents() is evil and dangerous.
The reason is, you are trying to use QGIS 3 API on QGIS 2.
Here is the API for QGIS 2:
Here is the API for QGIS 3:
There are 2 solutions to this problem:
Work with QGIS 3
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 installation site packages folder C:\Python27\Lib\site-packages called usrlocal.pth. In this text file insert one line giving the path to your second python ...
Solved, 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 nuisance in the beginning, but once you get it it's quite easy. Here are some links that were very helpful for me:
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 module failed but did not throw any errors. Yes sometimes you don't see the wood for the trees ;-)
from qgis.core import QgsRasterLayer
raster = ...
If the uploaded file is not in image or .csv file it should thrown an
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 only one extension. Example:
dialog = QtGui.QFileDialog()
fname = dialog.getOpenFileName(None, "Import CSV", "", "CSV data files ...
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 want to check> == qgis.core.NULL:
# do something
The above check should compare the input with the value that the user set for the NULLs.
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 33401477 are decimals.
If I use other values for p:
p = [318333,4993348]
on this sample raster (CRS UTM 32N, EPSG:32632):
I get a result without any problem (...
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,QApplication
s = QSettings()
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, to load some layer for example (this canvas have a objectname "canvas")
""" Contructor """
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 the related answer:
print str(len(selFeatures)) + " features were selected: " + str(selFeatures)
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 support it, so I had to convert it to uint8.
Another problem that came up was that my image was completely black, because the values were most of the time like 0.x, ...
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 their children.
For instance, I can give the custom name mActionCopyLayersToClipboard to one of my plugin buttons:
self.actionCopy = QAction( icon, u"Copy ...
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__(self, iface):
layers = self.iface.legendInterface().layers()
layer_list = [ layer.name() for layer ...
You can use QgsMapRegistry signals like layersAdded and LayersRemoved. Just connect function that can modify your QComboBox.
Another solution is to use QgsMapLayerComboBox:
I think it should be updated automatically.
I reply myself here, according with the solution given in the qgis developers mail list.
In the initGui function I should add this line:
self.dockwidget = GeoFibraDockWidget()
Is the constructor for the dockwidget.