New answers tagged

0

For Spatialite: It works when I specify the layer and set auto refresh: layer = QgsProject.instance().mapLayersByName("my_layer_name")[0] layer.setAutoRefreshInterval(500) layer.setAutoRefreshEnabled(True) For Oracle it takes too much time for the visual part, so I interact with spatialite in QGis, but I make my SQL statements on the two DB in parallel.


1

If you recall from your previous question, the method iface.addRasterLayer() takes 2 string arguments- the file path and layer name as parameters. You are passing it a raster layer object, hence the error is telling you that argument 1 has the unexpected type 'QgsRasterLayer'. You can use the addMapLayer() method which belongs to the QgsProject class ...


2

SQL queries are really optimal but I offer you an alternative that will create a layer of gps points for each stop. My starting layers # Identification of gps layer gps = QgsProject.instance().mapLayersByName("gps")[0] # Identification of stops layer stops = QgsProject.instance().mapLayersByName("stops")[0] # List : Field with unique identifiers in ...


2

From DB Manager > Virtual Layers > SQL Window, you can run the following query (replace the tables and fields names with real ones) : SELECT bus_stops.id, -- change here the field name id with identifier bus stop field MIN(gps.time) AS bus_entered, -- change here the field name time for the gps field with time MAX(gps.time) AS bus_left -- same here ...


5

With QGIS 3.10, you can duplicate your layer (polyline or polygon), go in its symbology, choose Geometry generator with Point / Multi-Point and paste this code : with_variable( 'distance_threshold', 5, --treshold to modify collect_geometries( array_filter( array_foreach( generate_series(1, num_points($geometry)), if( ...


4

Interesting question! I couldn't find any native signal emitted when an attribute table is opened or closed so I would call this solution a fairly inelegant workaround but it seems to work well enough. I found that QApplication has a focusChanged(old, new) signal which is emitted whenever the widget focus changes e.g. opening/ closing dialogs or clicking ...


0

I have found the solution: Just use Eclipse IDE and add the Pyqgis packages to the PyDev,and it will works!!!


1

You can use the qgis batch file as a template. @echo off SET QGISNAME=qgis SET PyScripter="C:\Program Files\PyScripter\PyScripter.exe" call "%~dp0\o4w_env.bat" call qt5_env.bat call py3_env.bat path %OSGEO4W_ROOT%\apps\%QGISNAME%\bin;%PATH% set QGIS_PREFIX_PATH=%OSGEO4W_ROOT:\=/%/apps/%QGISNAME% set GDAL_FILENAME_IS_UTF8=YES rem Set VSI cache to be ...


3

I've found a temporary solution: layer = QgsProject.instance().mapLayersByName("LAYER_NAME")[0] attr_table = iface.showAttributeTable(layer) table = attr_table.findChildren(QTableView)[0] def zoom(item): """ zooms to feature when clicking FID field """ x = item.data() # get cell value try: ID = list(layer.getFeatures('"FID" = ' + x))...


2

You're confusing a feature with a vector layer. A feature is a row on a vector layer that may contain attributes and geometry. A vector layer is a set of features that represent "the same kind of data", like a set of roads. (Im being really simplistic with this explanation, please look more into it) Now, assuming that you want the bounding box of all ...


1

As I wrote in the comment, I obtained something that works, activating the pan tool after the editing. I'm not sure if it is the correct method. I'm writing only the added code: class casePicker(QgsMapTool): ... def __init__(self, dlg, psrid, iface, tt, lab, lyr): ... self.iface.currentLayerChanged.connect(self.setPanTool) def ...


2

I've put together a script using bits from @Ben W's answer as well as from this answer this answer to a different question. This takes the following inputs: Number of Classes (number_classes) Filed to use in the ramp (fld) Existing Color Ramp (colorRampNumber) Optional Alternative: user specified start and end colors to use for a custom color ramp This ...


3

I have been through the same experience before, and (I may be wrong) but as far as I am aware, it is not possible to programmatically set a default color ramp and have it automatically applied. As you discovered, doing setSourceColorRamp() just sets that color ramp in the symbology dialog- it doesn't apply it to the renderer range symbols. You have to ...


0

If it helps, to read the searchable and identifiable, we can use: searchable = bool(QgsMapLayer.LayerFlag(layer.flags()) & 4) identifiable = bool(QgsMapLayer.LayerFlag(layer.flags()) & 1) print(searchable, identifiable)


0

if iface.mapCanvas().isCachingEnabled(): layer.triggerRepaint() else: iface.mapCanvas().refresh() This one is from the docs, and as mentioned there, it should refresh the query from your database, too.


0

Just define separate class methods in your main plugin class and connect them to different buttons in your UI tabs. For example, if you have buttons with object names like ok_btn_1 and ok_btn_2, in the initGui method of your main plugin file, connect the clicked signal to the methods which contain the 'processes' you want to run. def initGui(self): ... ...


6

You can get the list of field names in the order you have arranged them (using the Drag and drop designer) in this way: qgis_layer = iface.activeLayer() edit_form_config = qgis_layer.editFormConfig() root_container = edit_form_config.invisibleRootContainer() for field_editor in root_container.findElements(QgsAttributeEditorElement.AeTypeField): print(...


Top 50 recent answers are included