Hot answers tagged

7

The file bivariate_legend.py has a missing import. Open file /Users/judithheher/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/BivariateLegend/bivariate_legend.py in any editor. Add from qgis.core import Qgis to the import section. Restart QGIS and retry. The plugin will run seamlessly.


6

There is no problem in your code or no bug with QGIS. createRenderer method is deprecated since v3.10. Therefore, there may be incompatibility between the method and later versions of QGIS. I recommend you use the constructor.


4

Try running the code snippet below in the Python console: default_style = QgsStyle().defaultStyle() color_ramp = default_style.colorRamp('Spectral') #Spectral color ramp color_ramp.invert() layer = QgsProject().instance().mapLayersByName('Shapefile')[0] field_index = layer.fields().lookupField('Intensity') unique_values = list(layer.uniqueValues(field_index)...


4

Instead of categorizing the data by intensity, you can categorized it by a concatenation of intensity and affected_p The expression would be similar to "intensity" || ' - ' || sum("affected_p","intensity") The example below use the average instead of the sum:


4

You may choose: to use GDAL using ogrmerge.py like here but with setting a destination target not a file but your database compare to this example https://twitter.com/ThomasG77/status/1362118505819176966 See ogrmerge doc looping with bash doing something like below (not exact as it depends from your own table structure) psql -c "CREATE TABLE ...


3

As I understand it, the only way to update geometry on the go (using this reshapeGeometry method at least) is to access the layer's data provider: layer = iface.activeLayer() provider = layer.dataProvider() line = QgsLineString([QgsPoint(1, 1), QgsPoint(2, 2)]) feats_to_update=[] for feat in layer.selectedFeatures(): geom = feat.geometry() geom....


1

From a little search and experimentation: from qgis.utils import iface from qgis.core import QgsProject from PyQt5.QtCore import QObject, Qt from PyQt5.QtWidgets import QAction class Toggler(): def __init__(self): self.root = QgsProject.instance().layerTreeRoot() self.current = self.root.findLayer(iface.activeLayer().id()) self....


1

from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def func(feature, parent): root = QgsProject.instance().layerTreeRoot() layer = qgis.utils.iface.activeLayer() lyr = root.findLayer(QgsProject.instance().mapLayersByName(layer.name())[0].id()) group = lyr.parent().name() if group != '': ...


1

To adapt the code you are using to categorize based on the expression suggested by @JGH, you actually need to create the list of unique values and QgsRendererCategory list based on the expression. Please try the code below, adapted (and 'Pythonicized') from the logic in the addCategories() method of QgsCategorizedSymbolRendererWidget class which starts at ...


1

In the end creating an instance of QgsVectorLayerExporter and passing it the desired geometry type helped. con_string = """dbname='gis' host='localhost' port='25432' user='qgis' password='qgis' key='id' table="public"."my_layer_new" (geom)""" exporter = QgsVectorLayerExporter(con_string, 'postgres', fields=...


Only top voted, non community-wiki answers of a minimum length are eligible